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

JS_NewCompartmentAndGlobalObject

Obsolete since JSAPI 16
This feature is obsolete. Although it may still work in some browsers, its use is discouraged since it could be removed at any time. Try to avoid using it.

This article covers features introduced in SpiderMonkey 1.8.1

JS_NewCompartmentAndGlobalObject has been removed in bug 755186. Use JS_NewGlobalObject instead.

Create a new global object in a new compartment.

Syntax

JSObject *
JS_NewCompartmentAndGlobalObject(JSContext *cx, JSClass *clasp,
                                 JSPrincipals *principals);
Name Type Description
cx JSContext * The context in which to create the new global object. Requires request. In a JS_THREADSAFE build, the caller must be in a request on this JSContext.
clasp JSClass *

The class to use for the new global object.

clasp->flags must have the JSCLASS_GLOBAL_FLAGS bits set.

The caller must ensure that the JSClass remains alive throughout the lifetime of the new object, including the garbage collection cycle that finally frees it. The usual way to do this is to make JSClasses global or static.

principals JSPrincipals * The security information to associate with this compartment.

Description

JS_NewCompartmentAndGlobalObject creates a new compartment, and then creates a new global object as the first object in that compartment.

On success, JS_NewCompartmentAndGlobalObject returns a pointer to the new global object. Otherwise it returns NULL.

See Also

Document Tags and Contributors

 Contributors to this page: arai, fscholz, sfink, tschneidereit, markg, Dmandelin
 Last updated by: arai,