Bug 989528 - Introduce a mechanism to explicitly enter a null compartment. r=luke

This commit is contained in:
Bobby Holley 2014-04-14 20:26:59 -07:00
Родитель 265d0ea069
Коммит 1f55e4ee53
4 изменённых файлов: 32 добавлений и 1 удалений

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

@ -984,6 +984,19 @@ JSAutoCompartment::~JSAutoCompartment()
cx_->leaveCompartment(oldCompartment_);
}
JSAutoNullCompartment::JSAutoNullCompartment(JSContext *cx)
: cx_(cx),
oldCompartment_(cx->compartment())
{
AssertHeapIsIdleOrIterating(cx_);
cx_->enterNullCompartment();
}
JSAutoNullCompartment::~JSAutoNullCompartment()
{
cx_->leaveCompartment(oldCompartment_);
}
JS_PUBLIC_API(void)
JS_SetCompartmentPrivate(JSCompartment *compartment, void *data)
{

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

@ -1677,6 +1677,15 @@ class JS_PUBLIC_API(JSAutoCompartment)
~JSAutoCompartment();
};
class JS_PUBLIC_API(JSAutoNullCompartment)
{
JSContext *cx_;
JSCompartment *oldCompartment_;
public:
JSAutoNullCompartment(JSContext *cx);
~JSAutoNullCompartment();
};
/* NB: This API is infallible; a nullptr return value does not indicate error. */
extern JS_PUBLIC_API(JSCompartment *)
JS_EnterCompartment(JSContext *cx, JSObject *target);

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

@ -350,6 +350,7 @@ class ExclusiveContext : public ThreadSafeContext
#endif
inline void enterCompartment(JSCompartment *c);
inline void enterNullCompartment();
inline void leaveCompartment(JSCompartment *oldCompartment);
void setWorkerThread(WorkerThread *workerThread);

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

@ -407,6 +407,13 @@ js::ExclusiveContext::enterCompartment(JSCompartment *c)
setCompartment(c);
}
inline void
js::ExclusiveContext::enterNullCompartment()
{
enterCompartmentDepth_++;
setCompartment(nullptr);
}
inline void
js::ExclusiveContext::leaveCompartment(JSCompartment *oldCompartment)
{
@ -417,7 +424,8 @@ js::ExclusiveContext::leaveCompartment(JSCompartment *oldCompartment)
// compartment.
JSCompartment *startingCompartment = compartment_;
setCompartment(oldCompartment);
startingCompartment->leave();
if (startingCompartment)
startingCompartment->leave();
}
inline void