Bug 686582 - Begin to specialize ObjectOps::setElement to not just delegate to ObjectOps::setProperty. r=dvander
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user