diff --git a/mozilla/js2/src/js2array.cpp b/mozilla/js2/src/js2array.cpp index b5ee66526da..81a8093cd8d 100644 --- a/mozilla/js2/src/js2array.cpp +++ b/mozilla/js2/src/js2array.cpp @@ -816,7 +816,7 @@ void initArrayObject(JS2Metadata *meta) { NULL } }; - meta->arrayClass->prototype = new ArrayInstance(meta, meta->objectClass->prototype, meta->arrayClass); + meta->arrayClass->prototype = OBJECT_TO_JS2VAL(new ArrayInstance(meta, OBJECT_TO_JS2VAL(meta->objectClass->prototype), meta->arrayClass)); meta->initBuiltinClass(meta->arrayClass, &prototypeFunctions[0], NULL, Array_Constructor, Array_Constructor); } diff --git a/mozilla/js2/src/js2boolean.cpp b/mozilla/js2/src/js2boolean.cpp index 18058839dc2..1ca6b15f359 100644 --- a/mozilla/js2/src/js2boolean.cpp +++ b/mozilla/js2/src/js2boolean.cpp @@ -105,7 +105,7 @@ namespace MetaData { { NULL } }; - meta->booleanClass->prototype = new BooleanInstance(meta, meta->objectClass->prototype, meta->booleanClass); + meta->booleanClass->prototype = OBJECT_TO_JS2VAL(new BooleanInstance(meta, OBJECT_TO_JS2VAL(meta->objectClass->prototype), meta->booleanClass)); meta->initBuiltinClass(meta->booleanClass, &prototypeFunctions[0], NULL, Boolean_Constructor, Boolean_Call); } diff --git a/mozilla/js2/src/js2date.cpp b/mozilla/js2/src/js2date.cpp index 358a3c466e8..d9f4e92dc87 100644 --- a/mozilla/js2/src/js2date.cpp +++ b/mozilla/js2/src/js2date.cpp @@ -1479,7 +1479,7 @@ void initDateObject(JS2Metadata *meta) LocalTZA = -(PRMJ_LocalGMTDifference() * msPerSecond); - meta->dateClass->prototype = new DateInstance(meta, meta->objectClass->prototype, meta->dateClass); + meta->dateClass->prototype = OBJECT_TO_JS2VAL(new DateInstance(meta, OBJECT_TO_JS2VAL(meta->objectClass->prototype), meta->dateClass)); meta->initBuiltinClass(meta->dateClass, &prototypeFunctions[0], &staticFunctions[0], Date_Constructor, Date_Call); } diff --git a/mozilla/js2/src/js2engine.cpp b/mozilla/js2/src/js2engine.cpp index 78d5186fc50..2724bc86056 100644 --- a/mozilla/js2/src/js2engine.cpp +++ b/mozilla/js2/src/js2engine.cpp @@ -588,7 +588,7 @@ namespace MetaData { case TYPE_PTR: { JS2Class *c = BytecodeContainer::getType(pc); - stdOut << " " << *c->name; + stdOut << " " << *c->getName(); pc += sizeof(JS2Class *); } break; @@ -1080,9 +1080,13 @@ namespace MetaData { } if (it == length) { if (obj->kind == SimpleInstanceKind) { - obj = (checked_cast(obj))->super; - if (obj) - return buildNameList(); + js2val protoval = (checked_cast(obj))->super; + if (!JS2VAL_IS_NULL(protoval)) { + if (JS2VAL_IS_OBJECT(protoval)) { + obj = JS2VAL_TO_OBJECT(protoval); + return buildNameList(); + } + } } return false; } diff --git a/mozilla/js2/src/js2error.cpp b/mozilla/js2/src/js2error.cpp index 90d09306261..ddbabb1e4be 100644 --- a/mozilla/js2/src/js2error.cpp +++ b/mozilla/js2/src/js2error.cpp @@ -57,7 +57,7 @@ namespace MetaData { js2val error_ConstructorCore(JS2Metadata *meta, JS2Class *errorClass, js2val arg) { - JS2Object *obj = new PrototypeInstance(meta, errorClass->prototype, errorClass); + JS2Object *obj = new SimpleInstance(meta, OBJECT_TO_JS2VAL(errorClass->prototype), errorClass); js2val thatValue = OBJECT_TO_JS2VAL(obj); if (!JS2VAL_IS_VOID(arg)) { @@ -126,9 +126,10 @@ static void initErrorClass(JS2Metadata *meta, JS2Class *c, Constructor *construc { // XXX Or make 'name' a static class member? c->construct = constructor; - c->prototype = new PrototypeInstance(meta, NULL, c); + c->prototype = new SimpleInstance(meta, JS2VAL_NULL, c); js2val nameVal = meta->engine->allocString(c->name); - meta->writeDynamicProperty(c->prototype, new Multiname(&meta->world.identifiers["name"], meta->publicNamespace), true, nameVal, RunPhase); + QualifiedName qName(meta->publicNamespace, &meta->world.identifiers["name"]) + meta->createDynamicProperty(c->prototype, &qName, nameVal, true, true); } void initErrorObject(JS2Metadata *meta) diff --git a/mozilla/js2/src/js2metadata.cpp b/mozilla/js2/src/js2metadata.cpp index 79e91fe5d7f..5dc5f9188cf 100644 --- a/mozilla/js2/src/js2metadata.cpp +++ b/mozilla/js2/src/js2metadata.cpp @@ -109,7 +109,7 @@ namespace MetaData { pb = pb->next; } if (prototype) - result->writeProperty(this, engine->length_StringAtom, INT_TO_JS2VAL(pCount), DynamicPropertyValue::READONLY); + createDynamicProperty(result, engine->length_StringAtom, INT_TO_JS2VAL(pCount), ReadAccess, true, false); pb = fnDef->parameters; compileFrame->positional = new Variable *[pCount]; compileFrame->positionalCount = pCount; @@ -2940,8 +2940,7 @@ doUnary: return mOverridden; } - - defineLocalMember +#if 0 // Find the possible override conflicts that arise from the given id and namespaces // Fall back on the currently open namespace list if no others are specified. @@ -3267,8 +3266,8 @@ static const uint8 urlCharType[256] = { SimpleInstance *fInst = new SimpleInstance(functionClass); fInst->fWrap = new FunctionWrapper(true, new ParameterFrame(JS2VAL_VOID, true), code, env); - writeDynamicProperty(glob, new Multiname(&world.identifiers[name], publicNamespace), true, OBJECT_TO_JS2VAL(fInst), RunPhase); - fInst->writeProperty(this, engine->length_StringAtom, INT_TO_JS2VAL(length), DynamicPropertyValue::READONLY | DynamicPropertyValue::PERMANENT); + createDynamicProperty(glob, &world.identifiers[name], OBJECT_TO_JS2VAL(fInst), ReadWriteAccess, false, true); + createDynamicProperty(fInst, engine->length_StringAtom, INT_TO_JS2VAL(length), ReadAccess, true, false); } static js2val Object_toString(JS2Metadata *meta, const js2val thisValue, js2val /* argv */ [], uint32 /* argc */) @@ -3514,11 +3513,7 @@ XXX see EvalAttributeExpression, where identifiers are being handled for now... } - void SimpleInstance::writeProperty(JS2Metadata * /* meta */, const String *name, js2val newValue, uint32 flags) - { - ASSERT(false); - } - +/* void ArrayInstance::writeProperty(JS2Metadata *meta, const String *name, js2val newValue, uint32 flags) { // An index has to pass the test that : @@ -3545,7 +3540,7 @@ XXX see EvalAttributeExpression, where identifiers are being handled for now... setLength(meta, this, index + 1); } } - +*/ InstanceBinding *JS2Metadata::findLocalInstanceMember(JS2Class *limit, Multiname *multiname, Access access) { @@ -3566,7 +3561,7 @@ XXX see EvalAttributeExpression, where identifiers are being handled for now... return result; } - InstanceMember* JS2Metadata::findBaseInstanceMember(JS2Class *limit, Multiname *multiname, Access access) + InstanceMember *JS2Metadata::findBaseInstanceMember(JS2Class *limit, Multiname *multiname, Access access) { InstanceMember *result = NULL; if (limit->super) { @@ -3580,7 +3575,7 @@ XXX see EvalAttributeExpression, where identifiers are being handled for now... // whose access includes access. The caller of getDerivedInstanceMember ensures that such a member always exists. // If accesses is readWrite then it is possible that this search could find both a getter and a setter defined in the same class; // in this case either the getter or the setter is returned at the implementation's discretion - InstanceMember *getDerivedInstanceMember(JS2Class *c, InstanceMember *mBase, Multiname *multiname, Access access) + InstanceMember *JS2Metadata::getDerivedInstanceMember(JS2Class *c, InstanceMember *mBase, Multiname *multiname, Access access) { InstanceBindingEntry **ibeP = c->instanceBindings[*multiname->name]; if (ibeP) { @@ -3852,7 +3847,7 @@ XXX see EvalAttributeExpression, where identifiers are being handled for now... Multiname mn(qName); if ( (meta->findBaseInstanceMember(limit, &mn, ReadAccess, NULL) == NULL) && (meta->findCommonMember(base, &mn, ReadAccess, true, NULL) == NULL) ) { - meta->createDynamicProperty(JS2VAL_TO_OBJECT(base), &qName, newValue, ReadWriteAccess); + meta->createDynamicProperty(JS2VAL_TO_OBJECT(base), &qName, newValue, ReadWriteAccess, false, true); return true; } } @@ -3961,10 +3956,10 @@ XXX see EvalAttributeExpression, where identifiers are being handled for now... } // The caller must make sure that the created property does not already exist and does not conflict with any other property. - void JS2Metadata::createDynamicProperty(JS2Object *obj, QualifiedName *qName, js2val initVal, Access access) + void JS2Metadata::createDynamicProperty(JS2Object *obj, QualifiedName *qName, js2val initVal, Access access, bool sealed, bool enumerable) { - DynamicVariable *dv = new DynamicVariable(initVal); - LocalBinding *new_b = new LocalBinding(access, dv); + DynamicVariable *dv = new DynamicVariable(initVal, sealed); + LocalBinding *new_b = new LocalBinding(access, dv, enumerable); LocalBindingMap *lMap; if (obj->kind == SimpleInstanceKind) lMap = &checked_cast(obj)->localBindings; @@ -4281,10 +4276,10 @@ XXX see EvalAttributeExpression, where identifiers are being handled for now... // Construct a Simple instance of a class. Set the // initial value of all slots to uninitialized. - SimpleInstance::SimpleInstance(JS2Metadata *meta, JS2Object *parent, JS2Class *type) + SimpleInstance::SimpleInstance(JS2Metadata *meta, js2val parent, JS2Class *type) : JS2Object(SimpleInstanceKind), sealed(false), - super(OBJECT_TO_JS2VAL(parent)), + super(parent), type(type), slots(new Slot[type->slotCount]), fWrap(NULL) diff --git a/mozilla/js2/src/js2metadata.h b/mozilla/js2/src/js2metadata.h index d28b8efdb3e..ca431c061c7 100644 --- a/mozilla/js2/src/js2metadata.h +++ b/mozilla/js2/src/js2metadata.h @@ -64,6 +64,7 @@ typedef bool (Write)(JS2Metadata *meta, js2val base, JS2Class *limit, Multiname typedef bool (DeleteProperty)(JS2Metadata *meta, js2val base, JS2Class *limit, Multiname *multiname, LookupKind *lookupKind, bool *result); typedef bool (BracketRead)(JS2Metadata *meta, js2val base, JS2Class *limit, Multiname *multiname, Phase phase, js2val *rval); typedef bool (BracketWrite)(JS2Metadata *meta, js2val base, JS2Class *limit, Multiname *multiname, js2val newValue); +typedef bool (BracketDelete)(JS2Metadata *meta, js2val base, JS2Class *limit, Multiname *multiname, bool *result); extern void initDateObject(JS2Metadata *meta); extern void initStringObject(JS2Metadata *meta); @@ -195,14 +196,12 @@ public: void *operator new(size_t s) { return alloc(s); } void operator delete(void *p) { unalloc(p); } - virtual void markChildren() { } + virtual void markChildren() { } // XXX !!!! XXXX these are supposed to not have vtables !!!! bool isMarked() { return ((PondScum *)this)[-1].isMarked(); } void markObject() { ((PondScum *)this)[-1].mark(); } static void mark(const void *p) { ((PondScum *)p)[-1].mark(); } static void markJS2Value(js2val v); - - virtual void writeProperty(JS2Metadata *meta, const String *name, js2val newValue, uint32 flags) { ASSERT(false); } }; class RootKeeper { @@ -354,7 +353,7 @@ public: class DynamicVariable : public LocalMember { public: DynamicVariable() : LocalMember(Member::DynamicVariableKind), value(JS2VAL_UNDEFINED), sealed(false) { } - DynamicVariable(js2val value) : LocalMember(Member::DynamicVariableKind), value(value), sealed(false) { } + DynamicVariable(js2val value, bool sealed) : LocalMember(Member::DynamicVariableKind), value(value), sealed(sealed) { } js2val value; // This variable's current value // XXX may be an uninstantiated function at compile time @@ -402,7 +401,7 @@ public: // the other binding is for writing only). class LocalBinding { public: - LocalBinding(AccessSet accesses, LocalMember *content) : accesses(accesses), content(content), xplicit(false) { } + LocalBinding(AccessSet accesses, LocalMember *content, bool enumerable) : accesses(accesses), content(content), xplicit(false), enumerable(enumerable) { } // The qualified name is to be inferred from the map where this binding is kept // QualifiedName qname; // The qualified name bound by this binding @@ -410,6 +409,7 @@ public: AccessSet accesses; LocalMember *content; // The member to which this qualified name was bound bool xplicit; // true if this binding should not be imported into the global scope by an import statement + bool enumerable; }; class InstanceMember : public Member { @@ -608,7 +608,7 @@ private: class JS2Class : public NonWithFrame { public: - JS2Class(JS2Class *super, JS2Object *proto, Namespace *privateNamespace, bool dynamic, bool allowNull, bool final, const String *name); + JS2Class(JS2Class *super, js2val proto, Namespace *privateNamespace, bool dynamic, bool allowNull, bool final, const String *name); const String *getName() { return typeofString; } @@ -616,7 +616,7 @@ public: InstanceBindingMap instanceBindings; // Map of qualified names to instance members defined in this class InstanceVariable **instanceInitOrder; // List of instance variables defined in this class in the order in which they are initialised bool complete; // true after all members of this class have been added to this CLASS record - JS2Object *prototype; // An object that serves as this class's prototype for compatibility with ECMAScript 3; may be null + js2val prototype; // The default value of the super field of newly created simple instances of this class; for most classes const String *typeofString; Namespace *privateNamespace; // This class's private namespace bool dynamic; // true if this class or any of its ancestors was defined with the dynamic attribute @@ -632,9 +632,11 @@ public: Read *read; - Write *write; + Write *write; + DeleteProperty *deleteProperty; BracketRead *bracketRead; - BracketWrite *bracketWrite; + BracketWrite *bracketWrite; + BracketDelete *bracketDelete; bool isAncestor(JS2Class *heir); @@ -688,10 +690,10 @@ public: // Instances which do not respond to the function call or new operators are represented as SIMPLEINSTANCE records class SimpleInstance : public JS2Object { public: - SimpleInstance(JS2Metadata *meta, JS2Object *parent, JS2Class *type); + SimpleInstance(JS2Metadata *meta, js2val parent, JS2Class *type); LocalBindingMap localBindings; - js2val super; + js2val super; // Optional link ot the next object in this instance's prototype chain bool sealed; JS2Class *type; // This instance's type Slot *slots; // A set of slots that hold this instance's fixed property values @@ -700,16 +702,13 @@ public: virtual void markChildren(); virtual ~SimpleInstance() { } - - virtual void writeProperty(JS2Metadata *meta, const String *name, js2val newValue, uint32 flags); - }; // Date instances are simple instances created by the Date class, they have an extra field // that contains the millisecond count class DateInstance : public SimpleInstance { public: - DateInstance(JS2Metadata *meta, JS2Object *parent, JS2Class *type) : SimpleInstance(meta, parent, type) { } + DateInstance(JS2Metadata *meta, js2val parent, JS2Class *type) : SimpleInstance(meta, parent, type) { } float64 ms; }; @@ -718,7 +717,7 @@ public: // that contains the string data class StringInstance : public SimpleInstance { public: - StringInstance(JS2Metadata *meta, JS2Object *parent, JS2Class *type) : SimpleInstance(meta, parent, type), mValue(NULL) { } + StringInstance(JS2Metadata *meta, js2val parent, JS2Class *type) : SimpleInstance(meta, parent, type), mValue(NULL) { } String *mValue; // has been allocated by engine in the GC'able Pond @@ -730,7 +729,7 @@ public: // that contains the float64 data class NumberInstance : public SimpleInstance { public: - NumberInstance(JS2Metadata *meta, JS2Object *parent, JS2Class *type) : SimpleInstance(meta, parent, type), mValue(0.0) { } + NumberInstance(JS2Metadata *meta, js2val parent, JS2Class *type) : SimpleInstance(meta, parent, type), mValue(0.0) { } float64 mValue; virtual ~NumberInstance() { } @@ -740,7 +739,7 @@ public: // that contains the bool data class BooleanInstance : public SimpleInstance { public: - BooleanInstance(JS2Metadata *meta, JS2Object *parent, JS2Class *type) : SimpleInstance(meta, parent, type), mValue(false) { } + BooleanInstance(JS2Metadata *meta, js2val parent, JS2Class *type) : SimpleInstance(meta, parent, type), mValue(false) { } bool mValue; virtual ~BooleanInstance() { } @@ -750,7 +749,7 @@ public: // that contains a pointer to the function implementation class FunctionInstance : public SimpleInstance { public: - FunctionInstance(JS2Metadata *meta, JS2Object *parent, JS2Class *type); + FunctionInstance(JS2Metadata *meta, js2val parent, JS2Class *type); FunctionWrapper *fWrap; @@ -763,9 +762,8 @@ public: // are added. class ArrayInstance : public SimpleInstance { public: - ArrayInstance(JS2Metadata *meta, JS2Object *parent, JS2Class *type) : SimpleInstance(meta, parent, type) { setLength(meta, this, 0); } + ArrayInstance(JS2Metadata *meta, js2val parent, JS2Class *type) : SimpleInstance(meta, parent, type) { setLength(meta, this, 0); } - virtual void writeProperty(JS2Metadata *meta, const String *name, js2val newValue, uint32 flags); virtual ~ArrayInstance() { } }; @@ -773,7 +771,7 @@ public: // that contains the RegExp object class RegExpInstance : public SimpleInstance { public: - RegExpInstance(JS2Metadata *meta, JS2Object *parent, JS2Class *type) : SimpleInstance(meta, parent, type) { } + RegExpInstance(JS2Metadata *meta, js2val parent, JS2Class *type) : SimpleInstance(meta, parent, type) { } void setLastIndex(JS2Metadata *meta, js2val a); void setGlobal(JS2Metadata *meta, js2val a); @@ -801,8 +799,8 @@ public: virtual ~AlienInstance() { } - virtual bool readProperty(Multiname *m, js2val *rval); // return true/false to signal whether the property is available - virtual void writeProperty(Multiname *m, js2val rval); + bool readProperty(Multiname *m, js2val *rval); // return true/false to signal whether the property is available + void writeProperty(Multiname *m, js2val rval); }; // A helper class for 'for..in' statements @@ -1144,35 +1142,46 @@ public: DynamicVariable *defineHoistedVar(Environment *env, const String *id, StmtNode *p, bool isVar); Multiname *defineLocalMember(Environment *env, const String *id, NamespaceList *namespaces, Attribute::OverrideModifier overrideMod, bool xplicit, Access access, LocalMember *m, size_t pos); - OverrideStatusPair *defineInstanceMember(JS2Class *c, Context *cxt, const String *id, NamespaceList *namespaces, Attribute::OverrideModifier overrideMod, bool xplicit, Access access, InstanceMember *m, size_t pos); - OverrideStatus *resolveOverrides(JS2Class *c, Context *cxt, const String *id, NamespaceList *namespaces, Access access, bool expectMethod, size_t pos); - OverrideStatus *searchForOverrides(JS2Class *c, const String *id, NamespaceList *namespaces, Access access, size_t pos); + InstanceMember *defineInstanceMember(JS2Class *c, Context *cxt, const String *id, NamespaceList *namespaces, + Attribute::OverrideModifier overrideMod, bool xplicit, + InstanceMember *m, size_t pos); + InstanceMember *searchForOverrides(JS2Class *c, Multiname *multiname, Access access, size_t pos); InstanceMember *findInstanceMember(JS2Class *c, QualifiedName *qname, Access access); Slot *findSlot(js2val thisObjVal, InstanceVariable *id); - bool findLocalMember(JS2Class *c, Multiname *multiname, Access access, Phase phase, MemberDescriptor *result); + LocalMember *findLocalMember(JS2Object *container, Multiname *multiname, Access access); + js2val getSuperObject(JS2Object *obj); JS2Class *getVariableType(Variable *v, Phase phase, size_t pos); + InstanceMember *getDerivedInstanceMember(JS2Class *c, InstanceMember *mBase, Multiname *multiname, Access access) + InstanceMember *findBaseInstanceMember(JS2Class *limit, Multiname *multiname, Access access); + InstanceBinding *findLocalInstanceMember(JS2Class *limit, Multiname *multiname, Access access); js2val invokeFunction(const char *fname); bool invokeFunctionOnObject(js2val thisValue, const String *fnName, js2val &result); js2val invokeFunction(JS2Object *fnObj, js2val thisValue, js2val *argv, uint32 argc); - bool readProperty(js2val *container, Multiname *multiname, LookupKind *lookupKind, Phase phase, js2val *rval); - bool readProperty(Frame *pf, Multiname *multiname, LookupKind *lookupKind, Phase phase, js2val *rval); - bool readDynamicProperty(JS2Object *container, Multiname *multiname, LookupKind *lookupKind, Phase phase, js2val *rval); + void createDynamicProperty(JS2Object *obj, QualifiedName *qName, js2val initVal, Access access, bool sealed, bool enumerable); + void createDynamicProperty(JS2Object *obj, const String *name, js2val initVal, Access access, bool sealed, bool enumerable) + { QualifiedName qName(publicNamespace, qName); createDynamicProperty(obj, &qName, initVal, access, sealed, enumerable); } + + + +// bool readProperty(js2val *container, Multiname *multiname, LookupKind *lookupKind, Phase phase, js2val *rval); +// bool readProperty(Frame *pf, Multiname *multiname, LookupKind *lookupKind, Phase phase, js2val *rval); +// bool readDynamicProperty(JS2Object *container, Multiname *multiname, LookupKind *lookupKind, Phase phase, js2val *rval); bool readLocalMember(LocalMember *m, Phase phase, js2val *rval); bool readInstanceMember(js2val containerVal, JS2Class *c, QualifiedName *qname, Phase phase, js2val *rval); JS2Object *lookupDynamicProperty(JS2Object *obj, const String *name); bool JS2Metadata::hasOwnProperty(JS2Object *obj, const String *name); - bool writeProperty(js2val container, Multiname *multiname, LookupKind *lookupKind, bool createIfMissing, js2val newValue, Phase phase); - bool writeProperty(Frame *container, Multiname *multiname, LookupKind *lookupKind, bool createIfMissing, js2val newValue, Phase phase, bool initFlag); - bool writeDynamicProperty(JS2Object *container, Multiname *multiname, bool createIfMissing, js2val newValue, Phase phase); +// bool writeProperty(js2val container, Multiname *multiname, LookupKind *lookupKind, bool createIfMissing, js2val newValue, Phase phase); +// bool writeProperty(Frame *container, Multiname *multiname, LookupKind *lookupKind, bool createIfMissing, js2val newValue, Phase phase, bool initFlag); +// bool writeDynamicProperty(JS2Object *container, Multiname *multiname, bool createIfMissing, js2val newValue, Phase phase); bool writeLocalMember(LocalMember *m, js2val newValue, Phase phase, bool initFlag); bool writeInstanceMember(js2val containerVal, JS2Class *c, QualifiedName *qname, js2val newValue, Phase phase); - bool deleteProperty(Frame *container, Multiname *multiname, LookupKind *lookupKind, Phase phase, bool *result); - bool deleteProperty(js2val container, Multiname *multiname, LookupKind *lookupKind, Phase phase, bool *result); - bool deleteDynamicProperty(JS2Object *container, Multiname *multiname, LookupKind *lookupKind, bool *result); +// bool deleteProperty(Frame *container, Multiname *multiname, LookupKind *lookupKind, Phase phase, bool *result); +// bool deleteProperty(js2val container, Multiname *multiname, LookupKind *lookupKind, Phase phase, bool *result); +// bool deleteDynamicProperty(JS2Object *container, Multiname *multiname, LookupKind *lookupKind, bool *result); bool deleteLocalMember(LocalMember *m, bool *result); bool deleteInstanceMember(JS2Class *c, QualifiedName *qname, bool *result); diff --git a/mozilla/js2/src/js2op_access.cpp b/mozilla/js2/src/js2op_access.cpp index b3c6e4cd764..390dccb0251 100644 --- a/mozilla/js2/src/js2op_access.cpp +++ b/mozilla/js2/src/js2op_access.cpp @@ -39,7 +39,7 @@ pc += sizeof(short); b = pop(); - JS2Class *limit = objectType(b); + JS2Class *limit = meta->objectType(b); if (!limit->read(meta, b, limit, mn, &lookup, RunPhase, &a)) meta->reportError(Exception::propertyAccessError, "No property named {0}", errorPos(), mn->name); push(a); @@ -53,8 +53,8 @@ pc += sizeof(short); b = pop(); bool result; - JS2Class *limit = objectType(b); - if (!limit->deleteProperty(meta, b, limit, mn, &lookup, RunPhase, &result)) + JS2Class *limit = meta->objectType(b); + if (!limit->deleteProperty(meta, b, limit, mn, &lookup, &result)) push(JS2VAL_FALSE); else push(BOOLEAN_TO_JS2VAL(result)); @@ -70,7 +70,7 @@ Multiname *mn = bCon->mMultinameList[BytecodeContainer::getShort(pc)]; pc += sizeof(short); b = pop(); - JS2Class *limit = objectType(b); + JS2Class *limit = meta->objectType(b); if (!limit->write(meta, b, limit, mn, &lookup, true, a)) meta->reportError(Exception::propertyAccessError, "No property named {0}", errorPos(), mn->name); push(a); @@ -84,7 +84,7 @@ Multiname *mn = bCon->mMultinameList[BytecodeContainer::getShort(pc)]; pc += sizeof(short); b = pop(); - JS2Class *limit = objectType(b); + JS2Class *limit = meta->objectType(b); if (!limit->read(meta, b, limit, mn, &lookup, RunPhase, &a)) meta->reportError(Exception::propertyAccessError, "No property named {0}", errorPos(), mn->name); push(b); @@ -140,7 +140,7 @@ { Multiname *mn = bCon->mMultinameList[BytecodeContainer::getShort(pc)]; pc += sizeof(short); - a = meta->env->lexicalRead(meta, mn, phase); + meta->env->lexicalRead(meta, mn, phase, &a); push(JS2VAL_NULL); push(a); } @@ -153,8 +153,8 @@ b = pop(); astr = meta->toString(indexVal); Multiname mn(&meta->world.identifiers[*astr], meta->publicNamespace); - JS2Class *limit = objectType(b); - if (!limit->bracketRead(meta, b, limit, mn, RunPhase, &a)) + JS2Class *limit = meta->objectType(b); + if (!limit->bracketRead(meta, b, limit, &mn, RunPhase, &a)) meta->reportError(Exception::propertyAccessError, "No property named {0}", errorPos(), mn.name); push(a); indexVal = JS2VAL_VOID; @@ -170,8 +170,8 @@ astr = meta->toString(indexVal); Multiname mn(&meta->world.identifiers[*astr], meta->publicNamespace); bool result; - JS2Class *limit = objectType(b); - if (!limit->bracketDelete(meta, b, limit, mn, &result)) + JS2Class *limit = meta->objectType(b); + if (!limit->bracketDelete(meta, b, limit, &mn, &result)) push(JS2VAL_FALSE); else push(BOOLEAN_TO_JS2VAL(result)); @@ -189,9 +189,8 @@ b = pop(); astr = meta->toString(indexVal); Multiname mn(&meta->world.identifiers[*astr], meta->publicNamespace); - meta->writeProperty(b, &mn, &lookup, true, a, RunPhase); - JS2Class *limit = objectType(b); - if (!limit->bracketWrite(meta, b, limit, mn, a)) + JS2Class *limit = meta->objectType(b); + if (!limit->bracketWrite(meta, b, limit, &mn, a)) meta->reportError(Exception::propertyAccessError, "No property named {0}", errorPos(), mn.name); push(a); indexVal = JS2VAL_VOID; @@ -207,8 +206,8 @@ b = top(); astr = meta->toString(indexVal); Multiname mn(&meta->world.identifiers[*astr], meta->publicNamespace); - JS2Class *limit = objectType(b); - if (!limit->bracketRead(meta, b, limit, mn, RunPhase, &a)) + JS2Class *limit = meta->objectType(b); + if (!limit->bracketRead(meta, b, limit, &mn, RunPhase, &a)) meta->reportError(Exception::propertyAccessError, "No property named {0}", errorPos(), mn.name); push(a); indexVal = JS2VAL_VOID; @@ -225,8 +224,8 @@ astr = meta->toString(indexVal); push(STRING_TO_JS2VAL(astr)); Multiname mn(&meta->world.identifiers[*astr], meta->publicNamespace); - JS2Class *limit = objectType(b); - if (!limit->bracketRead(meta, b, limit, mn, RunPhase, &a)) + JS2Class *limit = meta->objectType(b); + if (!limit->bracketRead(meta, b, limit, &mn, RunPhase, &a)) meta->reportError(Exception::propertyAccessError, "No property named {0}", errorPos(), mn.name); push(a); indexVal = JS2VAL_VOID; @@ -243,8 +242,8 @@ ASSERT(JS2VAL_IS_STRING(indexVal)); b = pop(); Multiname mn(&meta->world.identifiers[*JS2VAL_TO_STRING(indexVal)], meta->publicNamespace); - JS2Class *limit = objectType(b); - if (!limit->bracketWrite(meta, b, limit, mn, a)) + JS2Class *limit = meta->objectType(b); + if (!limit->bracketWrite(meta, b, limit, &mn, a)) meta->reportError(Exception::propertyAccessError, "No property named {0}", errorPos(), mn.name); push(a); indexVal = JS2VAL_VOID; diff --git a/mozilla/js2/src/js2op_invocation.cpp b/mozilla/js2/src/js2op_invocation.cpp index b839c775292..1c02cecfe72 100644 --- a/mozilla/js2/src/js2op_invocation.cpp +++ b/mozilla/js2/src/js2op_invocation.cpp @@ -63,8 +63,7 @@ // XXX this won't last - if a non-primitive is returned from the function, // it's supposed to supplant the constructed object. XXX and I think the // stack is out of balance anyway... - js2val protoVal; - JS2Object *protoObj = meta->objectClass->prototype; + js2val protoVal = OBJECT_TO_JS2VAL(meta->objectClass->prototype); Multiname mn(prototype_StringAtom); // gc safe because the content is rooted elsewhere LookupKind lookup(true, JS2VAL_NULL); // make it a lexical lookup since we want it to // fail if 'prototype' hasn't been defined @@ -72,7 +71,6 @@ if (meta->readProperty(&a, &mn, &lookup, RunPhase, &protoVal)) { if (!JS2VAL_IS_OBJECT(protoVal)) meta->reportError(Exception::badValueError, "Non-object prototype value", errorPos()); - protoObj = JS2VAL_TO_OBJECT(protoVal); } if (fWrap->code) { // native code, pass pointer to argument base @@ -83,10 +81,7 @@ else { pFrame = new ParameterFrame(fWrap->compileFrame); pFrame->instantiate(meta->env); - if (protoObj->kind == PrototypeInstanceKind) - baseVal = OBJECT_TO_JS2VAL(new PrototypeInstance(meta, protoObj, (checked_cast(protoObj))->type)); - else - baseVal = OBJECT_TO_JS2VAL(new PrototypeInstance(meta, protoObj, meta->objectClass)); + baseVal = OBJECT_TO_JS2VAL(new SimpleInstance(meta, protoVal, meta->objectType(protoVal))); pFrame->thisObject = baseVal; pFrame->assignArguments(meta, obj, base(argCount), argCount); jsr(phase, fWrap->bCon, base(argCount + 1) - execStack, baseVal, fWrap->env); // seems out of order, but we need to catch the current top frame @@ -116,11 +111,6 @@ && (meta->objectType(b) == meta->functionClass)) { fWrap = (checked_cast(fObj))->fWrap; } - else - if ((fObj->kind == PrototypeInstanceKind) - && ((checked_cast(fObj))->type == meta->functionClass)) { - fWrap = (checked_cast(fObj))->fWrap; - } if (fWrap) { if (fWrap->compileFrame->prototype) { if (JS2VAL_IS_VOID(a) || JS2VAL_IS_NULL(a)) { @@ -262,34 +252,39 @@ if (!JS2VAL_IS_OBJECT(b)) meta->reportError(Exception::typeError, "Object expected for instanceof", errorPos()); JS2Object *obj = JS2VAL_TO_OBJECT(b); - if ((obj->kind == PrototypeInstanceKind) - && (checked_cast(obj)->type == meta->functionClass)) { + if ((obj->kind == SimpleInstanceKind) + && (checked_cast(obj)->type == meta->functionClass)) { // XXX this is [[hasInstance]] from ECMA3 if (!JS2VAL_IS_OBJECT(a)) push(JS2VAL_FALSE); else { - if (JS2VAL_TO_OBJECT(a)->kind != PrototypeInstanceKind) - meta->reportError(Exception::typeError, "PrototypeInstance expected for instanceof", errorPos()); - JS2Object *a_protoObj = checked_cast(JS2VAL_TO_OBJECT(a))->parent; + JS2Object *aObj = JS2VAL_TO_OBJECT(a); + if (aObj->kind != SimpleInstanceKind) + meta->reportError(Exception::typeError, "Prototype instance expected for instanceof", errorPos()); + js2val a_protoVal = checked_cast(aObj)->super; js2val b_protoVal; - JS2Object *b_protoObj = NULL; Multiname mn(prototype_StringAtom); // gc safe because the content is rooted elsewhere LookupKind lookup(true, JS2VAL_NULL); // make it a lexical lookup since we want it to // fail if 'prototype' hasn't been defined // XXX (prototype should always exist for functions) - if (meta->readProperty(&a, &mn, &lookup, RunPhase, &b_protoVal)) { + JS2Class *limit = meta->objectType(b); + if (limit->read(meta, b, limit, &mn, &lookup, RunPhase, &b_protoVal)) { if (!JS2VAL_IS_OBJECT(b_protoVal)) meta->reportError(Exception::typeError, "Non-object prototype value in instanceOf", errorPos()); - b_protoObj = JS2VAL_TO_OBJECT(b_protoVal); } bool result = false; - while (a_protoObj) { - if (b_protoObj == a_protoObj) { + while (!JS2VAL_IS_NULL(a_protoVal) && !JS2VAL_IS_UNDEFINED(a_protoVal)) { + if (b_protoVal == a_protoVal) { result = true; break; } - a_protoObj = checked_cast(a_protoObj)->parent; + if (!JS2VAL_IS_OBJECT(a_protoVal)) + meta->reportError(Exception::typeError, "Non-object prototype value in instanceOf", errorPos()); + aObj = JS2VAL_TO_OBJECT(a_protoVal); + if (aObj->kind != SimpleInstanceKind) + meta->reportError(Exception::typeError, "Prototype instance expected for instanceof", errorPos()); + a_protoVal = checked_cast(aObj)->super; } push(BOOLEAN_TO_JS2VAL(result)); } @@ -300,19 +295,25 @@ if (!JS2VAL_IS_OBJECT(a)) push(JS2VAL_FALSE); else { - if (JS2VAL_TO_OBJECT(a)->kind != PrototypeInstanceKind) - meta->reportError(Exception::typeError, "PrototypeInstance expected for instanceof", errorPos()); - JS2Object *a_protoObj = checked_cast(JS2VAL_TO_OBJECT(a))->parent; + JS2Object *aObj = JS2VAL_TO_OBJECT(a); + if (aObj->kind != SimpleInstanceKind) + meta->reportError(Exception::typeError, "Prototype instance expected for instanceof", errorPos()); + js2val a_protoVal = checked_cast(aObj)->super; - JS2Object *b_protoObj = checked_cast(obj)->prototype; + js2val b_protoVal = checked_cast(obj)->prototype; bool result = false; - while (a_protoObj) { - if (b_protoObj == a_protoObj) { + while (!JS2VAL_IS_NULL(a_protoVal) && !JS2VAL_IS_UNDEFINED(a_protoVal)) { + if (b_protoVal == a_protoVal) { result = true; break; } - a_protoObj = checked_cast(a_protoObj)->parent; + if (!JS2VAL_IS_OBJECT(a_protoVal)) + meta->reportError(Exception::typeError, "Non-object prototype value in instanceOf", errorPos()); + aObj = JS2VAL_TO_OBJECT(a_protoVal); + if (aObj->kind != SimpleInstanceKind) + meta->reportError(Exception::typeError, "Prototype instance expected for instanceof", errorPos()); + a_protoVal = checked_cast(aObj)->super; } push(BOOLEAN_TO_JS2VAL(result)); } diff --git a/mozilla/js2/src/js2op_literal.cpp b/mozilla/js2/src/js2op_literal.cpp index 920bd93f2ec..0357de09bda 100644 --- a/mozilla/js2/src/js2op_literal.cpp +++ b/mozilla/js2/src/js2op_literal.cpp @@ -115,16 +115,14 @@ { uint16 argCount = BytecodeContainer::getShort(pc); pc += sizeof(uint16); - PrototypeInstance *pInst = new PrototypeInstance(meta, meta->objectClass->prototype, meta->objectClass); - baseVal = OBJECT_TO_JS2VAL(pInst); + SimpleInstance *sInst = new SimpleInstance(meta, OBJECT_TO_JS2VAL(meta->objectClass->prototype), meta->objectClass); + baseVal = OBJECT_TO_JS2VAL(sInst); for (uint16 i = 0; i < argCount; i++) { a = pop(); ASSERT(JS2VAL_IS_STRING(a)); astr = JS2VAL_TO_STRING(a); - const StringAtom &nameAtom = meta->world.identifiers[*astr]; b = pop(); - DynamicPropertyBinding *dpb = new DynamicPropertyBinding(nameAtom, DynamicPropertyValue(b, DynamicPropertyValue::ENUMERATE)); - pInst->dynamicProperties.insert(dpb->name, dpb); + meta->createDynamicProperty(sInst, astr, b, false, true); } push(baseVal); baseVal = JS2VAL_VOID; @@ -136,12 +134,11 @@ { uint16 argCount = BytecodeContainer::getShort(pc); pc += sizeof(uint16); - ArrayInstance *aInst = new ArrayInstance(meta, meta->arrayClass->prototype, meta->arrayClass); + ArrayInstance *aInst = new ArrayInstance(meta, OBJECT_TO_JS2VAL(meta->arrayClass->prototype), meta->arrayClass); baseVal = OBJECT_TO_JS2VAL(aInst); for (uint16 i = 0; i < argCount; i++) { b = pop(); - DynamicPropertyBinding *dpb = new DynamicPropertyBinding(*numberToString((argCount - 1) - i), DynamicPropertyValue(b, DynamicPropertyValue::ENUMERATE)); - aInst->dynamicProperties.insert(dpb->name, dpb); + meta->createDynamicProperty(aInst, numberToString((argCount - 1) - i), b, false, true); } setLength(meta, aInst, argCount); push(baseVal); diff --git a/mozilla/js2/src/parser.h b/mozilla/js2/src/parser.h index e9d142f4d12..059b0542529 100644 --- a/mozilla/js2/src/parser.h +++ b/mozilla/js2/src/parser.h @@ -63,8 +63,6 @@ namespace JavaScript { class JS2Class; class Member; class Multiname; - class OverrideStatus; - typedef std::pair OverrideStatusPair; class FunctionWrapper; class BlockFrame; typedef uint32 LabelID;