Bug 1541580 - Cleanup ProxyObject creation r=jandem a=pascalc
authorTed Campbell <tcampbell@mozilla.com>
Mon, 08 Apr 2019 14:45:34 +0000
changeset 523108 590d0706d113fca9c085f866f3c7ea29955cc8e2
parent 523107 e52e74683afcfd9434253927cc54c9081b28a187
child 523109 661df9ccbd0de5eda56c3cf0a766c2ddcee3abbe
push id11057
push userarchaeopteryx@coole-files.de
push dateWed, 10 Apr 2019 14:56:16 +0000
treeherdermozilla-beta@590d0706d113 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjandem, pascalc
bugs1541580
milestone67.0
Bug 1541580 - Cleanup ProxyObject creation r=jandem a=pascalc Differential Revision: https://phabricator.services.mozilla.com/D26157
js/src/vm/ProxyObject.cpp
--- a/js/src/vm/ProxyObject.cpp
+++ b/js/src/vm/ProxyObject.cpp
@@ -108,18 +108,26 @@ ProxyObject* ProxyObject::New(JSContext*
   proxy->data.handler = handler;
   if (IsCrossCompartmentWrapper(proxy)) {
     MOZ_ASSERT(cx->global() == &cx->compartment()->globalForNewCCW());
     proxy->setCrossCompartmentPrivate(priv);
   } else {
     proxy->setSameCompartmentPrivate(priv);
   }
 
+  if (newKind == SingletonObject) {
+    Rooted<ProxyObject*> rootedProxy(cx, proxy);
+    if (!JSObject::setSingleton(cx, rootedProxy)) {
+      return nullptr;
+    }
+    return rootedProxy;
+  }
+
   /* Don't track types of properties of non-DOM and non-singleton proxies. */
-  if (newKind != SingletonObject && !clasp->isDOMClass()) {
+  if (!clasp->isDOMClass()) {
     MarkObjectGroupUnknownProperties(cx, proxy->group());
   }
 
   return proxy;
 }
 
 gc::AllocKind ProxyObject::allocKindForTenure() const {
   MOZ_ASSERT(usingInlineValueArray());
@@ -197,24 +205,16 @@ void ProxyObject::nuke() {
   pobj->initGroup(group);
   pobj->initShape(shape);
 
   MOZ_ASSERT(clasp->shouldDelayMetadataBuilder());
   cx->realm()->setObjectPendingMetadata(cx, pobj);
 
   js::gc::gcTracer.traceCreateObject(pobj);
 
-  if (newKind == SingletonObject) {
-    Rooted<ProxyObject*> pobjRoot(cx, pobj);
-    if (!JSObject::setSingleton(cx, pobjRoot)) {
-      return cx->alreadyReportedOOM();
-    }
-    pobj = pobjRoot;
-  }
-
   return pobj;
 }
 
 JS_FRIEND_API void js::detail::SetValueInProxy(Value* slot,
                                                const Value& value) {
   // Slots in proxies are not GCPtrValues, so do a cast whenever assigning
   // values to them which might trigger a barrier.
   *reinterpret_cast<GCPtrValue*>(slot) = value;