Fixed Array.length & proto functions.

git-svn-id: svn://10.0.0.236/trunk@138036 18797224-902f-48f8-a5cc-f745e15eee43
This commit is contained in:
rogerl%netscape.com
2003-02-20 16:17:49 +00:00
parent 3f01246d39
commit 63ae1fcbf1
10 changed files with 77 additions and 38 deletions

View File

@@ -68,15 +68,31 @@ uint32 getLength(JS2Metadata *meta, JS2Object *obj)
js2val setLength(JS2Metadata *meta, JS2Object *obj, uint32 length)
{
Multiname mn(meta->engine->length_StringAtom, meta->publicNamespace);
js2val result = meta->engine->allocNumber(length);
meta->writeDynamicProperty(obj, &mn, true, result, RunPhase);
if (obj->kind == PrototypeInstanceKind) {
// Can't call 'writeDynamicProperty' as that'll just cycle back here for
// ArrayInstances.
DynamicPropertyMap *dMap = &checked_cast<PrototypeInstance *>(obj)->dynamicProperties;
for (DynamicPropertyIterator i = dMap->begin(), end = dMap->end(); (i != end); i++) {
if (i->first == *meta->engine->length_StringAtom) {
i->second = result;
return result;
}
}
const DynamicPropertyMap::value_type e(*meta->engine->length_StringAtom, result);
checked_cast<PrototypeInstance *>(obj)->dynamicProperties.insert(e);
}
else {
Multiname mn(meta->engine->length_StringAtom, meta->publicNamespace);
meta->writeDynamicProperty(obj, &mn, true, result, RunPhase);
}
return result;
}
js2val Array_Constructor(JS2Metadata *meta, const js2val /*thisValue*/, js2val *argv, uint32 argc)
{
js2val thatValue = OBJECT_TO_JS2VAL(new ArrayInstance(meta->arrayClass->prototype, meta->arrayClass));
js2val thatValue = OBJECT_TO_JS2VAL(new ArrayInstance(meta, meta->arrayClass->prototype, meta->arrayClass));
ArrayInstance *arrInst = checked_cast<ArrayInstance *>(JS2VAL_TO_OBJECT(thatValue));
if (argc > 0) {
if (argc == 1) {
@@ -208,7 +224,7 @@ js2val Array_concat(JS2Metadata *meta, const js2val thisValue, js2val *argv, uin
{
js2val E = thisValue;
js2val result = OBJECT_TO_JS2VAL(new ArrayInstance(meta->arrayClass->prototype, meta->arrayClass));
js2val result = OBJECT_TO_JS2VAL(new ArrayInstance(meta, meta->arrayClass->prototype, meta->arrayClass));
ArrayInstance *A = checked_cast<ArrayInstance *>(JS2VAL_TO_OBJECT(result));
uint32 n = 0;
uint32 i = 0;
@@ -358,7 +374,7 @@ static js2val Array_slice(JS2Metadata *meta, const js2val thisValue, js2val *arg
ASSERT(JS2VAL_IS_OBJECT(thisValue));
JS2Object *thisObj = JS2VAL_TO_OBJECT(thisValue);
js2val result = OBJECT_TO_JS2VAL(new ArrayInstance(meta->arrayClass->prototype, meta->arrayClass));
js2val result = OBJECT_TO_JS2VAL(new ArrayInstance(meta, meta->arrayClass->prototype, meta->arrayClass));
ArrayInstance *A = checked_cast<ArrayInstance *>(JS2VAL_TO_OBJECT(result));
uint32 length = getLength(meta, thisObj);
@@ -584,7 +600,7 @@ static js2val Array_splice(JS2Metadata *meta, const js2val thisValue, js2val *ar
JS2Object *thisObj = JS2VAL_TO_OBJECT(thisValue);
uint32 length = getLength(meta, thisObj);
js2val result = OBJECT_TO_JS2VAL(new ArrayInstance(meta->arrayClass->prototype, meta->arrayClass));
js2val result = OBJECT_TO_JS2VAL(new ArrayInstance(meta, meta->arrayClass->prototype, meta->arrayClass));
ArrayInstance *A = checked_cast<ArrayInstance *>(JS2VAL_TO_OBJECT(result));
int32 arg0 = meta->toInteger(argv[0]);
@@ -807,7 +823,8 @@ void initArrayObject(JS2Metadata *meta)
publicNamespaceList.push_back(meta->publicNamespace);
meta->arrayClass->construct = Array_Constructor;
meta->arrayClass->prototype = new ArrayInstance(meta->objectClass->prototype, meta->arrayClass);
meta->arrayClass->call = Array_Constructor;
meta->arrayClass->prototype = new ArrayInstance(meta, meta->objectClass->prototype, meta->arrayClass);
// Adding "prototype" & "length" as static members of the class - not dynamic properties; XXX
meta->env->addFrame(meta->arrayClass);
@@ -819,11 +836,19 @@ void initArrayObject(JS2Metadata *meta)
PrototypeFunction *pf = &arrayProtos[0];
while (pf->name) {
SimpleInstance *fInst = new SimpleInstance(meta->functionClass);
fInst->fWrap = new FunctionWrapper(true, new ParameterFrame(JS2VAL_INACCESSIBLE, true), pf->code);
InstanceMember *m = new InstanceMethod(fInst);
SimpleInstance *callInst = new SimpleInstance(meta->functionClass);
callInst->fWrap = new FunctionWrapper(true, new ParameterFrame(JS2VAL_INACCESSIBLE, true), pf->code);
InstanceMember *m = new InstanceMethod(callInst);
meta->defineInstanceMember(meta->arrayClass, &meta->cxt, &meta->world.identifiers[pf->name], &publicNamespaceList, Attribute::NoOverride, false, ReadWriteAccess, m, 0);
/*
Dynamic property of the prototype:
*/
FunctionInstance *fInst = new FunctionInstance(meta->functionClass->prototype, meta->functionClass);
fInst->fWrap = callInst->fWrap;
meta->writeDynamicProperty(meta->arrayClass->prototype, new Multiname(&meta->world.identifiers[pf->name], meta->publicNamespace), true, OBJECT_TO_JS2VAL(fInst), RunPhase);
meta->writeDynamicProperty(fInst, new Multiname(meta->engine->length_StringAtom, meta->publicNamespace), true, INT_TO_JS2VAL(pf->length), RunPhase);
pf++;
}
}