Your Search Results


    Access a JSContext field for application-specific data.


    void *
    JS_GetContextPrivate(JSContext *cx);
    JS_SetContextPrivate(JSContext *cx, void *data);
    void *
    JS_GetSecondContextPrivate(JSContext *cx); // Added in SpiderMonkey 17
    JS_SetSecondContextPrivate(JSContext *cx, void *data); // Added in SpiderMonkey 17
    Name Type Description
    cx JSContext * Any context.
    data void * (in JS_SetContextPrivate or JS_SetSecondContextPrivate) Pointer to application-defined data to be associated with the context cx.


    Each JSContext has two fields of type void * which the application may use for any purpose. They are especially useful for storing data needed by callbacks. JS_GetContextPrivate and JS_GetSecondContextPrivate get this field and JS_SetContextPrivate and JS_SetSecondContextPrivate set it. The field is initially NULL.

    Memory management for this private data is the application's responsibility. The JavaScript engine itself never uses it.

    See Also

    Document Tags and Contributors

    Contributors to this page: fscholz, Cheatah, Nickolay, arai, Tservo, Dria, Jorend
    Last updated by: arai,
    Hide Sidebar