Fixed missing function name/class info crashes.

git-svn-id: svn://10.0.0.236/trunk@100947 18797224-902f-48f8-a5cc-f745e15eee43
This commit is contained in:
rogerl%netscape.com 2001-08-13 23:14:56 +00:00
parent cb6da3d791
commit 0e11953ad3
6 changed files with 52 additions and 32 deletions

View File

@ -728,7 +728,7 @@ bool ByteCodeGen::genCodeForStatement(StmtNode *p, ByteCodeGen *static_cg, uint3
VariableBinding *v = vs->bindings;
bool isStatic = (vs->attributeValue->mTrueFlags & Property::Static) == Property::Static;
while (v) {
Reference *ref = mScopeChain->getName(*v->name, CURRENT_ATTR, Write);
Reference *ref = mScopeChain->getName(*v->name, vs->attributeValue->mNamespaceList, Write);
ASSERT(ref); // must have been added previously by collectNames
if (v->initializer) {
if (isStatic && (static_cg != NULL)) {

View File

@ -1407,12 +1407,12 @@ JSValue Context::interpret(uint8 *pc, uint8 *endPC)
NamespaceList *t = a1->mNamespaceList;
while (t) {
x->mNamespaceList = new NamespaceList(&t->mName, x->mNamespaceList);
x->mNamespaceList = new NamespaceList(t->mName, x->mNamespaceList);
t = t->mNext;
}
t = a2->mNamespaceList;
while (t) {
x->mNamespaceList = new NamespaceList(&t->mName, x->mNamespaceList);
x->mNamespaceList = new NamespaceList(t->mName, x->mNamespaceList);
t = t->mNext;
}
if (a1->mExtendArgument)

View File

@ -94,11 +94,9 @@ Attribute *Context::executeAttributes(ExprNode *attr)
}
// find a property by the given name, and then check to see if there's any
// overlap between the supplied attribute list and the property's list.
// ***** REWRITE ME -- matching attribute lists for inclusion is a bad idea.
// XXX it's re-written a little bit, but is still doing linear searching (o^2) ...
// Find a property with the given name, but make sure it's in
// the supplied namespace. XXX speed up! XXX
//
PropertyIterator JSObject::findNamespacedProperty(const String &name, NamespaceList *names)
{
for (PropertyIterator i = mProperties.lower_bound(name),
@ -796,7 +794,7 @@ void ScopeChain::collectNames(StmtNode *p)
{
ClassStmtNode *classStmt = checked_cast<ClassStmtNode *>(p);
const StringAtom *name = &classStmt->name;
JSType *thisClass = new JSType(name, NULL);
JSType *thisClass = new JSType(m_cx, name, NULL);
m_cx->setAttributeValue(classStmt, 0); // XXX default attribute for a class?
@ -863,6 +861,12 @@ void ScopeChain::collectNames(StmtNode *p)
if (p->getKind() == StmtNode::Const)
vs->attributeValue->mTrueFlags |= Property::Const;
bool isStatic = (vs->attributeValue->mTrueFlags & Property::Static) == Property::Static;
if ((vs->attributeValue->mTrueFlags & Property::Private) == Property::Private) {
JSType *theClass = topClass();
if (theClass == NULL)
m_cx->reportError(Exception::typeError, "Private can only be used inside a class");
vs->attributeValue->mNamespaceList = new NamespaceList(theClass->mPrivateNamespace, vs->attributeValue->mNamespaceList);
}
while (v) {
if (isStatic)
@ -1229,12 +1233,13 @@ Reference *JSType::genReference(bool hasBase, const String& name, NamespaceList
return NULL;
}
JSType::JSType(const StringAtom *name, JSType *super)
JSType::JSType(Context *cx, const StringAtom *name, JSType *super)
: JSObject(Type_Type),
mSuperType(super),
mVariableCount(0),
mInstanceInitializer(NULL),
mClassName(name),
mPrivateNamespace(&cx->mWorld.identifiers[*name + " private"]),
mIsDynamic(false),
mUninitializedValue(kNullValue),
mPrototypeObject(NULL)
@ -1255,6 +1260,7 @@ JSType::JSType(JSType *xClass) // used for constructing the static component
mVariableCount(0),
mInstanceInitializer(NULL),
mClassName(NULL),
mPrivateNamespace(NULL),
mIsDynamic(false),
mUninitializedValue(kNullValue),
mPrototypeObject(NULL)
@ -1729,14 +1735,23 @@ void Context::assureStackSpace(uint32 s)
void Context::initClass(JSType *type, ClassDef *cdef, PrototypeFunctions *pdef)
{
mScopeChain->addScope(type);
type->setDefaultConstructor(this, new JSFunction(cdef->defCon, Object_Type));
JSFunction *constructor = new JSFunction(cdef->defCon, Object_Type);
constructor->setClass(type);
FunctionName *fnName = new FunctionName();
fnName->name = type->mClassName;
constructor->setFunctionName(fnName);
type->setDefaultConstructor(this, constructor);
// the prototype functions are defined in the prototype object...
if (pdef) {
for (uint32 i = 0; i < pdef->mCount; i++) {
JSFunction *fun = new JSFunction(pdef->mDef[i].imp, pdef->mDef[i].result);
fun->setClass(type);
StringAtom *name = &mWorld.identifiers[widenCString(pdef->mDef[i].name)];
FunctionName *fnName = new FunctionName();
fun->setFunctionName(fnName);
fun->setArgCounts(pdef->mDef[i].length, 0, false);
type->mPrototypeObject->defineVariable(this, widenCString(pdef->mDef[i].name),
type->mPrototypeObject->defineVariable(this, *name, //widenCString(pdef->mDef[i].name),
(NamespaceList *)(NULL),
pdef->mDef[i].result,
JSValue(fun));
@ -1770,21 +1785,21 @@ void Context::initBuiltins()
{ "NamedArgument", NULL, &kNullValue },
};
Object_Type = new JSType(&mWorld.identifiers[widenCString(builtInClasses[0].name)], NULL);
Object_Type = new JSType(this, &mWorld.identifiers[widenCString(builtInClasses[0].name)], NULL);
Object_Type->mIsDynamic = true;
// XXX aren't all the built-ins thus?
Type_Type = new JSType(&mWorld.identifiers[widenCString(builtInClasses[1].name)], Object_Type);
Function_Type = new JSType(&mWorld.identifiers[widenCString(builtInClasses[2].name)], Object_Type);
Number_Type = new JSType(&mWorld.identifiers[widenCString(builtInClasses[3].name)], Object_Type);
Integer_Type = new JSType(&mWorld.identifiers[widenCString(builtInClasses[4].name)], Object_Type);
String_Type = new JSStringType(&mWorld.identifiers[widenCString(builtInClasses[5].name)], Object_Type);
Array_Type = new JSArrayType(&mWorld.identifiers[widenCString(builtInClasses[6].name)], Object_Type);
Boolean_Type = new JSType(&mWorld.identifiers[widenCString(builtInClasses[7].name)], Object_Type);
Void_Type = new JSType(&mWorld.identifiers[widenCString(builtInClasses[8].name)], Object_Type);
Unit_Type = new JSType(&mWorld.identifiers[widenCString(builtInClasses[9].name)], Object_Type);
Attribute_Type = new JSType(&mWorld.identifiers[widenCString(builtInClasses[10].name)], Object_Type);
NamedArgument_Type = new JSType(&mWorld.identifiers[widenCString(builtInClasses[11].name)], Object_Type);
Type_Type = new JSType(this, &mWorld.identifiers[widenCString(builtInClasses[1].name)], Object_Type);
Function_Type = new JSType(this, &mWorld.identifiers[widenCString(builtInClasses[2].name)], Object_Type);
Number_Type = new JSType(this, &mWorld.identifiers[widenCString(builtInClasses[3].name)], Object_Type);
Integer_Type = new JSType(this, &mWorld.identifiers[widenCString(builtInClasses[4].name)], Object_Type);
String_Type = new JSStringType(this, &mWorld.identifiers[widenCString(builtInClasses[5].name)], Object_Type);
Array_Type = new JSArrayType(this, &mWorld.identifiers[widenCString(builtInClasses[6].name)], Object_Type);
Boolean_Type = new JSType(this, &mWorld.identifiers[widenCString(builtInClasses[7].name)], Object_Type);
Void_Type = new JSType(this, &mWorld.identifiers[widenCString(builtInClasses[8].name)], Object_Type);
Unit_Type = new JSType(this, &mWorld.identifiers[widenCString(builtInClasses[9].name)], Object_Type);
Attribute_Type = new JSType(this, &mWorld.identifiers[widenCString(builtInClasses[10].name)], Object_Type);
NamedArgument_Type = new JSType(this, &mWorld.identifiers[widenCString(builtInClasses[11].name)], Object_Type);
String_Type->defineVariable(this, widenCString("fromCharCode"), NULL, String_Type, JSValue(new JSFunction(String_fromCharCode, String_Type)));

View File

@ -678,7 +678,7 @@ XXX ...couldn't get this to work...
class JSType : public JSObject {
public:
JSType(const StringAtom *name, JSType *super);
JSType(Context *cx, const StringAtom *name, JSType *super);
JSType(JSType *xClass); // used for constructing the static component type
virtual ~JSType() { } // keeping gcc happy
@ -768,6 +768,7 @@ XXX ...couldn't get this to work...
// the 'vtable'
MethodList mMethods;
const StringAtom *mClassName;
const StringAtom *mPrivateNamespace;
JSFunction *mUnaryOperators[OperatorCount]; // XXX too wasteful
@ -776,6 +777,7 @@ XXX ...couldn't get this to work...
JSObject *mPrototypeObject; // becomes the prototype for any instance
void printSlotsNStuff(Formatter& f) const;
};
@ -803,8 +805,8 @@ XXX ...couldn't get this to work...
class JSArrayType : public JSType {
public:
JSArrayType(const StringAtom *name, JSType *super)
: JSType(name, super)
JSArrayType(Context *cx, const StringAtom *name, JSType *super)
: JSType(cx, name, super)
{
}
virtual ~JSArrayType() { } // keeping gcc happy
@ -837,8 +839,8 @@ XXX ...couldn't get this to work...
class JSStringType : public JSType {
public:
JSStringType(const StringAtom *name, JSType *super)
: JSType(name, super)
JSStringType(Context *cx, const StringAtom *name, JSType *super)
: JSType(cx, name, super)
{
}
virtual ~JSStringType() { } // keeping gcc happy

View File

@ -131,9 +131,9 @@ namespace JS2Runtime {
Formatter& operator<<(Formatter& f, const Property& prop);
struct NamespaceList {
NamespaceList(const String *name, NamespaceList *next) : mName(*name), mNext(next) { }
NamespaceList(const StringAtom *name, NamespaceList *next) : mName(name), mNext(next) { }
const String mName;
const StringAtom *mName;
NamespaceList *mNext;
};

View File

@ -29,11 +29,14 @@ Package=<4>
Begin Project Dependency
Project_Dep_Name DikDik
End Project Dependency
Begin Project Dependency
Project_Dep_Name fdlibm
End Project Dependency
}}}
###############################################################################
Project: "fdlibm"=.\fdlibm\fdlibm.dsp - Package Owner=<4>
Project: "fdlibm"=.\fdlibm.dsp - Package Owner=<4>
Package=<5>
{{{