зеркало из https://github.com/mozilla/gecko-dev.git
Bug 887334 - Add a JSCompartment* to AutoCompartment and use it in JS_NewGlobalObject. r=luke
This gets rid of the wonky setCompartment usage in that function.
This commit is contained in:
Родитель
42413d79c9
Коммит
91ae5cf5ba
|
@ -3318,10 +3318,12 @@ JS_NewGlobalObject(JSContext *cx, JSClass *clasp, JSPrincipals *principals,
|
|||
|
||||
AutoHoldZone hold(compartment->zone());
|
||||
|
||||
JSCompartment *saved = cx->compartment();
|
||||
cx->setCompartment(compartment);
|
||||
Rooted<GlobalObject *> global(cx, GlobalObject::create(cx, Valueify(clasp)));
|
||||
cx->setCompartment(saved);
|
||||
Rooted<GlobalObject *> global(cx);
|
||||
{
|
||||
AutoCompartment ac(cx, compartment);
|
||||
global = GlobalObject::create(cx, Valueify(clasp));
|
||||
}
|
||||
|
||||
if (!global)
|
||||
return NULL;
|
||||
|
||||
|
|
|
@ -460,6 +460,7 @@ class AutoCompartment
|
|||
|
||||
public:
|
||||
inline AutoCompartment(JSContext *cx, JSObject *target);
|
||||
inline AutoCompartment(JSContext *cx, JSCompartment *target);
|
||||
inline ~AutoCompartment();
|
||||
|
||||
JSContext *context() const { return cx_; }
|
||||
|
|
|
@ -33,6 +33,13 @@ js::AutoCompartment::AutoCompartment(JSContext *cx, JSObject *target)
|
|||
cx_->enterCompartment(target->compartment());
|
||||
}
|
||||
|
||||
js::AutoCompartment::AutoCompartment(JSContext *cx, JSCompartment *target)
|
||||
: cx_(cx),
|
||||
origin_(cx->compartment())
|
||||
{
|
||||
cx_->enterCompartment(target);
|
||||
}
|
||||
|
||||
js::AutoCompartment::~AutoCompartment()
|
||||
{
|
||||
cx_->leaveCompartment(origin_);
|
||||
|
|
Загрузка…
Ссылка в новой задаче