Please note, this is a STATIC archive of website from 03 Nov 2016, does not collect or store any user information, there is no "phishing" involved.


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: arai, fscholz, Jorend, Cheatah, Dria, Nickolay, Tservo
 Last updated by: arai,