Bug 1468252 part 8 - Rename JSObject::global to deprecatedGlobal. r=luke
authorJan de Mooij <jdemooij@mozilla.com>
Thu, 14 Jun 2018 09:07:32 -0700
changeset 422558 fc2ffbc36c07
parent 422557 5a19b871c590
child 422559 a165a02849d3
push id34138
push userdluca@mozilla.com
push dateFri, 15 Jun 2018 02:39:59 +0000
treeherdermozilla-central@e51f8dbf0397 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersluke
bugs1468252
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 1468252 part 8 - Rename JSObject::global to deprecatedGlobal. r=luke
js/src/jit/CacheIR.cpp
js/src/jsapi.cpp
js/src/jsfriendapi.cpp
js/src/vm/Debugger.cpp
js/src/vm/JSObject-inl.h
js/src/vm/JSObject.cpp
js/src/vm/JSObject.h
--- a/js/src/jit/CacheIR.cpp
+++ b/js/src/jit/CacheIR.cpp
@@ -1106,17 +1106,17 @@ GetPropIRGenerator::tryAttachCrossCompar
 
     // If we allowed different zones we would have to wrap strings.
     if (unwrapped->compartment()->zone() != cx_->compartment()->zone())
         return false;
 
     // Take the unwrapped object's global, and wrap in a
     // this-compartment wrapper. This is what will be stored in the IC
     // keep the compartment alive.
-    RootedObject wrappedTargetGlobal(cx_, &unwrapped->global());
+    RootedObject wrappedTargetGlobal(cx_, &unwrapped->deprecatedGlobal());
     if (!cx_->compartment()->wrap(cx_, &wrappedTargetGlobal))
         return false;
 
     bool isWindowProxy = false;
     RootedShape shape(cx_);
     RootedNativeObject holder(cx_);
 
     // Enter realm of target since some checks have side-effects
--- a/js/src/jsapi.cpp
+++ b/js/src/jsapi.cpp
@@ -1210,17 +1210,17 @@ JS_IdToProtoKey(JSContext* cx, HandleId 
     return static_cast<JSProtoKey>(stdnm - standard_class_names);
 }
 
 JS_PUBLIC_API(JSObject*)
 JS_GetGlobalForObject(JSContext* cx, JSObject* obj)
 {
     AssertHeapIsIdle();
     assertSameCompartment(cx, obj);
-    return &obj->global();
+    return &obj->deprecatedGlobal();
 }
 
 extern JS_PUBLIC_API(bool)
 JS_IsGlobalObject(JSObject* obj)
 {
     return obj->is<GlobalObject>();
 }
 
--- a/js/src/jsfriendapi.cpp
+++ b/js/src/jsfriendapi.cpp
@@ -380,17 +380,17 @@ JS_FRIEND_API(bool)
 js::IsFunctionObject(JSObject* obj)
 {
     return obj->is<JSFunction>();
 }
 
 JS_FRIEND_API(JSObject*)
 js::GetGlobalForObjectCrossCompartment(JSObject* obj)
 {
-    return &obj->global();
+    return &obj->deprecatedGlobal();
 }
 
 JS_FRIEND_API(JSObject*)
 js::GetPrototypeNoProxy(JSObject* obj)
 {
     MOZ_ASSERT(!obj->is<js::ProxyObject>());
     return obj->staticPrototype();
 }
--- a/js/src/vm/Debugger.cpp
+++ b/js/src/vm/Debugger.cpp
@@ -3946,18 +3946,18 @@ Debugger::construct(JSContext* cx, unsig
             return false;
 
         debugger = dbg.release();
         obj->setPrivate(debugger); // owns the released pointer
     }
 
     /* Add the initial debuggees, if any. */
     for (unsigned i = 0; i < args.length(); i++) {
-        Rooted<GlobalObject*>
-            debuggee(cx, &args[i].toObject().as<ProxyObject>().private_().toObject().global());
+        JSObject& wrappedObj = args[i].toObject().as<ProxyObject>().private_().toObject();
+        Rooted<GlobalObject*> debuggee(cx, &wrappedObj.deprecatedGlobal());
         if (!debugger->addDebuggeeGlobal(cx, debuggee))
             return false;
     }
 
     args.rval().setObject(*obj);
     return true;
 }
 
