This article needs a technical review. How you can help.
This article covers features introduced in SpiderMonkey 24
The type of the JSClass.delProperty
.
Syntax
typedef bool (* JSDeletePropertyOp)(JSContext *cx, JS::HandleObject obj, JS::HandleId id, bool *succeeded);
Name | Type | Description |
---|---|---|
cx |
JSContext * |
The context in which the property access is taking place. Provides request. In |
obj |
JS::HandleObject |
The object whose properties are being deleted. |
id |
JS::HandleId |
The name or index of the property being deleted. This is either a string (Unicode property identifier) or an integer (element index). |
succeeded |
bool * |
Out parameter. Receives the result of deletion. |
Description
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.
If a 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
hooks
JSClass offers the following hook:
-
JSClass.delProperty
is called during most property deletions, even whenobj
has no property namedid
.If an error occurred, return
false
as per normal JSAPI error practice.If no error occurred, but the deletion attempt wasn't allowed (perhaps because the property was non-configurable), set
*succeeded
tofalse
and returntrue
. This will causedelete obj[id]
to evaluate tofalse
in non-strict mode code, and to throw aTypeError
in 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
*succeeded
totrue
and returntrue
.This hook is not called when the target property is
JSPROP_PERMANENT
and is an own property of the target object. An attempt to delete such a property fails early, returningfalse
, before thedelProperty
hook is reached.JS_ClearScope
does not call this hook either.