Visit Mozilla.org

JS SetContextCallback

From MDC

(Redirected from JSCONTEXT NEW)

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

[edit] Syntax

JSContextCallback JS_SetContextCallback(JSRuntime *rt, JSContextCallback cb)
Name Type Description
rt JSRuntime * Pointer to a JS runtime.
cb JSContextCallback Pointer to the callback function, described below.

[edit] Callback syntax

typedef JSBool (*JSContextCallback)(JSContext *cx, uintN contextOp);
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.
unitN contextOp The possible values for contextOp when the runtime calls the callback are:
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 JS_TRUE. In a DEBUG build, if the callback returns JS_FALSE, the JS engine will halt with an assertion.
Any other value
For future compatibility the callback must do nothing and return JS_TRUE.

[edit] 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.

LXR ID Search for JS_SetContextCallback