We're looking for a user researcher to understand the needs of developers and designers. Is this you or someone you know? Check out the post: https://mzl.la/2IGzdXS


This article covers features introduced in SpiderMonkey 31

Return the global object for the active function on the context.


JSObject *
JS::CurrentGlobalOrNull(JSContext *cx);
Name Type Description
cx JSContext * The context for which to return the global object. Requires request. In a JS_THREADSAFE build, the caller must be in a request on this JSContext.


JS::CurrentGlobalOrNull() returns the global object for whatever function is currently running on the context. In other words, it returns the global object on the current scope chain.

If there is no JavaScript running on the context, this returns the context's global, i.e., JS_GetGlobalObject(cx). Note that JS_GetGlobalObject() and context globals are becoming obsolete.

See also

Document Tags and Contributors

Contributors to this page: kscarfone, arai
Last updated by: kscarfone,