Bug 686582 - Begin to specialize ObjectOps::setElement to not just delegate to ObjectOps::setProperty. r=dvander

This commit is contained in:
Jeff Walden
2011-08-10 14:54:52 -07:00
parent 21b39d16b3
commit 10cdb9e766
5 changed files with 116 additions and 46 deletions

View File

@@ -917,7 +917,37 @@ array_setElement(JSContext *cx, JSObject *obj, uint32 index, Value *vp, JSBool s
jsid id;
if (!IndexToId(cx, index, &id))
return false;
return array_setProperty(cx, obj, id, vp, strict);
if (!obj->isDenseArray())
return js_SetPropertyHelper(cx, obj, id, 0, vp, strict);
do {
/*
* UINT32_MAX is not an array index and must not affect the length
* property, so specifically reject it.
*/
if (index == UINT32_MAX)
break;
if (js_PrototypeHasIndexedProperties(cx, obj))
break;
JSObject::EnsureDenseResult result = obj->ensureDenseArrayElements(cx, index, 1);
if (result != JSObject::ED_OK) {
if (result == JSObject::ED_FAILED)
return false;
JS_ASSERT(result == JSObject::ED_SPARSE);
break;
}
if (index >= obj->getArrayLength())
obj->setDenseArrayLength(index + 1);
obj->setDenseArrayElementWithType(cx, index, *vp);
return true;
} while (false);
if (!obj->makeDenseArraySlow(cx))
return false;
return js_SetPropertyHelper(cx, obj, id, 0, vp, strict);
}
JSBool