This feature is obsolete. Although it is still supported by browsers, its usage is discouraged in new projects. Try to avoid using it.
||The context from which to retrieve the global object.|
This function is obsolete: use
JS_GetGlobalForScopeChain instead. The concept of a global object belonging to a context will likely be phased out in future versions of SpiderMonkey.
JS_GetGlobalObject retrieves the global object for a specified
cx. This returns
cx has no global object.
SpiderMonkey supports applications that have multiple global objects, such as the various window objects in a Web browser. The object returned by
cx! If a function is executing, the global object used by that function is determined when the function is created. Furthermore, some JSAPI functions, such as
JS_ExecuteScript, allow the caller to specify a global object in which the script executes. In either case, the global function used by the function or script may differ from the context's global object.
The context's global object field serves two purposes. First, it is a convenient place for the application to stash the global object, where it is automatically protected from garbage collection and the application can easily access it. Second, the context's global object is used as a default value of last resort by functions that need a default parent object (see
JS_SetParent for details) and by
JS_SetGlobalObject to replace the global object.
someone should document common use case "giving the global object a name", which can be done with JS_GetGlobalObject and JS_SetProperty