JSDeletePropertyOp 编辑

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);
NameTypeDescription
cxJSContext *

The context in which the property access is taking place. Provides request. In JS_THREADSAFE builds, the JavaScript engine calls this callback only from within an active request on cx. The callback does not need to call JS_BeginRequest()).

objJS::HandleObjectThe object whose properties are being deleted.
idJS::HandleIdThe name or index of the property being deleted. This is either a string (Unicode property identifier) or an integer (element index).
succeededbool *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 when obj has no property named id.

    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 to false and return true. This will cause delete obj[id] to evaluate to false in non-strict mode code, and to throw a TypeError 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 to true and return true.

    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, returning false, before the delProperty hook is reached.

    JS_ClearScope does not call this hook either.

See Also

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据

词条统计

浏览:70 次

字数:5442

最后编辑:8年前

编辑次数:0 次

    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文