From d9bf6404776cf687dba6d9f4b454b74c60c8fe41 Mon Sep 17 00:00:00 2001 From: "beard%netscape.com" Date: Wed, 28 Jun 2000 16:32:52 +0000 Subject: [PATCH] Fixed dynamic lookup of static slots. Added code to compare strings. --- js/js2/interpreter.cpp | 6 +++--- js/js2/jsclasses.h | 12 +++++++++--- js2/src/interpreter.cpp | 6 +++--- js2/src/jsclasses.h | 12 +++++++++--- 4 files changed, 24 insertions(+), 12 deletions(-) diff --git a/js/js2/interpreter.cpp b/js/js2/interpreter.cpp index df3475539c14..a226554f1d59 100644 --- a/js/js2/interpreter.cpp +++ b/js/js2/interpreter.cpp @@ -234,7 +234,7 @@ static JSValue less_Default(const JSValue& r1, const JSValue& r2) JSValue rv = r2.toPrimitive(JSValue::Number); if (lv.isString() && rv.isString()) { // XXX FIXME urgh, call w_strcmp ??? on a JSString ??? - return JSValue(); + return JSValue(rv.string->compare(*lv.string)); } else { lv = lv.toNumber(); @@ -690,7 +690,7 @@ JSValue Context::interpret(ICodeModule* iCode, const JSValues& args) // REVISIT: should signal error if slot doesn't exist. JSClass* thisClass = dynamic_cast(value.type); if (thisClass && thisClass->hasStatic(*src2(gp))) { - const JSSlot& slot = thisClass->getSlot(*src2(gp)); + const JSSlot& slot = thisClass->getStatic(*src2(gp)); (*registers)[dst(gp).first] = (*thisClass)[slot.mIndex]; } } else { @@ -709,7 +709,7 @@ JSValue Context::interpret(ICodeModule* iCode, const JSValues& args) // REVISIT: should signal error if slot doesn't exist. JSClass* thisClass = dynamic_cast(value.object); if (thisClass && thisClass->hasStatic(*src1(sp))) { - const JSSlot& slot = thisClass->getSlot(*src1(sp)); + const JSSlot& slot = thisClass->getStatic(*src1(sp)); (*thisClass)[slot.mIndex] = (*registers)[src2(sp).first]; } } else { diff --git a/js/js2/jsclasses.h b/js/js2/jsclasses.h index c591bd2e802c..e7ea1128ce3f 100644 --- a/js/js2/jsclasses.h +++ b/js/js2/jsclasses.h @@ -195,14 +195,20 @@ namespace JSClasses { public: void* operator new(size_t n, JSClass* thisClass) { - return gc_base::operator new((n - sizeof(JSValue)) + thisClass->getSlotCount() * sizeof(JSValue)); + uint32 slotCount = thisClass->getSlotCount(); + if (slotCount > 0) n += sizeof(JSValue) * (slotCount - 1); + return gc_base::operator new(n); } JSInstance(JSClass* thisClass) { mType = thisClass; - // initialize all slots with undefined. - std::uninitialized_fill(&mSlots[1], &mSlots[0] + thisClass->getSlotCount(), JSTypes::kUndefinedValue); + // initialize extra slots with undefined. + uint32 slotCount = thisClass->getSlotCount(); + if (slotCount > 0) { + std::uninitialized_fill(&mSlots[1], &mSlots[1] + (slotCount - 1), + JSTypes::kUndefinedValue); + } // for grins, use the prototype link to access methods. setPrototype(thisClass->getScope()); } diff --git a/js2/src/interpreter.cpp b/js2/src/interpreter.cpp index df3475539c14..a226554f1d59 100644 --- a/js2/src/interpreter.cpp +++ b/js2/src/interpreter.cpp @@ -234,7 +234,7 @@ static JSValue less_Default(const JSValue& r1, const JSValue& r2) JSValue rv = r2.toPrimitive(JSValue::Number); if (lv.isString() && rv.isString()) { // XXX FIXME urgh, call w_strcmp ??? on a JSString ??? - return JSValue(); + return JSValue(rv.string->compare(*lv.string)); } else { lv = lv.toNumber(); @@ -690,7 +690,7 @@ JSValue Context::interpret(ICodeModule* iCode, const JSValues& args) // REVISIT: should signal error if slot doesn't exist. JSClass* thisClass = dynamic_cast(value.type); if (thisClass && thisClass->hasStatic(*src2(gp))) { - const JSSlot& slot = thisClass->getSlot(*src2(gp)); + const JSSlot& slot = thisClass->getStatic(*src2(gp)); (*registers)[dst(gp).first] = (*thisClass)[slot.mIndex]; } } else { @@ -709,7 +709,7 @@ JSValue Context::interpret(ICodeModule* iCode, const JSValues& args) // REVISIT: should signal error if slot doesn't exist. JSClass* thisClass = dynamic_cast(value.object); if (thisClass && thisClass->hasStatic(*src1(sp))) { - const JSSlot& slot = thisClass->getSlot(*src1(sp)); + const JSSlot& slot = thisClass->getStatic(*src1(sp)); (*thisClass)[slot.mIndex] = (*registers)[src2(sp).first]; } } else { diff --git a/js2/src/jsclasses.h b/js2/src/jsclasses.h index c591bd2e802c..e7ea1128ce3f 100644 --- a/js2/src/jsclasses.h +++ b/js2/src/jsclasses.h @@ -195,14 +195,20 @@ namespace JSClasses { public: void* operator new(size_t n, JSClass* thisClass) { - return gc_base::operator new((n - sizeof(JSValue)) + thisClass->getSlotCount() * sizeof(JSValue)); + uint32 slotCount = thisClass->getSlotCount(); + if (slotCount > 0) n += sizeof(JSValue) * (slotCount - 1); + return gc_base::operator new(n); } JSInstance(JSClass* thisClass) { mType = thisClass; - // initialize all slots with undefined. - std::uninitialized_fill(&mSlots[1], &mSlots[0] + thisClass->getSlotCount(), JSTypes::kUndefinedValue); + // initialize extra slots with undefined. + uint32 slotCount = thisClass->getSlotCount(); + if (slotCount > 0) { + std::uninitialized_fill(&mSlots[1], &mSlots[1] + (slotCount - 1), + JSTypes::kUndefinedValue); + } // for grins, use the prototype link to access methods. setPrototype(thisClass->getScope()); }