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);
Name | Type | Description |
---|---|---|
rt | JSRuntime * | Pointer to a JS runtime. |
cxCallback | JSContextCallback | Pointer to the callback function, described below. |
data | void * | 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);
Name | Type | Description |
---|---|---|
cx | JSContext * | 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 . |
contextOp | unsigned | See JSContextOp . For future compatibility the callback must do nothing and return true if any other value is passed. |
data | void * | data specified in JS_SetContextCallback . Added in SpiderMonkey 31 |
typedef enum JSContextOp {
JSCONTEXT_NEW,
JSCONTEXT_DESTROY
} JSContextOp;
Enumeration | Meaning |
---|---|
JSCONTEXT_NEW | JS_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_DESTROY | One 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 JSContext
s 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论