Bug 1691008 - Part 5: Remove Wrapper::NewSingleton. r=jandem
authorAndré Bargull <andre.bargull@gmail.com>
Fri, 05 Feb 2021 14:15:41 +0000
changeset 566144 b3580d2200b2c3fc915e26d83840232aa3201290
parent 566143 cec65ae7ba08877a3922678a8a03615f012ac4a9
child 566145 f37a4a21c8e83f06fa7eb6a104d6ca2d1299f761
push id38176
push userapavel@mozilla.com
push dateSat, 06 Feb 2021 09:42:43 +0000
treeherdermozilla-central@ea0966587b4a [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjandem
bugs1691008
milestone87.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 1691008 - Part 5: Remove Wrapper::NewSingleton. r=jandem `Wrapper::NewSingleton()` performs the same operations as `Wrapper::New()`. Depends on D104184 Differential Revision: https://phabricator.services.mozilla.com/D104185
dom/base/nsGlobalWindowOuter.cpp
js/public/Wrapper.h
js/rust/src/glue.rs
js/rust/src/jsglue.cpp
js/src/jsapi-tests/testBug604087.cpp
js/src/proxy/Wrapper.cpp
js/src/shell/js.cpp
--- a/dom/base/nsGlobalWindowOuter.cpp
+++ b/dom/base/nsGlobalWindowOuter.cpp
@@ -1297,20 +1297,20 @@ static JSObject* NewOuterWindowProxy(JSC
                                      bool isChrome) {
   MOZ_ASSERT(JS_IsGlobalObject(global));
 
   JSAutoRealm ar(cx, global);
 
   js::WrapperOptions options;
   options.setClass(&OuterWindowProxyClass);
   JSObject* obj =
-      js::Wrapper::NewSingleton(cx, global,
-                                isChrome ? &nsChromeOuterWindowProxy::singleton
-                                         : &nsOuterWindowProxy::singleton,
-                                options);
+      js::Wrapper::New(cx, global,
+                       isChrome ? &nsChromeOuterWindowProxy::singleton
+                                : &nsOuterWindowProxy::singleton,
+                       options);
   MOZ_ASSERT_IF(obj, js::IsWindowProxy(obj));
   return obj;
 }
 
 //*****************************************************************************
 //***    nsGlobalWindowOuter: Object Management
 //*****************************************************************************
 
--- a/js/public/Wrapper.h
+++ b/js/public/Wrapper.h
@@ -154,20 +154,16 @@ class JS_FRIEND_API Wrapper : public For
 
   using BaseProxyHandler::Action;
 
   enum Flags { CROSS_COMPARTMENT = 1 << 0, LAST_USED_FLAG = CROSS_COMPARTMENT };
 
   static JSObject* New(JSContext* cx, JSObject* obj, const Wrapper* handler,
                        const WrapperOptions& options = WrapperOptions());
 
-  static JSObject* NewSingleton(
-      JSContext* cx, JSObject* obj, const Wrapper* handler,
-      const WrapperOptions& options = WrapperOptions());
-
   static JSObject* Renew(JSObject* existing, JSObject* obj,
                          const Wrapper* handler);
 
   static inline const Wrapper* wrapperHandler(const JSObject* wrapper);
 
   static JSObject* wrappedObject(JSObject* wrapper);
 
   unsigned flags() const { return mFlags; }
--- a/js/rust/src/glue.rs
+++ b/js/rust/src/glue.rs
@@ -296,22 +296,16 @@ extern "C" {
         construct: *mut JSObject,
     ) -> *mut JSObject;
     pub fn WrapperNew(
         aCx: *mut JSContext,
         aObj: JS::HandleObject,
         aHandler: *const ::libc::c_void,
         aClass: *const JSClass,
     ) -> *mut JSObject;
-    pub fn WrapperNewSingleton(
-        aCx: *mut JSContext,
-        aObj: JS::HandleObject,
-        aHandler: *const ::libc::c_void,
-        aClass: *const JSClass,
-    ) -> *mut JSObject;
     pub fn NewWindowProxy(
         aCx: *mut JSContext,
         aObj: JS::HandleObject,
         aHandler: *const ::libc::c_void,
     ) -> *mut JSObject;
     pub fn GetWindowProxyClass() -> *const JSClass;
     pub fn GetProxyPrivate(obj: *mut JSObject) -> JS::Value;
     pub fn SetProxyPrivate(obj: *mut JSObject, private: *const JS::Value);
--- a/js/rust/src/jsglue.cpp
+++ b/js/rust/src/jsglue.cpp
@@ -460,42 +460,32 @@ JSObject* WrapperNew(JSContext* aCx, JS:
                      const void* aHandler, const JSClass* aClass) {
   js::WrapperOptions options;
   if (aClass) {
     options.setClass(aClass);
   }
   return js::Wrapper::New(aCx, aObj, (const js::Wrapper*)aHandler, options);
 }
 
-JSObject* WrapperNewSingleton(JSContext* aCx, JS::HandleObject aObj,
-                              const void* aHandler, const JSClass* aClass) {
-  js::WrapperOptions options;
-  if (aClass) {
-    options.setClass(aClass);
-  }
-  return js::Wrapper::NewSingleton(aCx, aObj, (const js::Wrapper*)aHandler,
-                                   options);
-}
-
 const JSClass WindowProxyClass = PROXY_CLASS_DEF(
     "Proxy", JSCLASS_HAS_RESERVED_SLOTS(1)); /* additional class flags */
 
 const JSClass* GetWindowProxyClass() { return &WindowProxyClass; }
 
 JS::Value GetProxyReservedSlot(JSObject* obj, uint32_t slot) {
   return js::GetProxyReservedSlot(obj, slot);
 }
 
 void SetProxyReservedSlot(JSObject* obj, uint32_t slot, const JS::Value* val) {
   js::SetProxyReservedSlot(obj, slot, *val);
 }
 
 JSObject* NewWindowProxy(JSContext* aCx, JS::HandleObject aObj,
                          const void* aHandler) {
-  return WrapperNewSingleton(aCx, aObj, aHandler, &WindowProxyClass);
+  return WrapperNew(aCx, aObj, aHandler, &WindowProxyClass);
 }
 
 JS::Value GetProxyPrivate(JSObject* obj) { return js::GetProxyPrivate(obj); }
 
 void SetProxyPrivate(JSObject* obj, const JS::Value* expando) {
   js::SetProxyPrivate(obj, *expando);
 }
 
--- a/js/src/jsapi-tests/testBug604087.cpp
+++ b/js/src/jsapi-tests/testBug604087.cpp
@@ -42,18 +42,17 @@ static JSObject* Wrap(JSContext* cx, JS:
 static const JSWrapObjectCallbacks WrapObjectCallbacks = {Wrap, PreWrap};
 
 BEGIN_TEST(testBug604087) {
   js::SetWindowProxyClass(cx, &OuterWrapperClass);
 
   js::WrapperOptions options;
   options.setClass(&OuterWrapperClass);
   JS::RootedObject outerObj(
-      cx,
-      js::Wrapper::NewSingleton(cx, global, &js::Wrapper::singleton, options));
+      cx, js::Wrapper::New(cx, global, &js::Wrapper::singleton, options));
   JS::RealmOptions globalOptions;
   JS::RootedObject compartment2(
       cx, JS_NewGlobalObject(cx, getGlobalClass(), nullptr,
                              JS::FireOnNewGlobalHook, globalOptions));
   CHECK(compartment2 != nullptr);
   JS::RootedObject compartment3(
       cx, JS_NewGlobalObject(cx, getGlobalClass(), nullptr,
                              JS::FireOnNewGlobalHook, globalOptions));
@@ -74,18 +73,17 @@ BEGIN_TEST(testBug604087) {
   JS::RootedObject c4wrapper(cx, wrap(cx, outerObj, compartment4));
   CHECK(c4wrapper);
   c4wrapper->as<js::ProxyObject>().setReservedSlot(0, js::Int32Value(4));
   compartment4 = c4wrapper = nullptr;
 
   JS::RootedObject next(cx);
   {
     JSAutoRealm ar(cx, compartment2);
-    next = js::Wrapper::NewSingleton(cx, compartment2, &js::Wrapper::singleton,
-                                     options);
+    next = js::Wrapper::New(cx, compartment2, &js::Wrapper::singleton, options);
     CHECK(next);
   }
 
   JS_SetWrapObjectCallbacks(cx, &WrapObjectCallbacks);
   CHECK(JS_TransplantObject(cx, outerObj, next));
   return true;
 }
 END_TEST(testBug604087)
--- a/js/src/proxy/Wrapper.cpp
+++ b/js/src/proxy/Wrapper.cpp
@@ -280,29 +280,16 @@ JSObject* Wrapper::New(JSContext* cx, JS
   mozilla::Maybe<AutoRealm> ar;
   if (handler->isCrossCompartmentWrapper()) {
     ar.emplace(cx, &cx->compartment()->globalForNewCCW());
   }
   RootedValue priv(cx, ObjectValue(*obj));
   return NewProxyObject(cx, handler, priv, options.proto(), options);
 }
 
-JSObject* Wrapper::NewSingleton(JSContext* cx, JSObject* obj,
-                                const Wrapper* handler,
-                                const WrapperOptions& options) {
-  // If this is a cross-compartment wrapper allocate it in the compartment's
-  // first global. See Compartment::globalForNewCCW.
-  mozilla::Maybe<AutoRealm> ar;
-  if (handler->isCrossCompartmentWrapper()) {
-    ar.emplace(cx, &cx->compartment()->globalForNewCCW());
-  }
-  RootedValue priv(cx, ObjectValue(*obj));
-  return NewProxyObject(cx, handler, priv, options.proto(), options);
-}
-
 JSObject* Wrapper::Renew(JSObject* existing, JSObject* obj,
                          const Wrapper* handler) {
   existing->as<ProxyObject>().renew(handler, ObjectValue(*obj));
   return existing;
 }
 
 JSObject* Wrapper::wrappedObject(JSObject* wrapper) {
   MOZ_ASSERT(wrapper->is<WrapperObject>());
--- a/js/src/shell/js.cpp
+++ b/js/src/shell/js.cpp
@@ -595,17 +595,17 @@ const JSClass ShellWindowProxyClass =
 JSObject* NewShellWindowProxy(JSContext* cx, JS::HandleObject global) {
   MOZ_ASSERT(global->is<GlobalObject>());
 
   js::WrapperOptions options;
   options.setClass(&ShellWindowProxyClass);
 
   JSAutoRealm ar(cx, global);
   JSObject* obj =
-      js::Wrapper::NewSingleton(cx, global, &js::Wrapper::singleton, options);
+      js::Wrapper::New(cx, global, &js::Wrapper::singleton, options);
   MOZ_ASSERT_IF(obj, js::IsWindowProxy(obj));
   return obj;
 }
 
 /*
  * A toy principals type for the shell.
  *
  * In the shell, a principal is simply a 32-bit mask: P subsumes Q if the