Bug 686582 - Begin to specialize ObjectOps::deleteElement to not just delegate to ObjectOps::deleteProperty. r=dvander

--HG--
extra : rebase_source : ea2bd6c2511e5be83fcb826b7d4b81b6d38260ce
This commit is contained in:
Jeff Walden 2011-08-10 14:54:52 -07:00
parent 7c903ab2a6
commit 4507218e6f
7 changed files with 73 additions and 15 deletions

View File

@ -1035,7 +1035,7 @@ array_deleteProperty(JSContext *cx, JSObject *obj, jsid id, Value *rval, JSBool
if (JSID_IS_ATOM(id, cx->runtime->atomState.lengthAtom)) {
rval->setBoolean(false);
return JS_TRUE;
return true;
}
if (js_IdIsIndex(id, &i) && i < obj->getDenseArrayInitializedLength()) {
@ -1047,17 +1047,26 @@ array_deleteProperty(JSContext *cx, JSObject *obj, jsid id, Value *rval, JSBool
return false;
rval->setBoolean(true);
return JS_TRUE;
return true;
}
/* non-static for direct deletion of array elements within the engine */
JSBool
array_deleteElement(JSContext *cx, JSObject *obj, uint32 index, Value *rval, JSBool strict)
{
jsid id;
if (!IndexToId(cx, index, &id))
if (!obj->isDenseArray())
return js_DeleteElement(cx, obj, index, rval, strict);
if (index < obj->getDenseArrayInitializedLength()) {
obj->markDenseArrayNotPacked(cx);
obj->setDenseArrayElement(index, MagicValue(JS_ARRAY_HOLE));
}
if (!js_SuppressDeletedElement(cx, obj, index))
return false;
return array_deleteProperty(cx, obj, id, rval, strict);
rval->setBoolean(true);
return true;
}
} // namespace js

View File

@ -920,6 +920,16 @@ js_SuppressDeletedProperty(JSContext *cx, JSObject *obj, jsid id)
return SuppressDeletedPropertyHelper(cx, obj, SingleIdPredicate(id));
}
bool
js_SuppressDeletedElement(JSContext *cx, JSObject *obj, uint32 index)
{
jsid id;
if (!IndexToId(cx, index, &id))
return false;
JS_ASSERT(id == js_CheckForStringIndex(id));
return SuppressDeletedPropertyHelper(cx, obj, SingleIdPredicate(id));
}
class IndexRangePredicate {
jsint begin, end;
public:

View File

@ -148,6 +148,9 @@ js_CloseIterator(JSContext *cx, JSObject *iterObj);
bool
js_SuppressDeletedProperty(JSContext *cx, JSObject *obj, jsid id);
bool
js_SuppressDeletedElement(JSContext *cx, JSObject *obj, uint32 index);
bool
js_SuppressDeletedIndexProperties(JSContext *cx, JSObject *obj, jsint begin, jsint end);

View File

@ -6397,6 +6397,15 @@ js_DeleteProperty(JSContext *cx, JSObject *obj, jsid id, Value *rval, JSBool str
return obj->removeProperty(cx, id) && js_SuppressDeletedProperty(cx, obj, id);
}
JSBool
js_DeleteElement(JSContext *cx, JSObject *obj, uint32 index, Value *rval, JSBool strict)
{
jsid id;
if (!IndexToId(cx, index, &id))
return false;
return js_DeleteProperty(cx, obj, id, rval, strict);
}
namespace js {
bool

View File

@ -298,6 +298,9 @@ js_SetElementAttributes(JSContext *cx, JSObject *obj, uint32 index, uintN *attrs
extern JSBool
js_DeleteProperty(JSContext *cx, JSObject *obj, jsid id, js::Value *rval, JSBool strict);
extern JSBool
js_DeleteElement(JSContext *cx, JSObject *obj, uint32 index, js::Value *rval, JSBool strict);
extern JS_FRIEND_API(JSBool)
js_Enumerate(JSContext *cx, JSObject *obj, JSIterateOp enum_op,
js::Value *statep, jsid *idp);

View File

@ -484,10 +484,10 @@ ArrayBuffer::obj_deleteProperty(JSContext *cx, JSObject *obj, jsid id, Value *rv
JSBool
ArrayBuffer::obj_deleteElement(JSContext *cx, JSObject *obj, uint32 index, Value *rval, JSBool strict)
{
jsid id;
if (!IndexToId(cx, index, &id))
JSObject *delegate = DelegateObject(cx, obj);
if (!delegate)
return false;
return obj_deleteElement(cx, obj, index, rval, strict);
return js_DeleteElement(cx, delegate, index, rval, strict);
}
JSBool
@ -1065,10 +1065,16 @@ class TypedArrayTemplate
static JSBool
obj_deleteElement(JSContext *cx, JSObject *obj, uint32 index, Value *rval, JSBool strict)
{
jsid id;
if (!IndexToId(cx, index, &id))
return false;
return obj_deleteProperty(cx, obj, id, rval, strict);
JSObject *tarray = TypedArray::getTypedArray(obj);
JS_ASSERT(tarray);
if (index < getLength(tarray)) {
rval->setBoolean(false);
return true;
}
rval->setBoolean(true);
return true;
}
static JSBool

View File

@ -4912,10 +4912,28 @@ xml_deleteProperty(JSContext *cx, JSObject *obj, jsid id, Value *rval, JSBool st
static JSBool
xml_deleteElement(JSContext *cx, JSObject *obj, uint32 index, Value *rval, JSBool strict)
{
jsid id;
if (!IndexToId(cx, index, &id))
JSXML *xml = reinterpret_cast<JSXML *>(obj->getPrivate());
if (xml->xml_class != JSXML_CLASS_LIST) {
/* See NOTE in spec: this variation is reserved for future use. */
ReportBadXMLName(cx, DoubleValue(index));
return false;
return xml_deleteProperty(cx, obj, id, rval, strict);
}
/* ECMA-357 9.2.1.3. */
DeleteListElement(cx, xml, index);
/*
* If this object has its own (mutable) scope, then we may have added a
* property to the scope in xml_lookupProperty for it to return to mean
* "found" and to provide a handle for access operations to call the
* property's getter or setter. But now it's time to remove any such
* property, to purge the property cache and remove the scope entry.
*/
if (!obj->nativeEmpty() && !js_DeleteElement(cx, obj, index, rval, false))
return false;
rval->setBoolean(true);
return true;
}
static JSString *