From 6d5c46a3391c09c493caef4a7e045b6e1de2eaf9 Mon Sep 17 00:00:00 2001 From: "rogerl%netscape.com" Date: Mon, 6 Jan 2003 05:58:07 +0000 Subject: [PATCH] More boolean class fun. git-svn-id: svn://10.0.0.236/trunk@135871 18797224-902f-48f8-a5cc-f745e15eee43 --- mozilla/js2/src/js2boolean.cpp | 13 ++++++++++--- mozilla/js2/src/js2metadata.h | 6 +++--- 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/mozilla/js2/src/js2boolean.cpp b/mozilla/js2/src/js2boolean.cpp index e0c68e6f111..6f7f7487a2a 100644 --- a/mozilla/js2/src/js2boolean.cpp +++ b/mozilla/js2/src/js2boolean.cpp @@ -57,7 +57,7 @@ namespace MetaData { static js2val Boolean_Constructor(JS2Metadata *meta, const js2val thisValue, js2val argv[], uint32 argc) { - js2val thatValue = OBJECT_TO_JS2VAL(new BooleanInstance(meta->booleanClass)); + js2val thatValue = OBJECT_TO_JS2VAL(new BooleanInstance(meta->booleanClass->prototype, meta->booleanClass)); BooleanInstance *boolInst = checked_cast(JS2VAL_TO_OBJECT(thatValue)); if (argc > 0) @@ -113,16 +113,23 @@ namespace MetaData { NamespaceList publicNamespaceList; publicNamespaceList.push_back(meta->publicNamespace); - meta->booleanClass->prototype = new PrototypeInstance(meta->objectClass->prototype, meta->booleanClass); + meta->booleanClass->prototype = new BooleanInstance(meta->objectClass->prototype, meta->booleanClass); + // Adding "prototype" as a static member of the class - not a dynamic property meta->env->addFrame(meta->booleanClass); Variable *v = new Variable(meta->booleanClass, OBJECT_TO_JS2VAL(meta->booleanClass->prototype), true); meta->defineStaticMember(meta->env, meta->engine->prototype_StringAtom, &publicNamespaceList, Attribute::NoOverride, false, ReadWriteAccess, v, 0); meta->env->removeTopFrame(); + // Add "constructor" as a dynamic property of the prototype + CallableInstance *fInst = new CallableInstance(meta->functionClass); + fInst->fWrap = new FunctionWrapper(true, new ParameterFrame(JS2VAL_INACCESSIBLE, true), Boolean_Constructor); + meta->writeDynamicProperty(meta->booleanClass->prototype, new Multiname(&meta->world.identifiers["constructor"], meta->publicNamespace), true, OBJECT_TO_JS2VAL(fInst), RunPhase); + + PrototypeFunction *pf = &prototypeFunctions[0]; while (pf->name) { - CallableInstance *fInst = new CallableInstance(meta->functionClass); + fInst = new CallableInstance(meta->functionClass); fInst->fWrap = new FunctionWrapper(true, new ParameterFrame(JS2VAL_INACCESSIBLE, true), pf->code); /* XXX not prototype object function properties, like ECMA3 diff --git a/mozilla/js2/src/js2metadata.h b/mozilla/js2/src/js2metadata.h index ed8ed5ed903..d3feb1972a0 100644 --- a/mozilla/js2/src/js2metadata.h +++ b/mozilla/js2/src/js2metadata.h @@ -613,11 +613,11 @@ public: float64 mValue; }; -// Boolean instances are Callable instances created by the Boolean class, they have an extra field +// Boolean instances are PrototypeInstance created by the Boolean class, they have an extra field // that contains the bool data -class BooleanInstance : public CallableInstance { +class BooleanInstance : public PrototypeInstance { public: - BooleanInstance(JS2Class *type) : CallableInstance(type), mValue(false) { } + BooleanInstance(JS2Object *parent, JS2Class *type) : PrototypeInstance(parent, type), mValue(false) { } bool mValue; };