This article covers features introduced in SpiderMonkey 24
The type of the
typedef bool (* JSDeletePropertyOp)(JSContext *cx, JS::HandleObject obj, JS::HandleId id, bool *succeeded);
The context in which the property access is taking place. Provides request. In
||The object whose properties are being deleted.|
||The name or index of the property being deleted. This is either a string (Unicode property identifier) or an integer (element index).|
||Out parameter. Receives the result of deletion.|
JSDeletePropertyOp callback is a hook that applications may install to be called at some point during property access. A
JSDeletePropertyOp may be installed on a
JSClass to hook property deletes.
JSDeletePropertyOp does nothing and returns
true, then property delete is unaffected. It proceeds as normal.
This callback may veto the ongoing property operation by optionally reporting an error or raising an exception and then returning
false. The operation then fails, and the error is propagated to the caller. Otherwise the callback must return
true, and the property operation proceeds.
JSClass offers the following hook:
JSClass.delPropertyis called during most property deletions, even when
objhas no property named
If an error occurred, return
falseas per normal JSAPI error practice.
If no error occurred, but the deletion attempt wasn't allowed (perhaps because the property was non-configurable), set
true. This will cause
delete obj[id]to evaluate to
falsein non-strict mode code, and to throw a
TypeErrorin strict mode code.
If no error occurred and the deletion wasn't disallowed (this is *not* the same as saying that a deletion actually occurred -- deleting a non-existent property, or an inherited property, is allowed -- it's just pointless), set
This hook is not called when the target property is
JSPROP_PERMANENTand is an own property of the target object. An attempt to delete such a property fails early, returning
false, before the
delPropertyhook is reached.
JS_ClearScopedoes not call this hook either.