JS_SetContextCallback 编辑

Specifies a callback function that is automatically called whenever a JSContext is created or destroyed.

Syntax

void
JS_SetContextCallback(JSRuntime *rt, JSContextCallback cxCallback, void *data);
NameTypeDescription
rtJSRuntime *Pointer to a JS runtime.
cxCallbackJSContextCallbackPointer to the callback function, described below.
datavoid *Any data passed as 3rd argument to the callback function. Added in SpiderMonkey 31

Callback syntax

typedef bool
(* JSContextCallback)(JSContext *cx, unsigned contextOp, void *data);
NameTypeDescription
cxJSContext *Pointer to a JSContext which the callback may use to call into JSAPI functions. This is the context which was just created, or is about to be destroyed. For example, the callback my call JS_GetContextPrivate(cx) in order to free up resources previously allocated by JS_SetContextPrivate.
contextOpunsignedSee JSContextOp. For future compatibility the callback must do nothing and return true if any other value is passed.
datavoid *data specified in JS_SetContextCallback. Added in SpiderMonkey 31
typedef enum JSContextOp {
    JSCONTEXT_NEW,
    JSCONTEXT_DESTROY
} JSContextOp;
EnumerationMeaning
JSCONTEXT_NEWJS_NewContext successfully created a new JSContext instance. The callback can initialize the instance as required. If the callback returns JS_FALSE, the instance will be destroyed and JS_NewContext returns NULL. In this case the callback is not called again.
JSCONTEXT_DESTROYOne of JS_DestroyContext, JS_DestroyContextNoGC, or JS_DestroyContextMaybeGC was called. The callback may perform its own cleanup and must always return true. In a DEBUG build, if the callback returns false, the JS engine will halt with an assertion.

Description

JS_SetContextCallback specifies a callback function that is automatically called when JSContexts are created or destroyed. Only one callback function may be specified per JS runtime. This function returns the previous context callback, if any, else NULL.

See Also

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

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

发布评论

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

词条统计

浏览:55 次

字数:7259

最后编辑:8年前

编辑次数:0 次

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