From 9dfd6e2fd011644b34a9c70feed6f9b51aacf28d Mon Sep 17 00:00:00 2001 From: "rogerl%netscape.com" Date: Fri, 28 Mar 2003 18:18:20 +0000 Subject: [PATCH] !!! BROKEN !!! git-svn-id: svn://10.0.0.236/trunk@140425 18797224-902f-48f8-a5cc-f745e15eee43 --- mozilla/js2/src/js2array.cpp | 4 +- mozilla/js2/src/js2metadata.cpp | 90 ++++++++++++++++++--------------- mozilla/js2/src/js2metadata.h | 11 ++-- 3 files changed, 60 insertions(+), 45 deletions(-) diff --git a/mozilla/js2/src/js2array.cpp b/mozilla/js2/src/js2array.cpp index 81a8093cd8d..4b524f2bfb0 100644 --- a/mozilla/js2/src/js2array.cpp +++ b/mozilla/js2/src/js2array.cpp @@ -61,8 +61,8 @@ uint32 getLength(JS2Metadata *meta, JS2Object *obj) LookupKind lookup(false, JS2VAL_NULL); uint32 length = 0; js2val result; - meta->mn1->name = meta->engine->length_StringAtom; - if (meta->readDynamicProperty(obj, meta->mn1, &lookup, RunPhase, &result)) + JS2Class *c = meta->objectType(obj); + if (c->readPublic(meta, obj, c, meta->engine->length_StringAtom, &lookup, RunPhase, &result)) length = toUInt32(meta->toInteger(result)); return length; } diff --git a/mozilla/js2/src/js2metadata.cpp b/mozilla/js2/src/js2metadata.cpp index 5dc5f9188cf..87233aa265c 100644 --- a/mozilla/js2/src/js2metadata.cpp +++ b/mozilla/js2/src/js2metadata.cpp @@ -3346,11 +3346,11 @@ XXX see EvalAttributeExpression, where identifiers are being handled for now... /*** ECMA 3 Global Object ***/ // Non-function properties of the global object : 'undefined', 'NaN' and 'Infinity' - writeDynamicProperty(glob, new Multiname(engine->undefined_StringAtom, publicNamespace), true, JS2VAL_UNDEFINED, RunPhase); - writeDynamicProperty(glob, new Multiname(&world.identifiers["NaN"], publicNamespace), true, engine->nanValue, RunPhase); - writeDynamicProperty(glob, new Multiname(&world.identifiers["Infinity"], publicNamespace), true, engine->posInfValue, RunPhase); + createDynamicProperty(glob, engine->undefined_StringAtom, JS2VAL_UNDEFINED, ReadAccess, true, false); + createDynamicProperty(glob, &world.identifiers["NaN"], engine->nanValue, ReadAccess, true, false); + createDynamicProperty(glob, &world.identifiers["Infinity"], engine->posInfValue, ReadAccess, true, false); // XXX add 'version()' - writeDynamicProperty(glob, new Multiname(&world.identifiers["version"], publicNamespace), true, INT_TO_JS2VAL(0), RunPhase); + createDynamicProperty(glob, &world.identifiers["version"], INT_TO_JS2VAL(0), ReadAccess, true, false); // Function properties of the global object addGlobalObjectFunction("isNaN", GlobalObject_isNaN, 1); addGlobalObjectFunction("eval", GlobalObject_eval, 1); @@ -3381,8 +3381,8 @@ XXX see EvalAttributeExpression, where identifiers are being handled for now... // Adding 'toString' to the Object.prototype XXX Or make this a static class member? FunctionInstance *fInst = new FunctionInstance(this, functionClass->prototype, functionClass); fInst->fWrap = new FunctionWrapper(true, new ParameterFrame(JS2VAL_VOID, true), Object_toString, env); - objectClass->prototype->writeProperty(this, engine->toString_StringAtom, OBJECT_TO_JS2VAL(fInst), 0); - fInst->writeProperty(this, engine->length_StringAtom, INT_TO_JS2VAL(0), DynamicPropertyValue::READONLY); + createDynamicProperty(objectClass->prototype, engine->toString_StringAtom, OBJECT_TO_JS2VAL(fInst), ReadAccess, true, false); + createDynamicProperty(fInst, engine->length_StringAtom, INT_TO_JS2VAL(0), ReadAccess, true, false); /*** ECMA 3 Date Class ***/ MAKEBUILTINCLASS(dateClass, objectClass, true, true, true, engine->allocStringPtr(&world.identifiers["Date"]), JS2VAL_NULL); @@ -3449,27 +3449,8 @@ XXX see EvalAttributeExpression, where identifiers are being handled for now... } - // objectType(o) returns an OBJECT o's most specific type. - JS2Class *JS2Metadata::objectType(js2val objVal) + JS2Class *JS2Metadata::objectType(JS2Object *obj) { - if (JS2VAL_IS_VOID(objVal)) - return undefinedClass; - if (JS2VAL_IS_NULL(objVal)) - return nullClass; - if (JS2VAL_IS_BOOLEAN(objVal)) - return booleanClass; - if (JS2VAL_IS_NUMBER(objVal)) - return numberClass; - if (JS2VAL_IS_STRING(objVal)) { - if (JS2VAL_TO_STRING(objVal)->length() == 1) - return stringClass; // XXX characterClass; Need the connection from class Character to - // class String - i.e. access to all the functions in 'String.prototype' - - // but (some of) those routines depened on being called on a StringInstance... - else - return stringClass; - } - ASSERT(JS2VAL_IS_OBJECT(objVal)); - JS2Object *obj = JS2VAL_TO_OBJECT(objVal); switch (obj->kind) { case AttributeObjectKind: return attributeClass; @@ -3496,6 +3477,29 @@ XXX see EvalAttributeExpression, where identifiers are being handled for now... } } + // objectType(o) returns an OBJECT o's most specific type. + JS2Class *JS2Metadata::objectType(js2val objVal) + { + if (JS2VAL_IS_VOID(objVal)) + return undefinedClass; + if (JS2VAL_IS_NULL(objVal)) + return nullClass; + if (JS2VAL_IS_BOOLEAN(objVal)) + return booleanClass; + if (JS2VAL_IS_NUMBER(objVal)) + return numberClass; + if (JS2VAL_IS_STRING(objVal)) { + if (JS2VAL_TO_STRING(objVal)->length() == 1) + return stringClass; // XXX characterClass; Need the connection from class Character to + // class String - i.e. access to all the functions in 'String.prototype' - + // but (some of) those routines depened on being called on a StringInstance... + else + return stringClass; + } + ASSERT(JS2VAL_IS_OBJECT(objVal)); + return objectType(JS2VAL_TO_OBJECT(objVal)); + } + // hasType(o, c) returns true if o is an instance of class c (or one of c's subclasses). // It considers null to be an instance of the classes Null and Object only. @@ -3821,6 +3825,13 @@ XXX see EvalAttributeExpression, where identifiers are being handled for now... } } + bool defaultReadPublicProperty(JS2Metadata *meta, js2val base, JS2Class *limit, const String *name, LookupKind *lookupKind, Phase phase, js2val *rval) + { + // XXX could speed up by pushing knowledge of single namespace? + Multiname mn(name, meta->publicNamespace); + return defaultReadProperty(meta, base, limit, &mn, lookupKind, phase, rval); + } + bool defaultBracketRead(JS2Metadata *meta, js2val base, JS2Class *limit, Multiname *multiname, Phase phase, js2val *rval) { LookupKind lookup(false, JS2VAL_NULL); @@ -3878,6 +3889,13 @@ XXX see EvalAttributeExpression, where identifiers are being handled for now... } } + bool defaultWriteProperty(JS2Metadata *meta, js2val base, JS2Class *limit, const String *name, LookupKind *lookupKind, bool createIfMissing, js2val newValue) + { + // XXX could speed up by pushing knowledge of single namespace? + Multiname mn(name, meta->publicNamespace); + return defaultWriteProperty(meta, base, limit, &mn, lookupKind, createIfMissing, newValue); + } + bool defaultBracketWrite(JS2Metadata *meta, js2val base, JS2Class *limit, Multiname *multiname, js2val newValue) { LookupKind lookup(false, JS2VAL_NULL); @@ -4104,7 +4122,7 @@ XXX see EvalAttributeExpression, where identifiers are being handled for now... callInst->fWrap = new FunctionWrapper(true, new ParameterFrame(JS2VAL_INACCESSIBLE, true), pf->code, env); v = new Variable(functionClass, OBJECT_TO_JS2VAL(callInst), true); defineLocalMember(env, &world.identifiers[pf->name], &publicNamespaceList, Attribute::NoOverride, false, ReadWriteAccess, v, 0); - writeDynamicProperty(callInst, new Multiname(engine->length_StringAtom, publicNamespace), true, INT_TO_JS2VAL(pf->length), RunPhase); + createDynamicProperty(callInst, engine->length_StringAtom, INT_TO_JS2VAL(pf->length), ReadAccess, true, false); pf++; } } @@ -4113,31 +4131,22 @@ XXX see EvalAttributeExpression, where identifiers are being handled for now... // Add "constructor" as a dynamic property of the prototype FunctionInstance *fInst = new FunctionInstance(this, functionClass->prototype, functionClass); - writeDynamicProperty(fInst, new Multiname(engine->length_StringAtom, publicNamespace), true, INT_TO_JS2VAL(1), RunPhase); + createDynamicProperty(fInst, engine->length_StringAtom, INT_TO_JS2VAL(1), ReadAccess, true, false); fInst->fWrap = new FunctionWrapper(true, new ParameterFrame(JS2VAL_INACCESSIBLE, true), construct, env); - writeDynamicProperty(builtinClass->prototype, new Multiname(&world.identifiers["constructor"], publicNamespace), true, OBJECT_TO_JS2VAL(fInst), RunPhase); + createDynamicProperty(builtinClass->prototype, &world.identifiers["constructor"], OBJECT_TO_JS2VAL(fInst), ReadWriteAccess, false, true); pf = protoFunctions; if (pf) { while (pf->name) { SimpleInstance *callInst = new SimpleInstance(functionClass); callInst->fWrap = new FunctionWrapper(true, new ParameterFrame(JS2VAL_INACCESSIBLE, true), pf->code, env); - /* - XXX not prototype object function properties, like ECMA3 - writeDynamicProperty(dateClass->prototype, new Multiname(world.identifiers[pf->name], publicNamespace), true, OBJECT_TO_JS2VAL(fInst), RunPhase); - */ - /* - XXX not static members, since those can't be accessed from the instance - Variable *v = new Variable(functionClass, OBJECT_TO_JS2VAL(fInst), true); - defineLocalMember(&env, &world.identifiers[pf->name], &publicNamespaceList, Attribute::NoOverride, false, ReadWriteAccess, v, 0); - */ InstanceMember *m = new InstanceMethod(callInst); defineInstanceMember(builtinClass, &cxt, &world.identifiers[pf->name], &publicNamespaceList, Attribute::NoOverride, false, ReadWriteAccess, m, 0); FunctionInstance *fInst = new FunctionInstance(this, functionClass->prototype, functionClass); fInst->fWrap = callInst->fWrap; - writeDynamicProperty(builtinClass->prototype, new Multiname(&world.identifiers[pf->name], publicNamespace), true, OBJECT_TO_JS2VAL(fInst), RunPhase); - fInst->writeProperty(this, engine->length_StringAtom, INT_TO_JS2VAL(pf->length), DynamicPropertyValue::READONLY | DynamicPropertyValue::PERMANENT); + createDynamicProperty(builtinClass->prototype, &world.identifiers[pf->name], OBJECT_TO_JS2VAL(fInst), ReadWriteAccess, false, true); + createDynamicProperty(fInst, engine->length_StringAtom, INT_TO_JS2VAL(pf->length), ReadAccess, true, false); pf++; } } @@ -4167,6 +4176,7 @@ XXX see EvalAttributeExpression, where identifiers are being handled for now... call(NULL), construct(JS2Engine::defaultConstructor), read(defaultReadProperty), + readPublic(defaultReadPublicProperty), write(defaultWriteProperty), bracketRead(defaultBracketReadProperty), bracketWrite(defaultBracketReadProperty), diff --git a/mozilla/js2/src/js2metadata.h b/mozilla/js2/src/js2metadata.h index ca431c061c7..192f05d3d31 100644 --- a/mozilla/js2/src/js2metadata.h +++ b/mozilla/js2/src/js2metadata.h @@ -60,7 +60,9 @@ typedef js2val (Constructor)(JS2Metadata *meta, const js2val thisValue, js2val * typedef js2val (NativeCode)(JS2Metadata *meta, const js2val thisValue, js2val argv[], uint32 argc); typedef bool (Read)(JS2Metadata *meta, js2val base, JS2Class *limit, Multiname *multiname, LookupKind *lookupKind, Phase phase, js2val *rval); +typedef bool (ReadPublic)(JS2Metadata *meta, js2val base, JS2Class *limit, const String *name, LookupKind *lookupKind, Phase phase, js2val *rval); typedef bool (Write)(JS2Metadata *meta, js2val base, JS2Class *limit, Multiname *multiname, LookupKind *lookupKind, bool createIfMissing, js2val newValue); +typedef bool (WritePublic)(JS2Metadata *meta, js2val base, JS2Class *limit, const String *name, LookupKind *lookupKind, bool createIfMissing, js2val newValue); 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); @@ -631,8 +633,10 @@ public: void emitDefaultValue(BytecodeContainer *bCon, size_t pos); - Read *read; + Read *read; + ReadPublic *readPublic; Write *write; + WritePublic *readWrite; DeleteProperty *deleteProperty; BracketRead *bracketRead; BracketWrite *bracketWrite; @@ -1134,6 +1138,7 @@ public: JS2Class *objectType(js2val obj); + JS2Class *objectType(JS2Object *obj); bool hasType(js2val objVal, JS2Class *c); bool relaxedHasType(js2val objVal, JS2Class *c); @@ -1151,7 +1156,7 @@ public: 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 *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); @@ -1161,7 +1166,7 @@ public: 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); } + { QualifiedName qName(publicNamespace, name); createDynamicProperty(obj, &qName, initVal, access, sealed, enumerable); }