@@ -9955,17 +9955,17 @@ DebuggerObject::getClassName(JSContext* 
 
 /* static */ bool
 DebuggerObject::getGlobal(JSContext* cx, HandleDebuggerObject object,
                           MutableHandleDebuggerObject result)
 {
     RootedObject referent(cx, object->referent());
     Debugger* dbg = object->owner();
 
-    RootedObject global(cx, &referent->global());
+    RootedObject global(cx, &referent->deprecatedGlobal());
     return dbg->wrapDebuggeeObject(cx, global, result);
 }
 
 JSAtom*
 DebuggerObject::name(JSContext* cx) const
 {
     MOZ_ASSERT(isFunction());
 
--- a/js/src/vm/JSObject-inl.h
+++ b/js/src/vm/JSObject-inl.h
@@ -386,34 +386,35 @@ SetNewObjectMetadata(JSContext* cx, T* o
     }
 
     return obj;
 }
 
 } // namespace js
 
 inline js::GlobalObject&
-JSObject::global() const
+JSObject::deprecatedGlobal() const
 {
+    return *realm()->unsafeUnbarrieredMaybeGlobal();
+}
+
+inline js::GlobalObject&
+JSObject::nonCCWGlobal() const
+{
+    MOZ_ASSERT(!js::IsCrossCompartmentWrapper(this));
+
     /*
      * The global is read-barriered so that it is kept live by access through
      * the Realm. When accessed through a JSObject, however, the global will be
      * already kept live by the black JSObject's group pointer, so does not
      * need to be read-barriered.
      */
     return *realm()->unsafeUnbarrieredMaybeGlobal();
 }
 
-inline js::GlobalObject&
-JSObject::nonCCWGlobal() const
-{
-    MOZ_ASSERT(!js::IsCrossCompartmentWrapper(this));
-    return global();
-}
-
 inline js::GlobalObject*
 JSObject::globalForTracing(JSTracer*) const
 {
     return realm()->unsafeUnbarrieredMaybeGlobal();
 }
 
 inline bool
 JSObject::isOwnGlobal(JSTracer* trc) const
--- a/js/src/vm/JSObject.cpp
+++ b/js/src/vm/JSObject.cpp
@@ -3554,19 +3554,24 @@ JSObject::uninlinedNonProxyIsExtensible(
 {
     return nonProxyIsExtensible();
 }
 
 void
 JSObject::dump(js::GenericPrinter& out) const
 {
     const JSObject* obj = this;
-    JSObject* globalObj = &global();
     out.printf("object %p\n", obj);
-    out.printf("  global %p [%s]\n", globalObj, globalObj->getClass()->name);
+
+    if (IsCrossCompartmentWrapper(this)) {
+        out.printf("  compartment %p\n", compartment());
+    } else {
+        JSObject* globalObj = &nonCCWGlobal();
+        out.printf("  global %p [%s]\n", globalObj, globalObj->getClass()->name);
+    }
 
     const Class* clasp = obj->getClass();
     out.printf("  class %p %s\n", clasp, clasp->name);
 
     if (obj->hasLazyGroup()) {
         out.put("  lazy group\n");
     } else {
         const ObjectGroup* group = obj->group();
--- a/js/src/vm/JSObject.h
+++ b/js/src/vm/JSObject.h
@@ -424,17 +424,18 @@ class JSObject : public js::gc::Cell
     /*
      * Get the enclosing environment of an object. When called on a
      * non-EnvironmentObject, this will just be the global (the name
      * "enclosing environment" still applies in this situation because
      * non-EnvironmentObjects can be on the environment chain).
      */
     inline JSObject* enclosingEnvironment() const;
 
-    inline js::GlobalObject& global() const;
+    // Deprecated: call nonCCWGlobal or NativeObject::global() instead!
+    inline js::GlobalObject& deprecatedGlobal() const;
 
     // Cross-compartment wrappers are not associated with a single realm/global,
     // so this method asserts the object is not a CCW.
     inline js::GlobalObject& nonCCWGlobal() const;
 
     // In some rare cases the global object's compartment's global may not be
     // the same global object. For this reason, we need to take extra care when
     // tracing.