Bug 1466121 part 3 - Merge Realm.cpp into JSCompartment.cpp to simplify later patches. r=luke
authorJan de Mooij <jdemooij@mozilla.com>
Fri, 08 Jun 2018 16:16:18 +0200
changeset 422011 4db98fad2f4e690d141c96f86fa38d6ba7cc7c0d
parent 422010 d2da1fe0c939cb2f381fabe1198a7b3ebb2d7016
child 422012 ac87103cdf38dd631b41dc6d16e646239b2f93da
push id34114
push userbtara@mozilla.com
push dateSat, 09 Jun 2018 15:31:58 +0000
treeherdermozilla-central@e02a5155d815 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersluke
bugs1466121
milestone62.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1466121 part 3 - Merge Realm.cpp into JSCompartment.cpp to simplify later patches. r=luke
js/src/moz.build
js/src/vm/JSCompartment.cpp
js/src/vm/Realm.cpp
--- a/js/src/moz.build
+++ b/js/src/moz.build
@@ -368,17 +368,16 @@ UNIFIED_SOURCES += [
     'vm/JSScript.cpp',
     'vm/MemoryMetrics.cpp',
     'vm/NativeObject.cpp',
     'vm/ObjectGroup.cpp',
     'vm/PIC.cpp',
     'vm/Printer.cpp',
     'vm/Probes.cpp',
     'vm/ProxyObject.cpp',
-    'vm/Realm.cpp',
     'vm/ReceiverGuard.cpp',
     'vm/RegExpObject.cpp',
     'vm/RegExpStatics.cpp',
     'vm/Runtime.cpp',
     'vm/SavedStacks.cpp',
     'vm/Scope.cpp',
     'vm/SelfHosting.cpp',
     'vm/Shape.cpp',
--- a/js/src/vm/JSCompartment.cpp
+++ b/js/src/vm/JSCompartment.cpp
@@ -1427,8 +1427,104 @@ AutoSetNewObjectMetadata::~AutoSetNewObj
         // in order.
         cx_->realm()->objectMetadataState_ = prevState_;
 
         obj = SetNewObjectMetadata(cx_, obj);
     } else {
         cx_->realm()->objectMetadataState_ = prevState_;
     }
 }
