diff --git a/js/src/builtin/TypedObject.cpp b/js/src/builtin/TypedObject.cpp index 593f070874e3..35f72a089d0b 100644 --- a/js/src/builtin/TypedObject.cpp +++ b/js/src/builtin/TypedObject.cpp @@ -2084,7 +2084,7 @@ TypedObject::obj_deleteGeneric(JSContext *cx, HandleObject obj, HandleId id, boo return true; } - return JSObject::deleteGeneric(cx, proto, id, succeeded); + return DeleteProperty(cx, proto, id, succeeded); } bool diff --git a/js/src/jsapi.cpp b/js/src/jsapi.cpp index 95e74730665a..79253f800c20 100644 --- a/js/src/jsapi.cpp +++ b/js/src/jsapi.cpp @@ -3178,7 +3178,7 @@ JS_DeletePropertyById2(JSContext *cx, HandleObject obj, HandleId id, bool *resul CHECK_REQUEST(cx); assertSameCompartment(cx, obj, id); - return JSObject::deleteGeneric(cx, obj, id, result); + return DeleteProperty(cx, obj, id, result); } JS_PUBLIC_API(bool) @@ -3188,7 +3188,7 @@ JS_DeleteElement2(JSContext *cx, HandleObject obj, uint32_t index, bool *result) CHECK_REQUEST(cx); assertSameCompartment(cx, obj); - return JSObject::deleteElement(cx, obj, index, result); + return DeleteElement(cx, obj, index, result); } JS_PUBLIC_API(bool) @@ -3201,7 +3201,7 @@ JS_DeleteProperty2(JSContext *cx, HandleObject obj, const char *name, bool *resu if (!atom) return false; RootedId id(cx, AtomToId(atom)); - return JSObject::deleteGeneric(cx, obj, id, result); + return DeleteProperty(cx, obj, id, result); } JS_PUBLIC_API(bool) @@ -3215,7 +3215,7 @@ JS_DeleteUCProperty2(JSContext *cx, HandleObject obj, const char16_t *name, size if (!atom) return false; RootedId id(cx, AtomToId(atom)); - return JSObject::deleteGeneric(cx, obj, id, result); + return DeleteProperty(cx, obj, id, result); } JS_PUBLIC_API(bool) diff --git a/js/src/jsarray.cpp b/js/src/jsarray.cpp index 31ab869439c2..638ce5d26938 100644 --- a/js/src/jsarray.cpp +++ b/js/src/jsarray.cpp @@ -410,7 +410,7 @@ DeleteArrayElement(JSContext *cx, HandleObject obj, double index, bool *succeede RootedId id(cx); if (!ToId(cx, index, &id)) return false; - return JSObject::deleteGeneric(cx, obj, id, succeeded); + return DeleteProperty(cx, obj, id, succeeded); } /* ES6 20130308 draft 9.3.5 */ @@ -628,7 +628,7 @@ js::ArraySetLength(JSContext *cx, Handle arr, HandleId id, /* Steps 15b-d. */ bool deleteSucceeded; - if (!JSObject::deleteElement(cx, arr, oldLen, &deleteSucceeded)) + if (!DeleteElement(cx, arr, oldLen, &deleteSucceeded)) return false; if (!deleteSucceeded) { newLen = oldLen + 1; @@ -688,7 +688,7 @@ js::ArraySetLength(JSContext *cx, Handle arr, HandleId id, /* Steps 15b-d. */ bool deleteSucceeded; - if (!JSObject::deleteElement(cx, arr, index, &deleteSucceeded)) + if (!DeleteElement(cx, arr, index, &deleteSucceeded)) return false; if (!deleteSucceeded) { newLen = index + 1; diff --git a/js/src/jsobj.cpp b/js/src/jsobj.cpp index 10166ae512db..0bac50951d21 100644 --- a/js/src/jsobj.cpp +++ b/js/src/jsobj.cpp @@ -2498,7 +2498,7 @@ bad: if (named) { bool succeeded; RootedId id(cx, AtomToId(atom)); - JSObject::deleteGeneric(cx, obj, id, &succeeded); + DeleteProperty(cx, obj, id, &succeeded); } if (cached) ClearClassObject(obj, key); diff --git a/js/src/jsobj.h b/js/src/jsobj.h index 8c7b32b544e0..7ae524dacdc7 100644 --- a/js/src/jsobj.h +++ b/js/src/jsobj.h @@ -573,11 +573,6 @@ class JSObject : public js::gc::Cell static inline bool setGenericAttributes(JSContext *cx, js::HandleObject obj, js::HandleId id, unsigned *attrsp); - static inline bool deleteGeneric(JSContext *cx, js::HandleObject obj, js::HandleId id, - bool *succeeded); - static inline bool deleteElement(JSContext *cx, js::HandleObject obj, uint32_t index, - bool *succeeded); - static inline bool watch(JSContext *cx, JS::HandleObject obj, JS::HandleId id, JS::HandleObject callable); static inline bool unwatch(JSContext *cx, JS::HandleObject obj, JS::HandleId id); @@ -978,6 +973,15 @@ inline bool SetElement(JSContext *cx, HandleObject obj, HandleObject receiver, uint32_t index, MutableHandleValue vp, bool strict); +/* + * ES6 [[Delete]]. Equivalent to the JS code `delete obj[id]`. + */ +inline bool +DeleteProperty(JSContext *cx, js::HandleObject obj, js::HandleId id, bool *succeeded); + +inline bool +DeleteElement(JSContext *cx, js::HandleObject obj, uint32_t index, bool *succeeded); + /*** SpiderMonkey nonstandard internal methods ***************************************************/ diff --git a/js/src/jsobjinlines.h b/js/src/jsobjinlines.h index b889dd5f5ea7..3c4f1849fb56 100644 --- a/js/src/jsobjinlines.h +++ b/js/src/jsobjinlines.h @@ -35,26 +35,6 @@ JSObject::setGenericAttributes(JSContext *cx, js::HandleObject obj, return js::NativeSetPropertyAttributes(cx, obj.as(), id, attrsp); } -/* static */ inline bool -JSObject::deleteGeneric(JSContext *cx, js::HandleObject obj, js::HandleId id, - bool *succeeded) -{ - js::types::MarkTypePropertyNonData(cx, obj, id); - js::DeleteGenericOp op = obj->getOps()->deleteGeneric; - if (op) - return op(cx, obj, id, succeeded); - return js::NativeDeleteProperty(cx, obj.as(), id, succeeded); -} - -/* static */ inline bool -JSObject::deleteElement(JSContext *cx, js::HandleObject obj, uint32_t index, bool *succeeded) -{ - JS::RootedId id(cx); - if (!js::IndexToId(cx, index, &id)) - return false; - return deleteGeneric(cx, obj, id, succeeded); -} - /* static */ inline bool JSObject::watch(JSContext *cx, JS::HandleObject obj, JS::HandleId id, JS::HandleObject callable) @@ -236,6 +216,24 @@ js::GetElementNoGC(JSContext *cx, JSObject *obj, JSObject *receiver, uint32_t in return GetPropertyNoGC(cx, obj, receiver, INT_TO_JSID(index), vp); } +inline bool +js::DeleteProperty(JSContext *cx, HandleObject obj, HandleId id, bool *succeeded) +{ + types::MarkTypePropertyNonData(cx, obj, id); + if (DeleteGenericOp op = obj->getOps()->deleteGeneric) + return op(cx, obj, id, succeeded); + return NativeDeleteProperty(cx, obj.as(), id, succeeded); +} + +inline bool +js::DeleteElement(JSContext *cx, HandleObject obj, uint32_t index, bool *succeeded) +{ + RootedId id(cx); + if (!IndexToId(cx, index, &id)) + return false; + return DeleteProperty(cx, obj, id, succeeded); +} + /* * */ diff --git a/js/src/json.cpp b/js/src/json.cpp index 019e58bd1254..479bbd52741b 100644 --- a/js/src/json.cpp +++ b/js/src/json.cpp @@ -712,7 +712,7 @@ Walk(JSContext *cx, HandleObject holder, HandleId name, HandleValue reviver, Mut if (newElement.isUndefined()) { /* Step 2a(iii)(2). */ bool succeeded; - if (!JSObject::deleteGeneric(cx, obj, id, &succeeded)) + if (!DeleteProperty(cx, obj, id, &succeeded)) return false; } else { /* Step 2a(iii)(3). */ @@ -740,7 +740,7 @@ Walk(JSContext *cx, HandleObject holder, HandleId name, HandleValue reviver, Mut if (newElement.isUndefined()) { /* Step 2b(ii)(2). */ bool succeeded; - if (!JSObject::deleteGeneric(cx, obj, id, &succeeded)) + if (!DeleteProperty(cx, obj, id, &succeeded)) return false; } else { /* Step 2b(ii)(3). */ diff --git a/js/src/proxy/DirectProxyHandler.cpp b/js/src/proxy/DirectProxyHandler.cpp index 05d310cec7db..f48a66bdf22c 100644 --- a/js/src/proxy/DirectProxyHandler.cpp +++ b/js/src/proxy/DirectProxyHandler.cpp @@ -59,7 +59,7 @@ DirectProxyHandler::delete_(JSContext *cx, HandleObject proxy, HandleId id, bool { assertEnteredPolicy(cx, proxy, id, SET); RootedObject target(cx, proxy->as().target()); - return JSObject::deleteGeneric(cx, target, id, bp); + return DeleteProperty(cx, target, id, bp); } bool diff --git a/js/src/vm/Debugger.cpp b/js/src/vm/Debugger.cpp index 78449018f714..ac05a2216c43 100644 --- a/js/src/vm/Debugger.cpp +++ b/js/src/vm/Debugger.cpp @@ -6702,7 +6702,7 @@ DebuggerObject_deleteProperty(JSContext *cx, unsigned argc, Value *vp) ErrorCopier ec(ac); bool succeeded; - if (!JSObject::deleteGeneric(cx, obj, id, &succeeded)) + if (!DeleteProperty(cx, obj, id, &succeeded)) return false; args.rval().setBoolean(succeeded); return true; diff --git a/js/src/vm/Interpreter.cpp b/js/src/vm/Interpreter.cpp index b88a9db83075..d0d057d8f8c3 100644 --- a/js/src/vm/Interpreter.cpp +++ b/js/src/vm/Interpreter.cpp @@ -2287,7 +2287,7 @@ CASE(JSOP_STRICTDELPROP) FETCH_OBJECT(cx, -1, obj); bool succeeded; - if (!JSObject::deleteGeneric(cx, obj, id, &succeeded)) + if (!DeleteProperty(cx, obj, id, &succeeded)) goto error; if (!succeeded && JSOp(*REGS.pc) == JSOP_STRICTDELPROP) { obj->reportNotConfigurable(cx, id); @@ -2314,7 +2314,7 @@ CASE(JSOP_STRICTDELELEM) RootedId &id = rootId0; if (!ValueToId(cx, propval, &id)) goto error; - if (!JSObject::deleteGeneric(cx, obj, id, &succeeded)) + if (!DeleteProperty(cx, obj, id, &succeeded)) goto error; if (!succeeded && JSOp(*REGS.pc) == JSOP_STRICTDELELEM) { obj->reportNotConfigurable(cx, id); @@ -3786,7 +3786,7 @@ js::DeleteProperty(JSContext *cx, HandleValue v, HandlePropertyName name, bool * return false; RootedId id(cx, NameToId(name)); - if (!JSObject::deleteGeneric(cx, obj, id, bp)) + if (!DeleteProperty(cx, obj, id, bp)) return false; if (strict && !*bp) { @@ -3810,7 +3810,7 @@ js::DeleteElement(JSContext *cx, HandleValue val, HandleValue index, bool *bp) RootedId id(cx); if (!ValueToId(cx, index, &id)) return false; - if (!JSObject::deleteGeneric(cx, obj, id, bp)) + if (!DeleteProperty(cx, obj, id, bp)) return false; if (strict && !*bp) { @@ -3922,7 +3922,7 @@ js::DeleteNameOperation(JSContext *cx, HandlePropertyName name, HandleObject sco bool succeeded; RootedId id(cx, NameToId(name)); - if (!JSObject::deleteGeneric(cx, scope, id, &succeeded)) + if (!DeleteProperty(cx, scope, id, &succeeded)) return false; res.setBoolean(succeeded); return true; diff --git a/js/src/vm/ScopeObject.cpp b/js/src/vm/ScopeObject.cpp index b10c213e5612..37a746e57638 100644 --- a/js/src/vm/ScopeObject.cpp +++ b/js/src/vm/ScopeObject.cpp @@ -580,7 +580,7 @@ static bool with_DeleteGeneric(JSContext *cx, HandleObject obj, HandleId id, bool *succeeded) { RootedObject actual(cx, &obj->as().object()); - return JSObject::deleteGeneric(cx, actual, id, succeeded); + return DeleteProperty(cx, actual, id, succeeded); } static JSObject *