This article covers features introduced in SpiderMonkey 24
Note: the preferred way of changing a context's current compartment is using
Enter a different compartment on the given context, so that objects in that compartment can be accessed.
JSCompartment * JS_EnterCompartment(JSContext *cx, JSObject *target);
||The context on which a cross-compartment call is needed.|
The object in a different compartment to be accessed. This implicitly identifies the compartment to be entered.
JSContexthas a current compartment. Any access to an object in a different compartment must be bracketed by calling
JS_EnterCompartmentreturns a pointer to the previously entered compartment. To return to that compartment, pass it to
JS_EnterCompartmentis infallible, so a
NULLreturn value doesn't indicate failure.