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:
Bobby Holley 2013-07-17 11:53:52 -07:00
Родитель 42413d79c9
Коммит 91ae5cf5ba
3 изменённых файлов: 14 добавлений и 4 удалений

Просмотреть файл

@ -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_);