Bug 1461605 part 2 - Rename JS_{Enter,Leave}Compartment -> JS::{Enter,Leave}Realm. r=luke

This commit is contained in:
Jan de Mooij 2018-05-17 11:00:21 +02:00
Родитель 17f3983d0f
Коммит c7a435f1ca
8 изменённых файлов: 29 добавлений и 25 удалений

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

@ -51,7 +51,7 @@ struct DevTools : public ::testing::Test {
global.init(cx, createGlobal());
if (!global)
return;
JS_EnterCompartment(cx, global);
JS::EnterRealm(cx, global);
compartment = js::GetContextCompartment(cx);
zone = js::GetContextZone(cx);
@ -108,7 +108,7 @@ struct DevTools : public ::testing::Test {
_initialized = false;
if (global) {
JS_LeaveCompartment(cx, nullptr);
JS::LeaveRealm(cx, nullptr);
global = nullptr;
}
if (cx)

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

@ -316,7 +316,7 @@ const WHITELIST_FUNCTIONS: &'static [&'static str] = &[
"js::Dump.*",
"JS_EncodeStringToUTF8",
"JS_EndRequest",
"JS_EnterCompartment",
"JS::EnterRealm",
"JS_EnumerateStandardClasses",
"JS_ErrorFromException",
"JS_FireOnNewGlobalObject",
@ -353,7 +353,7 @@ const WHITELIST_FUNCTIONS: &'static [&'static str] = &[
"JS_IsExceptionPending",
"JS_IsGlobalObject",
"JS::IsCallable",
"JS_LeaveCompartment",
"JS::LeaveRealm",
"JS_LinkConstructorAndPrototype",
"JS_MayResolveStandardClass",
"JS_NewArrayBuffer",

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

@ -611,7 +611,7 @@ impl GCMethods for JS::Value {
impl Drop for JSAutoRealm {
fn drop(&mut self) {
unsafe { JS_LeaveCompartment(self.cx_, self.oldCompartment_); }
unsafe { JS::LeaveRealm(self.cx_, self.oldCompartment_); }
}
}

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

@ -82,7 +82,7 @@ jsfuzz_init(JSContext** cx, JS::PersistentRootedObject* global)
*global = jsfuzz_createGlobal(*cx, nullptr);
if (!*global)
return false;
JS_EnterCompartment(*cx, *global);
JS::EnterRealm(*cx, *global);
return true;
}
@ -90,7 +90,7 @@ static void
jsfuzz_uninit(JSContext* cx, JSCompartment* oldCompartment)
{
if (oldCompartment) {
JS_LeaveCompartment(cx, oldCompartment);
JS::LeaveRealm(cx, oldCompartment);
oldCompartment = nullptr;
}
if (cx) {

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

@ -26,18 +26,18 @@ bool JSAPITest::init()
createGlobal();
if (!global)
return false;
JS_EnterCompartment(cx, global);
JS::EnterRealm(cx, global);
return true;
}
void JSAPITest::uninit()
{
if (oldCompartment) {
JS_LeaveCompartment(cx, oldCompartment);
JS::LeaveRealm(cx, oldCompartment);
oldCompartment = nullptr;
}
if (global) {
JS_LeaveCompartment(cx, nullptr);
JS::LeaveRealm(cx, nullptr);
global = nullptr;
}
if (cx) {

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

@ -675,7 +675,7 @@ JS_SetExternalStringSizeofCallback(JSContext* cx, JSExternalStringSizeofCallback
}
JS_PUBLIC_API(JSCompartment*)
JS_EnterCompartment(JSContext* cx, JSObject* target)
JS::EnterRealm(JSContext* cx, JSObject* target)
{
AssertHeapIsIdle();
CHECK_REQUEST(cx);
@ -686,11 +686,11 @@ JS_EnterCompartment(JSContext* cx, JSObject* target)
}
JS_PUBLIC_API(void)
JS_LeaveCompartment(JSContext* cx, JSCompartment* oldCompartment)
JS::LeaveRealm(JSContext* cx, JSCompartment* oldRealm)
{
AssertHeapIsIdle();
CHECK_REQUEST(cx);
cx->leaveCompartment(oldCompartment);
cx->leaveCompartment(oldRealm);
}
JSAutoRealm::JSAutoRealm(JSContext* cx, JSObject* target

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

@ -1045,17 +1045,17 @@ JS_RefreshCrossCompartmentWrappers(JSContext* cx, JS::Handle<JSObject*> obj);
* realm can be entered and left using separate function calls:
*
* void foo(JSContext* cx, JSObject* obj) {
* // in 'oldCompartment'
* JSCompartment* oldCompartment = JS_EnterCompartment(cx, obj);
* // in the compartment of 'obj'
* JS_LeaveCompartment(cx, oldCompartment);
* // back in 'oldCompartment'
* // in 'oldRealm'
* JSCompartment* oldRealm = JS::EnterRealm(cx, obj);
* // in the realm of 'obj'
* JS::LeaveRealm(cx, oldRealm);
* // back in 'oldRealm'
* }
*
* Note: these calls must still execute in a LIFO manner w.r.t all other
* enter/leave calls on the context. Furthermore, only the return value of a
* JS_EnterCompartment call may be passed as the 'oldCompartment' argument of
* the corresponding JS_LeaveCompartment call.
* JS::EnterRealm call may be passed as the 'oldRealm' argument of
* the corresponding JS::LeaveRealm call.
*
* Entering a realm roots the realm and its global object for the lifetime of
* the JSAutoRealm.
@ -1085,16 +1085,20 @@ class MOZ_RAII JS_PUBLIC_API(JSAutoNullableRealm)
MOZ_DECL_USE_GUARD_OBJECT_NOTIFIER
};
namespace JS {
/** NB: This API is infallible; a nullptr return value does not indicate error.
*
* Entering a compartment roots the compartment and its global object until the
* matching JS_LeaveCompartment() call.
* matching JS::LeaveRealm() call.
*/
extern JS_PUBLIC_API(JSCompartment*)
JS_EnterCompartment(JSContext* cx, JSObject* target);
EnterRealm(JSContext* cx, JSObject* target);
extern JS_PUBLIC_API(void)
JS_LeaveCompartment(JSContext* cx, JSCompartment* oldCompartment);
LeaveRealm(JSContext* cx, JSCompartment* oldRealm);
} // namespace JS
typedef void (*JSIterateCompartmentCallback)(JSContext* cx, void* data, JSCompartment* compartment);

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

@ -100,7 +100,7 @@ CreateGlobalAndRunTest(JSContext* cx)
global = JS_NewGlobalObject(cx, &GlobalClass, nullptr, JS::FireOnNewGlobalHook, options);
ASSERT_TRUE(global != nullptr);
JSCompartment *oldCompartment = JS_EnterCompartment(cx, global);
JSCompartment* oldRealm = JS::EnterRealm(cx, global);
typedef Heap<JSObject*> ElementT;
@ -121,7 +121,7 @@ CreateGlobalAndRunTest(JSContext* cx)
RunTest(cx, &array);
}
JS_LeaveCompartment(cx, oldCompartment);
JS::LeaveRealm(cx, oldRealm);
}
TEST(GCPostBarriers, nsTArray) {