+
+JS_PUBLIC_API(void)
+gc::TraceRealm(JSTracer* trc, JS::Realm* realm, const char* name)
+{
+    // The way GC works with compartments is basically incomprehensible.
+    // For Realms, what we want is very simple: each Realm has a strong
+    // reference to its GlobalObject, and vice versa.
+    //
+    // Here we simply trace our side of that edge. During GC,
+    // GCRuntime::traceRuntimeCommon() marks all other realm roots, for
+    // all realms.
+    realm->traceGlobal(trc);
+}
+
+JS_PUBLIC_API(bool)
+gc::RealmNeedsSweep(JS::Realm* realm)
+{
+    return realm->globalIsAboutToBeFinalized();
+}
+
+JS_PUBLIC_API(JS::Realm*)
+JS::GetCurrentRealmOrNull(JSContext* cx)
+{
+    return cx->realm();
+}
+
+JS_PUBLIC_API(JS::Realm*)
+JS::GetObjectRealmOrNull(JSObject* obj)
+{
+    return IsCrossCompartmentWrapper(obj) ? nullptr : obj->realm();
+}
+
+JS_PUBLIC_API(void*)
+JS::GetRealmPrivate(JS::Realm* realm)
+{
+    return realm->realmPrivate();
+}
+
+JS_PUBLIC_API(void)
+JS::SetRealmPrivate(JS::Realm* realm, void* data)
+{
+    realm->setRealmPrivate(data);
+}
+
+JS_PUBLIC_API(void)
+JS::SetDestroyRealmCallback(JSContext* cx, JS::DestroyRealmCallback callback)
+{
+    cx->runtime()->destroyRealmCallback = callback;
+}
+
+JS_PUBLIC_API(void)
+JS::SetRealmNameCallback(JSContext* cx, JS::RealmNameCallback callback)
+{
+    cx->runtime()->realmNameCallback = callback;
+}
+
+JS_PUBLIC_API(JSObject*)
+JS::GetRealmGlobalOrNull(Handle<JS::Realm*> realm)
+{
+    return realm->maybeGlobal();
+}
+
+JS_PUBLIC_API(JSObject*)
+JS::GetRealmObjectPrototype(JSContext* cx)
+{
+    CHECK_REQUEST(cx);
+    return GlobalObject::getOrCreateObjectPrototype(cx, cx->global());
+}
+
+JS_PUBLIC_API(JSObject*)
+JS::GetRealmFunctionPrototype(JSContext* cx)
+{
+    CHECK_REQUEST(cx);
+    return GlobalObject::getOrCreateFunctionPrototype(cx, cx->global());
+}
+
+JS_PUBLIC_API(JSObject*)
+JS::GetRealmArrayPrototype(JSContext* cx)
+{
+    CHECK_REQUEST(cx);
+    return GlobalObject::getOrCreateArrayPrototype(cx, cx->global());
+}
+
+JS_PUBLIC_API(JSObject*)
+JS::GetRealmErrorPrototype(JSContext* cx)
+{
+    CHECK_REQUEST(cx);
+    return GlobalObject::getOrCreateCustomErrorPrototype(cx, cx->global(), JSEXN_ERR);
+}
+
+JS_PUBLIC_API(JSObject*)
+JS::GetRealmIteratorPrototype(JSContext* cx)
+{
+    CHECK_REQUEST(cx);
+    return GlobalObject::getOrCreateIteratorPrototype(cx, cx->global());
+}
deleted file mode 100644
--- a/js/src/vm/Realm.cpp
+++ /dev/null
@@ -1,111 +0,0 @@
-/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
- * vim: set ts=8 sts=4 et sw=4 tw=99:
- * This Source Code Form is subject to the terms of the Mozilla Public
- * License, v. 2.0. If a copy of the MPL was not distributed with this
- * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
-
-#include "js/Realm.h"
-
-#include "vm/GlobalObject.h"
-#include "vm/JSCompartment.h"
-#include "vm/JSContext.h"
-
-#include "vm/JSCompartment-inl.h"
-
-using namespace js;
-
-JS_PUBLIC_API(void)
-gc::TraceRealm(JSTracer* trc, JS::Realm* realm, const char* name)
-{
-    // The way GC works with compartments is basically incomprehensible.
-    // For Realms, what we want is very simple: each Realm has a strong
-    // reference to its GlobalObject, and vice versa.
-    //
-    // Here we simply trace our side of that edge. During GC,
-    // GCRuntime::traceRuntimeCommon() marks all other realm roots, for
-    // all realms.
-    realm->traceGlobal(trc);
-}
-
-JS_PUBLIC_API(bool)
-gc::RealmNeedsSweep(JS::Realm* realm)
-{
-    return realm->globalIsAboutToBeFinalized();
-}
-
-JS_PUBLIC_API(JS::Realm*)
-JS::GetCurrentRealmOrNull(JSContext* cx)
-{
-    return cx->realm();
-}
-
-JS_PUBLIC_API(JS::Realm*)
-JS::GetObjectRealmOrNull(JSObject* obj)
-{
-    return IsCrossCompartmentWrapper(obj) ? nullptr : obj->realm();
-}
-
-JS_PUBLIC_API(void*)
-JS::GetRealmPrivate(JS::Realm* realm)
-{
-    return realm->realmPrivate();
-}
-
-JS_PUBLIC_API(void)
-JS::SetRealmPrivate(JS::Realm* realm, void* data)
-{
-    realm->setRealmPrivate(data);
-}
-
-JS_PUBLIC_API(void)
-JS::SetDestroyRealmCallback(JSContext* cx, JS::DestroyRealmCallback callback)
-{
-    cx->runtime()->destroyRealmCallback = callback;
-}
-
-JS_PUBLIC_API(void)
-JS::SetRealmNameCallback(JSContext* cx, JS::RealmNameCallback callback)
-{
-    cx->runtime()->realmNameCallback = callback;
-}
-
-JS_PUBLIC_API(JSObject*)
-JS::GetRealmGlobalOrNull(Handle<JS::Realm*> realm)
-{
-    return realm->maybeGlobal();
-}
-
-JS_PUBLIC_API(JSObject*)
-JS::GetRealmObjectPrototype(JSContext* cx)
-{
-    CHECK_REQUEST(cx);
-    return GlobalObject::getOrCreateObjectPrototype(cx, cx->global());
-}
-
-JS_PUBLIC_API(JSObject*)
-JS::GetRealmFunctionPrototype(JSContext* cx)
-{
-    CHECK_REQUEST(cx);
-    return GlobalObject::getOrCreateFunctionPrototype(cx, cx->global());
-}
-
-JS_PUBLIC_API(JSObject*)
-JS::GetRealmArrayPrototype(JSContext* cx)
-{
-    CHECK_REQUEST(cx);
-    return GlobalObject::getOrCreateArrayPrototype(cx, cx->global());
-}
-
-JS_PUBLIC_API(JSObject*)
-JS::GetRealmErrorPrototype(JSContext* cx)
-{
-    CHECK_REQUEST(cx);
-    return GlobalObject::getOrCreateCustomErrorPrototype(cx, cx->global(), JSEXN_ERR);
-}
-
-JS_PUBLIC_API(JSObject*)
-JS::GetRealmIteratorPrototype(JSContext* cx)
-{
-    CHECK_REQUEST(cx);
-    return GlobalObject::getOrCreateIteratorPrototype(cx, cx->global());
-}