Bug 1466121 part 7 - Split Compartment-inl.h from Realm-inl.h. r=luke
authorJan de Mooij <jdemooij@mozilla.com>
Fri, 08 Jun 2018 16:16:21 +0200
changeset 422015 cceb75ca1a1d212266feecdf1143c4d3f2724312
parent 422014 45e231683dbf3f724fa751aede3e617815c4cf23
child 422016 52724ae751a5e196e34cb8db096c6856ac7aee0f
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 7 - Split Compartment-inl.h from Realm-inl.h. r=luke
js/src/builtin/Promise.cpp
js/src/builtin/TestingFunctions.cpp
js/src/jsapi.cpp
js/src/proxy/CrossCompartmentWrapper.cpp
js/src/shell/js.cpp
js/src/vm/Compartment-inl.h
js/src/vm/Compartment.cpp
js/src/vm/Debugger.cpp
js/src/vm/Iteration.cpp
js/src/vm/JSContext.cpp
js/src/vm/JSObject.cpp
js/src/vm/JSScript.cpp
js/src/vm/Realm-inl.h
js/src/vm/Stack.cpp
--- a/js/src/builtin/Promise.cpp
+++ b/js/src/builtin/Promise.cpp
@@ -16,16 +16,17 @@
 #include "gc/Heap.h"
 #include "js/Debug.h"
 #include "vm/AsyncFunction.h"
 #include "vm/AsyncIteration.h"
 #include "vm/Debugger.h"
 #include "vm/Iteration.h"
 #include "vm/JSContext.h"
 
+#include "vm/Compartment-inl.h"
 #include "vm/Debugger-inl.h"
 #include "vm/JSObject-inl.h"
 #include "vm/NativeObject-inl.h"
 
 using namespace js;
 
 static double
 MillisecondsSinceStartup()
--- a/js/src/builtin/TestingFunctions.cpp
+++ b/js/src/builtin/TestingFunctions.cpp
@@ -65,16 +65,17 @@
 #include "wasm/AsmJS.h"
 #include "wasm/WasmBinaryToText.h"
 #include "wasm/WasmJS.h"
 #include "wasm/WasmModule.h"
 #include "wasm/WasmSignalHandlers.h"
 #include "wasm/WasmTextToBinary.h"
 #include "wasm/WasmTypes.h"
 
+#include "vm/Compartment-inl.h"
 #include "vm/Debugger-inl.h"
 #include "vm/EnvironmentObject-inl.h"
 #include "vm/JSContext-inl.h"
 #include "vm/JSObject-inl.h"
 #include "vm/NativeObject-inl.h"
 #include "vm/StringType-inl.h"
 
 using namespace js;
--- a/js/src/jsapi.cpp
+++ b/js/src/jsapi.cpp
@@ -89,16 +89,17 @@
 #include "vm/Shape.h"
 #include "vm/StringType.h"
 #include "vm/SymbolType.h"
 #include "vm/WrapperObject.h"
 #include "vm/Xdr.h"
 #include "wasm/AsmJS.h"
 #include "wasm/WasmModule.h"
 
+#include "vm/Compartment-inl.h"
 #include "vm/Interpreter-inl.h"
 #include "vm/JSAtom-inl.h"
 #include "vm/JSFunction-inl.h"
 #include "vm/JSScript-inl.h"
 #include "vm/NativeObject-inl.h"
 #include "vm/SavedStacks-inl.h"
 #include "vm/StringType-inl.h"
 
--- a/js/src/proxy/CrossCompartmentWrapper.cpp
+++ b/js/src/proxy/CrossCompartmentWrapper.cpp
@@ -6,16 +6,17 @@
 
 #include "gc/PublicIterators.h"
 #include "js/Wrapper.h"
 #include "proxy/DeadObjectProxy.h"
 #include "vm/Iteration.h"
 #include "vm/WrapperObject.h"
 
 #include "gc/Nursery-inl.h"
+#include "vm/Compartment-inl.h"
 #include "vm/JSObject-inl.h"
 #include "vm/Realm-inl.h"
 
 using namespace js;
 
 #define PIERCE(cx, wrapper, pre, op, post)                      \
     JS_BEGIN_MACRO                                              \
         bool ok;                                                \
--- a/js/src/shell/js.cpp
+++ b/js/src/shell/js.cpp
@@ -109,16 +109,17 @@
 #include "vm/Printer.h"
 #include "vm/Shape.h"
 #include "vm/SharedArrayObject.h"
 #include "vm/Time.h"
 #include "vm/TypedArrayObject.h"
 #include "vm/WrapperObject.h"
 #include "wasm/WasmJS.h"
 
