Bug 987112. Remove the redundant and somewhat annoying parentObject argument to dictionary ToObject() methods. r=bholley
authorBoris Zbarsky <bzbarsky@mit.edu>
Sat, 29 Mar 2014 01:45:10 -0400
changeset 176032 e45db0a68b4f805d3beefbd3d1c1a0b1f501f4a3
parent 176031 265e35a94cc5f72005988d41ed4f4abe8365125d
child 176033 fc8a8379714c8f6751d24893d7e4561cc8248bf0
push id41665
push userbzbarsky@mozilla.com
push dateSat, 29 Mar 2014 05:59:19 +0000
treeherdermozilla-inbound@e45db0a68b4f [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbholley
bugs987112
milestone31.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 987112. Remove the redundant and somewhat annoying parentObject argument to dictionary ToObject() methods. r=bholley
dom/activities/src/Activity.cpp
dom/base/Console.cpp
dom/base/nsGlobalWindow.cpp
dom/bindings/Codegen.py
dom/browser-element/BrowserElementParent.cpp
dom/media/MediaManager.cpp
dom/src/notification/DesktopNotification.cpp
dom/src/notification/Notification.cpp
dom/system/gonk/NetworkWorker.cpp
dom/wifi/WifiProxyService.cpp
layout/inspector/inDOMUtils.cpp
netwerk/base/src/Dashboard.cpp
--- a/dom/activities/src/Activity.cpp
+++ b/dom/activities/src/Activity.cpp
@@ -62,17 +62,17 @@ Activity::Initialize(nsPIDOMWindow* aWin
 
   // Instantiate a JS proxy that will do the child <-> parent communication
   // with the JS implementation of the backend.
   nsresult rv;
   mProxy = do_CreateInstance("@mozilla.org/dom/activities/proxy;1", &rv);
   NS_ENSURE_SUCCESS(rv, rv);
 
   JS::Rooted<JS::Value> optionsValue(aCx);
-  if (!aOptions.ToObject(aCx, JS::NullPtr(), &optionsValue)) {
+  if (!aOptions.ToObject(aCx, &optionsValue)) {
     return NS_ERROR_FAILURE;
   }
 
   mProxy->StartActivity(static_cast<nsIDOMDOMRequest*>(this), optionsValue, aWindow);
   return NS_OK;
 }
 
 Activity::~Activity()
--- a/dom/base/Console.cpp
+++ b/dom/base/Console.cpp
@@ -684,17 +684,17 @@ Console::ProfileMethod(JSContext* aCx, c
   event.mArguments.Construct();
   Sequence<JS::Value>& sequence = event.mArguments.Value();
 
   for (uint32_t i = 0; i < aData.Length(); ++i) {
     sequence.AppendElement(aData[i]);
   }
 
   JS::Rooted<JS::Value> eventValue(aCx);
-  if (!event.ToObject(aCx, JS::NullPtr(), &eventValue)) {
+  if (!event.ToObject(aCx, &eventValue)) {
     aRv.Throw(NS_ERROR_FAILURE);
     return;
   }
 
   JS::Rooted<JSObject*> eventObj(aCx, &eventValue.toObject());
   MOZ_ASSERT(eventObj);
 
   if (!JS_DefineProperty(aCx, eventObj, "wrappedJSObject", eventValue,
@@ -996,17 +996,17 @@ Console::ProcessCallData(ConsoleCallData
     event.mTimer = StopTimer(cx, aData->mArguments[0], aData->mMonotonicTimer);
   }
 
   else if (aData->mMethodName == MethodCount) {
     event.mCounter = IncreaseCounter(cx, frame, aData->mArguments);
   }
 
   JS::Rooted<JS::Value> eventValue(cx);
-  if (!event.ToObject(cx, JS::NullPtr(), &eventValue)) {
+  if (!event.ToObject(cx, &eventValue)) {
     Throw(cx, NS_ERROR_FAILURE);
     return;
   }
 
   JS::Rooted<JSObject*> eventObj(cx, &eventValue.toObject());
   MOZ_ASSERT(eventObj);
 
   if (!JS_DefineProperty(cx, eventObj, "wrappedJSObject", eventValue,
@@ -1295,17 +1295,17 @@ Console::ComposeGroupName(JSContext* aCx
 JS::Value
 Console::StartTimer(JSContext* aCx, const JS::Value& aName,
                     DOMHighResTimeStamp aTimestamp)
 {
   if (mTimerRegistry.Count() >= MAX_PAGE_TIMERS) {
     RootedDictionary<ConsoleTimerError> error(aCx);
 
     JS::Rooted<JS::Value> value(aCx);
-    if (!error.ToObject(aCx, JS::NullPtr(), &value)) {
+    if (!error.ToObject(aCx, &value)) {
       return JS::UndefinedValue();
     }
 
     return value;
   }
 
   RootedDictionary<ConsoleTimerStart> timer(aCx);
 
@@ -1327,17 +1327,17 @@ Console::StartTimer(JSContext* aCx, cons
     mTimerRegistry.Put(key, aTimestamp);
   } else {
     aTimestamp = entry;
   }
 
   timer.mStarted = aTimestamp;
 
   JS::Rooted<JS::Value> value(aCx);
-  if (!timer.ToObject(aCx, JS::NullPtr(), &value)) {
+  if (!timer.ToObject(aCx, &value)) {
     return JS::UndefinedValue();
   }
 
   return value;
 }
 
 JS::Value
 Console::StopTimer(JSContext* aCx, const JS::Value& aName,
@@ -1361,17 +1361,17 @@ Console::StopTimer(JSContext* aCx, const
 
   mTimerRegistry.Remove(key);
 
   RootedDictionary<ConsoleTimerEnd> timer(aCx);
   timer.mName = key;
   timer.mDuration = aTimestamp - entry;
 
   JS::Rooted<JS::Value> value(aCx);
-  if (!timer.ToObject(aCx, JS::NullPtr(), &value)) {
+  if (!timer.ToObject(aCx, &value)) {
     return JS::UndefinedValue();
   }
 
   return value;
 }
 
 void
 Console::ArgumentsToValueList(const nsTArray<JS::Heap<JS::Value>>& aData,
@@ -1409,33 +1409,33 @@ Console::IncreaseCounter(JSContext* aCx,
   }
 
   uint32_t count = 0;
   if (!mCounterRegistry.Get(key, &count)) {
     if (mCounterRegistry.Count() >= MAX_PAGE_COUNTERS) {
       RootedDictionary<ConsoleCounterError> error(aCx);
 
       JS::Rooted<JS::Value> value(aCx);
-      if (!error.ToObject(aCx, JS::NullPtr(), &value)) {
+      if (!error.ToObject(aCx, &value)) {
         return JS::UndefinedValue();
       }
 
       return value;
     }
   }
 
   ++count;
   mCounterRegistry.Put(key, count);
 
   RootedDictionary<ConsoleCounter> data(aCx);
   data.mLabel = label;
   data.mCount = count;
 
   JS::Rooted<JS::Value> value(aCx);
-  if (!data.ToObject(aCx, JS::NullPtr(), &value)) {
+  if (!data.ToObject(aCx, &value)) {
     return JS::UndefinedValue();
   }
 
   return value;
 }
 
 void
 Console::ClearConsoleData()
--- a/dom/base/nsGlobalWindow.cpp
+++ b/dom/base/nsGlobalWindow.cpp
@@ -5673,17 +5673,17 @@ nsGlobalWindow::DispatchResizeEvent(cons
   }
 
   AutoSafeJSContext cx;
   JSAutoCompartment ac(cx, mJSObject);
   DOMWindowResizeEventDetail detail;
   detail.mWidth = aSize.width;
   detail.mHeight = aSize.height;
   JS::Rooted<JS::Value> detailValue(cx);
-  if (!detail.ToObject(cx, JS::NullPtr(), &detailValue)) {
+  if (!detail.ToObject(cx, &detailValue)) {
     return false;
   }
 
   CustomEvent* customEvent = static_cast<CustomEvent*>(domEvent.get());
   customEvent->InitCustomEvent(cx,
                                NS_LITERAL_STRING("DOMWindowResize"),
                                /* bubbles = */ true,
                                /* cancelable = */ true,
--- a/dom/bindings/Codegen.py
+++ b/dom/bindings/Codegen.py
@@ -4667,17 +4667,17 @@ if (!returnArray) {
         return (setObject("*%s.Obj()" % result,
                           wrapAsType=type), False)
 
     if type.isUnion():
         return (wrapAndSetPtr("%s.ToJSVal(cx, ${obj}, ${jsvalHandle})" % result),
                 False)
 
     if type.isDictionary():
-        return (wrapAndSetPtr("%s.ToObject(cx, ${obj}, ${jsvalHandle})" % result),
+        return (wrapAndSetPtr("%s.ToObject(cx, ${jsvalHandle})" % result),
                 False)
 
     if type.isDate():
         return (wrapAndSetPtr("%s.ToDateObject(cx, ${jsvalHandle})" % result),
                 False)
 
     tag = type.tag()
 
@@ -9314,17 +9314,17 @@ if (!*reinterpret_cast<jsid**>(atomsCach
 
 """
             body += string.Template(initIdText).substitute(
               { "dictName": self.makeClassName(self.dictionary)})
 
         if self.dictionary.parent:
             body += (
                 "// Per spec, we define the parent's members first\n"
-                "if (!%s::ToObject(cx, parentObject, rval)) {\n"
+                "if (!%s::ToObject(cx, rval)) {\n"
                 "  return false;\n"
                 "}\n"
                 "JS::Rooted<JSObject*> obj(cx, &rval.toObject());\n"
                 "\n") % self.makeClassName(self.dictionary.parent)
         else:
             body += (
                 "JS::Rooted<JSObject*> obj(cx, JS_NewObject(cx, nullptr, JS::NullPtr(), JS::NullPtr()));\n"
                 "if (!obj) {\n"
@@ -9334,17 +9334,16 @@ if (!*reinterpret_cast<jsid**>(atomsCach
                 "\n")
 
         body += "\n\n".join(self.getMemberDefinition(m).define()
                             for m in self.memberInfo)
         body += "\n\nreturn true;"
 
         return ClassMethod("ToObject", "bool", [
             Argument('JSContext*', 'cx'),
-            Argument('JS::Handle<JSObject*>', 'parentObject'),
             Argument('JS::MutableHandle<JS::Value>', 'rval'),
         ], const=True, body=body)
 
     def initIdsMethod(self):
         assert self.needToInitIds
         idinit = [CGGeneric('!atomsCache->%s.init(cx, "%s")' %
                             (CGDictionary.makeIdName(m.identifier.name),
                              m.identifier.name))
@@ -9593,17 +9592,19 @@ if (""",
                 'result' : "currentValue",
                 'successCode' : ("if (!%s) {\n"
                                  "  return false;\n"
                                  "}\n"
                                  "break;" % propDef),
                 'jsvalRef': "temp",
                 'jsvalHandle': "&temp",
                 'returnsNewObject': False,
-                'obj': "parentObject",
+                # 'obj' can just be allowed to be the string "obj", since that
+                # will be our dictionary object, which is presumably itself in
+                # the right scope.
                 'typedArraysAreStructs': True
             })
         conversion = CGGeneric(innerTemplate)
         conversion = CGWrapper(conversion,
                                pre=("JS::Rooted<JS::Value> temp(cx);\n"
                                     "%s const & currentValue = %s;\n" %
                                     (declType.define(), memberData)
                                     ))
--- a/dom/browser-element/BrowserElementParent.cpp
+++ b/dom/browser-element/BrowserElementParent.cpp
@@ -155,17 +155,17 @@ BrowserElementParent::DispatchOpenWindow
 
   nsIGlobalObject* sgo = aPopupFrameElement->OwnerDoc()->GetScopeObject();
   if (!sgo) {
     return BrowserElementParent::OPEN_WINDOW_IGNORED;
   }
 
   JS::Rooted<JSObject*> global(cx, sgo->GetGlobalJSObject());
   JSAutoCompartment ac(cx, global);
-  if (!detail.ToObject(cx, global, &val)) {
+  if (!detail.ToObject(cx, &val)) {
     MOZ_CRASH("Failed to convert dictionary to JS::Value due to OOM.");
     return BrowserElementParent::OPEN_WINDOW_IGNORED;
   }
 
   nsEventStatus status;
   bool dispatchSucceeded =
     DispatchCustomDOMEvent(aOpenerFrameElement,
                            NS_LITERAL_STRING("mozbrowseropenwindow"),
@@ -327,19 +327,17 @@ NS_IMETHODIMP DispatchAsyncScrollEventRu
 
   AutoSafeJSContext cx;
   JS::Rooted<JSObject*> globalJSObject(cx, globalObject->GetGlobalJSObject());
   NS_ENSURE_TRUE(globalJSObject, NS_ERROR_UNEXPECTED);
 
   JSAutoCompartment ac(cx, globalJSObject);
   JS::Rooted<JS::Value> val(cx);
 
-  // We can get away with a null global here because
-  // AsyncScrollEventDetail only contains numeric values.
-  if (!detail.ToObject(cx, JS::NullPtr(), &val)) {
+  if (!detail.ToObject(cx, &val)) {
     MOZ_CRASH("Failed to convert dictionary to JS::Value due to OOM.");
     return NS_ERROR_FAILURE;
   }
 
   nsEventStatus status = nsEventStatus_eIgnore;
   DispatchCustomDOMEvent(frameElement,
                          NS_LITERAL_STRING("mozbrowserasyncscroll"),
                          cx,
--- a/dom/media/MediaManager.cpp
+++ b/dom/media/MediaManager.cpp
@@ -85,17 +85,17 @@ using dom::Sequence;
 
 static nsresult CompareDictionaries(JSContext* aCx, JSObject *aA,
                                     const MediaTrackConstraintSet &aB,
                                     nsString *aDifference)
 {
   JS::Rooted<JSObject*> a(aCx, aA);
   JSAutoCompartment ac(aCx, aA);
   JS::Rooted<JS::Value> bval(aCx);
-  aB.ToObject(aCx, JS::NullPtr(), &bval);
+  aB.ToObject(aCx, &bval);
   JS::Rooted<JSObject*> b(aCx, &bval.toObject());
 
   // Iterate over each property in A, and check if it is in B
 
   JS::AutoIdArray props(aCx, JS_Enumerate(aCx, a));
 
   for (size_t i = 0; i < props.length(); i++) {
     JS::Rooted<JS::Value> bprop(aCx);
--- a/dom/src/notification/DesktopNotification.cpp
+++ b/dom/src/notification/DesktopNotification.cpp
@@ -96,17 +96,17 @@ DesktopNotification::PostDesktopNotifica
       nsString manifestUrl = EmptyString();
       appsService->GetManifestURLByLocalId(appId, manifestUrl);
       mozilla::AutoSafeJSContext cx;
       JS::Rooted<JS::Value> val(cx);
       AppNotificationServiceOptions ops;
       ops.mTextClickable = true;
       ops.mManifestURL = manifestUrl;
 
-      if (!ops.ToObject(cx, JS::NullPtr(), &val)) {
+      if (!ops.ToObject(cx, &val)) {
         return NS_ERROR_FAILURE;
       }
 
       return appNotifier->ShowAppNotification(mIconURL, mTitle, mDescription,
                                               mObserver, val);
     }
   }
 #endif
--- a/dom/src/notification/Notification.cpp
+++ b/dom/src/notification/Notification.cpp
@@ -578,17 +578,17 @@ Notification::ShowInternal()
         AppNotificationServiceOptions ops;
         ops.mTextClickable = true;
         ops.mManifestURL = manifestUrl;
         ops.mId = alertName;
         ops.mDir = DirectionToString(mDir);
         ops.mLang = mLang;
         ops.mTag = mTag;
 
-        if (!ops.ToObject(cx, JS::NullPtr(), &val)) {
+        if (!ops.ToObject(cx, &val)) {
           NS_WARNING("Converting dict to object failed!");
           return;
         }
 
         appNotifier->ShowAppNotification(mIconUrl, mTitle, mBody,
                                          observer, val);
         return;
       }
--- a/dom/system/gonk/NetworkWorker.cpp
+++ b/dom/system/gonk/NetworkWorker.cpp
@@ -203,17 +203,17 @@ NetworkWorker::PostMessage(JS::Handle<JS
 void
 NetworkWorker::DispatchNetworkResult(const NetworkResultOptions& aOptions)
 {
   MOZ_ASSERT(NS_IsMainThread());
 
   mozilla::AutoSafeJSContext cx;
   JS::RootedValue val(cx);
 
-  if (!aOptions.ToObject(cx, JS::NullPtr(), &val)) {
+  if (!aOptions.ToObject(cx, &val)) {
     return;
   }
 
   // Call the listener with a JS value.
   if (mListener) {
     mListener->OnEvent(val);
   }
 }
--- a/dom/wifi/WifiProxyService.cpp
+++ b/dom/wifi/WifiProxyService.cpp
@@ -276,17 +276,17 @@ WifiProxyService::WaitForEvent(const nsA
 void
 WifiProxyService::DispatchWifiResult(const WifiResultOptions& aOptions, const nsACString& aInterface)
 {
   MOZ_ASSERT(NS_IsMainThread());
 
   mozilla::AutoSafeJSContext cx;
   JS::Rooted<JS::Value> val(cx);
 
-  if (!aOptions.ToObject(cx, JS::NullPtr(), &val)) {
+  if (!aOptions.ToObject(cx, &val)) {
     return;
   }
 
   // Call the listener with a JS value.
   mListener->OnCommand(val, aInterface);
 }
 
 void
--- a/layout/inspector/inDOMUtils.cpp
+++ b/layout/inspector/inDOMUtils.cpp
@@ -636,17 +636,17 @@ inDOMUtils::ColorNameToRGB(const nsAStri
     return NS_ERROR_INVALID_ARG;
   }
 
   InspectorRGBTriple triple;
   triple.mR = NS_GET_R(color);
   triple.mG = NS_GET_G(color);
   triple.mB = NS_GET_B(color);
 
-  if (!triple.ToObject(aCx, JS::NullPtr(), aValue)) {
+  if (!triple.ToObject(aCx, aValue)) {
     return NS_ERROR_FAILURE;
   }
 
   return NS_OK;
 }
 
 NS_IMETHODIMP
 inDOMUtils::RgbToColorName(uint8_t aR, uint8_t aG, uint8_t aB,
--- a/netwerk/base/src/Dashboard.cpp
+++ b/netwerk/base/src/Dashboard.cpp
@@ -312,17 +312,17 @@ LookupHelper::ConstructAnswer(LookupArgu
            aRecord->HasMore(&hasMore);
         }
     } else {
         dict.mAnswer = false;
         CopyASCIItoUTF16(Dashboard::GetErrorString(mStatus), dict.mError);
     }
 
     JS::RootedValue val(cx);
-    if (!dict.ToObject(cx, JS::NullPtr(), &val)) {
+    if (!dict.ToObject(cx, &val)) {
         return NS_ERROR_FAILURE;
     }
 
     this->mCallback->OnDashboardDataAvailable(val);
 
     return NS_OK;
 }
 
@@ -395,17 +395,17 @@ Dashboard::GetSockets(SocketData *aSocke
         mSocket.mReceived = (double) socketData->mData[i].received;
         dict.mSent += socketData->mData[i].sent;
         dict.mReceived += socketData->mData[i].received;
     }
 
     dict.mSent += socketData->mTotalSent;
     dict.mReceived += socketData->mTotalRecv;
     JS::RootedValue val(cx);
-    if (!dict.ToObject(cx, JS::NullPtr(), &val))
+    if (!dict.ToObject(cx, &val))
         return NS_ERROR_FAILURE;
     socketData->mCallback->OnDashboardDataAvailable(val);
 
     return NS_OK;
 }
 
 NS_IMETHODIMP
 Dashboard::RequestHttpConnections(NetDashboardCallback *aCallback)
@@ -498,17 +498,17 @@ Dashboard::GetHttpConnections(HttpData *
 
         for (uint32_t j = 0; j < httpData->mData[i].halfOpens.Length(); j++) {
             HalfOpenInfoDict &info = *halfOpens.AppendElement();
             info.mSpeculative = httpData->mData[i].halfOpens[j].speculative;
         }
     }
 
     JS::RootedValue val(cx);
-    if (!dict.ToObject(cx, JS::NullPtr(), &val)) {
+    if (!dict.ToObject(cx, &val)) {
         return NS_ERROR_FAILURE;
     }
 
     httpData->mCallback->OnDashboardDataAvailable(val);
 
     return NS_OK;
 }
 
@@ -625,17 +625,17 @@ Dashboard::GetWebSocketConnections(WebSo
         websocket.mMsgsent = mWs.data[i].mMsgSent;
         websocket.mMsgreceived = mWs.data[i].mMsgReceived;
         websocket.mSentsize = mWs.data[i].mSizeSent;
         websocket.mReceivedsize = mWs.data[i].mSizeReceived;
         websocket.mEncrypted = mWs.data[i].mEncrypted;
     }
 
     JS::RootedValue val(cx);
-    if (!dict.ToObject(cx, JS::NullPtr(), &val)) {
+    if (!dict.ToObject(cx, &val)) {
         return NS_ERROR_FAILURE;
     }
     wsRequest->mCallback->OnDashboardDataAvailable(val);
 
     return NS_OK;
 }
 
 NS_IMETHODIMP
@@ -712,17 +712,17 @@ Dashboard::GetDNSCacheEntries(DnsData *d
         if (dnsData->mData[i].family == PR_AF_INET6) {
             CopyASCIItoUTF16("ipv6", entry.mFamily);
         } else {
             CopyASCIItoUTF16("ipv4", entry.mFamily);
         }
     }
 
     JS::RootedValue val(cx);
-    if (!dict.ToObject(cx, JS::NullPtr(), &val)) {
+    if (!dict.ToObject(cx, &val)) {
         return NS_ERROR_FAILURE;
     }
     dnsData->mCallback->OnDashboardDataAvailable(val);
 
     return NS_OK;
 }
 
 NS_IMETHODIMP
@@ -814,17 +814,17 @@ Dashboard::GetConnectionStatus(Connectio
 {
     nsRefPtr<ConnectionData> connectionData = aConnectionData;
     AutoSafeJSContext cx;
 
     mozilla::dom::ConnStatusDict dict;
     dict.mStatus = connectionData->mStatus;
 
     JS::RootedValue val(cx);
-    if (!dict.ToObject(cx, JS::NullPtr(), &val))
+    if (!dict.ToObject(cx, &val))
         return NS_ERROR_FAILURE;
 
     connectionData->mCallback->OnDashboardDataAvailable(val);
 
     return NS_OK;
 }
 
 nsresult