Bug 763856 - Introduce JSAutoEnterCompartment::leave(). r=luke

This commit is contained in:
Bobby Holley 2012-06-13 11:44:24 +02:00
Родитель bdb5696e93
Коммит ac0847a571
2 изменённых файлов: 17 добавлений и 1 удалений

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

@ -1444,13 +1444,22 @@ JSAutoEnterCompartment::enterAndIgnoreErrors(JSContext *cx, JSObject *target)
(void) enter(cx, target);
}
JSAutoEnterCompartment::~JSAutoEnterCompartment()
void
JSAutoEnterCompartment::leave()
{
JS_ASSERT(entered());
if (state == STATE_OTHER_COMPARTMENT) {
AutoCompartment* ac = getAutoCompartment();
CHECK_REQUEST(ac->context);
ac->~AutoCompartment();
}
state = STATE_UNENTERED;
}
JSAutoEnterCompartment::~JSAutoEnterCompartment()
{
if (entered())
leave();
}
namespace JS {

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

@ -2892,6 +2892,13 @@ class JS_PUBLIC_API(JSAutoEnterCompartment)
bool entered() const { return state != STATE_UNENTERED; }
/*
* In general, consumers should try to avoid calling leave() explicitly,
* and defer to the destructor by scoping the JSAutoEnterCompartment
* appropriately. Sometimes, though, it's unavoidable.
*/
void leave();
~JSAutoEnterCompartment();
};