+#include "vm/Compartment-inl.h"
 #include "vm/ErrorObject-inl.h"
 #include "vm/Interpreter-inl.h"
 #include "vm/JSObject-inl.h"
 #include "vm/Realm-inl.h"
 #include "vm/Stack-inl.h"
 
 using namespace js;
 using namespace js::cli;
copy from js/src/vm/Realm-inl.h
copy to js/src/vm/Compartment-inl.h
--- a/js/src/vm/Realm-inl.h
+++ b/js/src/vm/Compartment-inl.h
@@ -1,97 +1,25 @@
 /* -*- 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/. */
 
-#ifndef vm_Realm_inl_h
-#define vm_Realm_inl_h
+#ifndef vm_Compartment_inl_h
+#define vm_Compartment_inl_h
 
-#include "vm/Realm.h"
+#include "vm/Compartment.h"
 
 #include "gc/Barrier.h"
 #include "gc/Marking.h"
 #include "vm/Iteration.h"
 
 #include "vm/JSContext-inl.h"
 
-inline void
-JS::Realm::initGlobal(js::GlobalObject& global)
-{
-    MOZ_ASSERT(global.realm() == this);
-    MOZ_ASSERT(!global_);
-    global_.set(&global);
-}
-
-js::GlobalObject*
-JS::Realm::maybeGlobal() const
-{
-    MOZ_ASSERT_IF(global_, global_->realm() == this);
-    return global_;
-}
-
-js::GlobalObject*
-JS::Realm::unsafeUnbarrieredMaybeGlobal() const
-{
-    return *global_.unsafeGet();
-}
-
-inline bool
-JS::Realm::globalIsAboutToBeFinalized()
-{
-    MOZ_ASSERT(zone_->isGCSweeping());
-    return global_ && js::gc::IsAboutToBeFinalizedUnbarriered(global_.unsafeGet());
-}
-
-/* static */ inline js::ObjectRealm&
-js::ObjectRealm::get(const JSObject* obj)
-{
-    return obj->realm()->objects_;
-}
-
-template <typename T>
-js::AutoRealm::AutoRealm(JSContext* cx, const T& target)
-  : cx_(cx),
-    origin_(cx->realm())
-{
-    cx_->enterRealmOf(target);
-}
-
-// Protected constructor that bypasses assertions in enterRealmOf.
-js::AutoRealm::AutoRealm(JSContext* cx, JS::Realm* target)
-  : cx_(cx),
-    origin_(cx->realm())
-{
-    cx_->enterRealm(target);
-}
-
-js::AutoRealm::~AutoRealm()
-{
-    cx_->leaveRealm(origin_);
-}
-
-js::AutoAtomsZone::AutoAtomsZone(JSContext* cx, js::AutoLockForExclusiveAccess& lock)
-  : cx_(cx),
-    origin_(cx->realm()),
-    lock_(lock)
-{
-    cx_->enterAtomsZone(lock);
-}
-
-js::AutoAtomsZone::~AutoAtomsZone()
-{
-    cx_->leaveAtomsZone(origin_, lock_);
-}
-
-js::AutoRealmUnchecked::AutoRealmUnchecked(JSContext* cx, JS::Realm* target)
-  : AutoRealm(cx, target)
-{}
-
 inline bool
 JS::Compartment::wrap(JSContext* cx, JS::MutableHandleValue vp)
 {
     /* Only GC things have to be wrapped or copied. */
     if (!vp.isGCThing())
         return true;
 
     /*
@@ -162,26 +90,9 @@ JS::Compartment::wrap(JSContext* cx, JS:
     JS::RootedObject obj(cx, &vp.toObject());
     if (!wrap(cx, &obj))
         return false;
     vp.setObject(*obj);
     MOZ_ASSERT_IF(cacheResult, obj == cacheResult);
     return true;
 }
 
-MOZ_ALWAYS_INLINE bool
-js::ObjectRealm::objectMaybeInIteration(JSObject* obj)
-{
-    MOZ_ASSERT(&ObjectRealm::get(obj) == this);
-
-    // If the list is empty we're not iterating any objects.
-    js::NativeIterator* next = enumerators->next();
-    if (enumerators == next)
-        return false;
-
-    // If the list contains a single object, check if it's |obj|.
-    if (next->next() == enumerators)
-        return next->objectBeingIterated() == obj;
-
-    return true;
-}
-
-#endif /* vm_Realm_inl_h */
+#endif /* vm_Compartment_inl_h */
--- a/js/src/vm/Compartment.cpp
+++ b/js/src/vm/Compartment.cpp
@@ -1,14 +1,16 @@
 /* -*- 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 "vm/Compartment-inl.h"
+
 #include "mozilla/MemoryReporting.h"
 
 #include <stddef.h>
 
 #include "jsfriendapi.h"
 
 #include "gc/Policy.h"
 #include "gc/PublicIterators.h"
@@ -24,17 +26,16 @@
 
 #include "gc/GC-inl.h"
 #include "gc/Marking-inl.h"
 #include "vm/JSAtom-inl.h"
 #include "vm/JSFunction-inl.h"
 #include "vm/JSObject-inl.h"
 #include "vm/JSScript-inl.h"
 #include "vm/NativeObject-inl.h"
-#include "vm/Realm-inl.h"
 #include "vm/UnboxedObject-inl.h"
 
 using namespace js;
 using namespace js::gc;
 
 Compartment::Compartment(Zone* zone)
   : zone_(zone),
     runtime_(zone->runtimeFromAnyThread())
--- a/js/src/vm/Debugger.cpp
+++ b/js/src/vm/Debugger.cpp
@@ -41,16 +41,17 @@
 #include "vm/JSObject.h"
 #include "vm/Realm.h"
 #include "vm/TraceLogging.h"
 #include "vm/WrapperObject.h"
 #include "wasm/WasmInstance.h"
 
 #include "gc/GC-inl.h"
 #include "vm/BytecodeUtil-inl.h"
+#include "vm/Compartment-inl.h"
 #include "vm/GeckoProfiler-inl.h"
 #include "vm/JSObject-inl.h"
 #include "vm/JSScript-inl.h"
 #include "vm/NativeObject-inl.h"
 #include "vm/Stack-inl.h"
 
 using namespace js;
 
--- a/js/src/vm/Iteration.cpp
+++ b/js/src/vm/Iteration.cpp
@@ -32,16 +32,17 @@
 #include "vm/Interpreter.h"
 #include "vm/JSAtom.h"
 #include "vm/JSContext.h"
 #include "vm/JSObject.h"
 #include "vm/JSScript.h"
 #include "vm/Shape.h"
 #include "vm/TypedArrayObject.h"
 
+#include "vm/Compartment-inl.h"
 #include "vm/JSScript-inl.h"
 #include "vm/NativeObject-inl.h"
 #include "vm/ReceiverGuard-inl.h"
 #include "vm/Stack-inl.h"
 #include "vm/StringType-inl.h"
 
 using namespace js;
 using namespace js::gc;
--- a/js/src/vm/JSContext.cpp
+++ b/js/src/vm/JSContext.cpp
@@ -48,16 +48,17 @@
 #include "vm/Iteration.h"
 #include "vm/JSAtom.h"
 #include "vm/JSFunction.h"
 #include "vm/JSObject.h"
 #include "vm/JSScript.h"
 #include "vm/Realm.h"
 #include "vm/Shape.h"
 
+#include "vm/Compartment-inl.h"
 #include "vm/JSObject-inl.h"
 #include "vm/JSScript-inl.h"
 #include "vm/Stack-inl.h"
 
 using namespace js;
 using namespace js::gc;
 
 using mozilla::DebugOnly;
--- a/js/src/vm/JSObject.cpp
+++ b/js/src/vm/JSObject.cpp
@@ -56,16 +56,17 @@
 #include "vm/TypedArrayObject.h"
 
 #include "builtin/Boolean-inl.h"
 #include "builtin/TypedObject-inl.h"
 #include "gc/Marking-inl.h"
 #include "vm/ArrayObject-inl.h"
 #include "vm/BooleanObject-inl.h"
 #include "vm/Caches-inl.h"
+#include "vm/Compartment-inl.h"
 #include "vm/Interpreter-inl.h"
 #include "vm/JSAtom-inl.h"
 #include "vm/JSContext-inl.h"
 #include "vm/JSFunction-inl.h"
 #include "vm/NativeObject-inl.h"
 #include "vm/NumberObject-inl.h"
 #include "vm/Realm-inl.h"
 #include "vm/Shape-inl.h"
--- a/js/src/vm/JSScript.cpp
+++ b/js/src/vm/JSScript.cpp
@@ -52,16 +52,17 @@
 #include "vm/Opcodes.h"
 #include "vm/SelfHosting.h"
 #include "vm/Shape.h"
 #include "vm/SharedImmutableStringsCache.h"
 #include "vm/Xdr.h"
 #include "vtune/VTuneWrapper.h"
 
 #include "gc/Marking-inl.h"
+#include "vm/Compartment-inl.h"
 #include "vm/EnvironmentObject-inl.h"
 #include "vm/JSFunction-inl.h"
 #include "vm/JSObject-inl.h"
 #include "vm/NativeObject-inl.h"
 #include "vm/SharedImmutableStringsCache-inl.h"
 #include "vm/Stack-inl.h"
 
 using namespace js;
--- a/js/src/vm/Realm-inl.h
+++ b/js/src/vm/Realm-inl.h
@@ -82,96 +82,16 @@ js::AutoAtomsZone::~AutoAtomsZone()
 {
     cx_->leaveAtomsZone(origin_, lock_);
 }
 
 js::AutoRealmUnchecked::AutoRealmUnchecked(JSContext* cx, JS::Realm* target)
   : AutoRealm(cx, target)
 {}
 
-inline bool
-JS::Compartment::wrap(JSContext* cx, JS::MutableHandleValue vp)
-{
-    /* Only GC things have to be wrapped or copied. */
-    if (!vp.isGCThing())
-        return true;
-
-    /*
-     * Symbols are GC things, but never need to be wrapped or copied because
-     * they are always allocated in the atoms zone. They still need to be
-     * marked in the new compartment's zone, however.
-     */
-    if (vp.isSymbol()) {
-        cx->markAtomValue(vp);
-        return true;
-    }
-
-    /* Handle strings. */
-    if (vp.isString()) {
-        JS::RootedString str(cx, vp.toString());
-        if (!wrap(cx, &str))
-            return false;
-        vp.setString(str);
-        return true;
-    }
-
-#ifdef ENABLE_BIGINT
-    if (vp.isBigInt()) {
-        JS::RootedBigInt bi(cx, vp.toBigInt());
-        if (!wrap(cx, &bi))
-            return false;
-        vp.setBigInt(bi);
-        return true;
-    }
-#endif
-
-    MOZ_ASSERT(vp.isObject());
-
-    /*
-     * All that's left are objects.
-     *
-     * Object wrapping isn't the fastest thing in the world, in part because
-     * we have to unwrap and invoke the prewrap hook to find the identity
-     * object before we even start checking the cache. Neither of these
-     * operations are needed in the common case, where we're just wrapping
-     * a plain JS object from the wrappee's side of the membrane to the
-     * wrapper's side.
-     *
-     * To optimize this, we note that the cache should only ever contain
-     * identity objects - that is to say, objects that serve as the
-     * canonical representation for a unique object identity observable by
-     * script. Unwrap and prewrap are both steps that we take to get to the
-     * identity of an incoming objects, and as such, they shuld never map
-     * one identity object to another object. This means that we can safely
-     * check the cache immediately, and only risk false negatives. Do this
-     * in opt builds, and do both in debug builds so that we can assert
-     * that we get the same answer.
-     */
-#ifdef DEBUG
-    MOZ_ASSERT(JS::ValueIsNotGray(vp));
-    JS::RootedObject cacheResult(cx);
-#endif
-    JS::RootedValue v(cx, vp);
-    if (js::WrapperMap::Ptr p = crossCompartmentWrappers.lookup(js::CrossCompartmentKey(v))) {
-#ifdef DEBUG
-        cacheResult = &p->value().get().toObject();
-#else
-        vp.set(p->value().get());
-        return true;
-#endif
-    }
-
-    JS::RootedObject obj(cx, &vp.toObject());
-    if (!wrap(cx, &obj))
-        return false;
-    vp.setObject(*obj);
-    MOZ_ASSERT_IF(cacheResult, obj == cacheResult);
-    return true;
-}
-
 MOZ_ALWAYS_INLINE bool
 js::ObjectRealm::objectMaybeInIteration(JSObject* obj)
 {
     MOZ_ASSERT(&ObjectRealm::get(obj) == this);
 
     // If the list is empty we're not iterating any objects.
     js::NativeIterator* next = enumerators->next();
     if (enumerators == next)
--- a/js/src/vm/Stack.cpp
+++ b/js/src/vm/Stack.cpp
@@ -12,16 +12,17 @@
 #include "jit/BaselineFrame.h"
 #include "jit/JitcodeMap.h"
 #include "jit/JitRealm.h"
 #include "vm/Debugger.h"
 #include "vm/JSContext.h"
 #include "vm/Opcodes.h"
 
 #include "jit/JSJitFrameIter-inl.h"
+#include "vm/Compartment-inl.h"
 #include "vm/EnvironmentObject-inl.h"
 #include "vm/Interpreter-inl.h"
 #include "vm/Probes-inl.h"
 
 using namespace js;
 
 using mozilla::ArrayLength;
 using mozilla::DebugOnly;