зеркало из https://github.com/mozilla/gecko-dev.git
Bug 989528 - Introduce a mechanism to explicitly enter a null compartment. r=luke
This commit is contained in:
Родитель
265d0ea069
Коммит
1f55e4ee53
|
@ -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
|
||||
|
|
Загрузка…
Ссылка в новой задаче