Bug 945416 part 4. Introduce a DoNewResolve method on nsGlobalWindow and call it from nsWindowSH::NewResolve. r=peterv
authorBoris Zbarsky <bzbarsky@mit.edu>
Wed, 29 Jan 2014 22:33:25 -0800
changeset 181960 6891009a669a605e8e3c60f65689aa57516127bd
parent 181959 7e8bbbcff2684cf0b204251c4c6f2b8b30cca706
child 181961 1275917b08fe14e77fd769aed786c4992e0a0323
push id3343
push userffxbld
push dateMon, 17 Mar 2014 21:55:32 +0000
treeherdermozilla-beta@2f7d3415f79f [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerspeterv
bugs945416
milestone29.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 945416 part 4. Introduce a DoNewResolve method on nsGlobalWindow and call it from nsWindowSH::NewResolve. r=peterv
dom/base/nsDOMClassInfo.cpp
dom/base/nsDOMClassInfo.h
dom/base/nsGlobalWindow.cpp
dom/base/nsGlobalWindow.h
--- a/dom/base/nsDOMClassInfo.cpp
+++ b/dom/base/nsDOMClassInfo.cpp
@@ -3373,32 +3373,34 @@ nsWindowSH::NewResolve(nsIXPConnectWrapp
     // object in that data structure as a flag that indicates that its name
     // (and any relevant named constructor names) has been resolved before;
     // this allows us to avoid re-resolving in the Xray case if the property is
     // deleted by page script.
     JS::Rooted<JSObject*> global(cx,
       js::UncheckedUnwrap(obj, /* stopAtOuter = */ false));
     JSAutoCompartment ac(cx, global);
     JS::Rooted<JSPropertyDescriptor> desc(cx);
-    nsresult rv = GlobalResolve(win, cx, global, id, &desc);
-    NS_ENSURE_SUCCESS(rv, rv);
+    if (!win->DoNewResolve(cx, global, id, &desc)) {
+      return NS_ERROR_FAILURE;
+    }
     // If we have an object here, that means we resolved the property.
     // But if the value is undefined, that means that GlobalResolve
     // also already defined it, so we don't have to.
     if (desc.object() && !desc.value().isUndefined() &&
         !JS_DefinePropertyById(cx, global, id, desc.value(),
                                desc.getter(), desc.setter(),
                                desc.attributes())) {
       return NS_ERROR_FAILURE;
     }
   }
 
   JS::Rooted<JSPropertyDescriptor> desc(cx);
-  nsresult rv = GlobalResolve(win, cx, obj, id, &desc);
-  NS_ENSURE_SUCCESS(rv, rv);
+  if (!win->DoNewResolve(cx, obj, id, &desc)) {
+    return NS_ERROR_FAILURE;
+  }
   if (desc.object()) {
     // If we have an object here, that means we resolved the property.
     // But if the value is undefined, that means that GlobalResolve
     // also already defined it, so we don't have to.  Note that in the
     // Xray case we should never see undefined.
     MOZ_ASSERT_IF(isXray, !desc.value().isUndefined());
     if (!desc.value().isUndefined() &&
         !JS_DefinePropertyById(cx, obj, id, desc.value(),
@@ -3409,18 +3411,18 @@ nsWindowSH::NewResolve(nsIXPConnectWrapp
 
     *objp = obj;
     return NS_OK;
   }
 
   if (!(flags & JSRESOLVE_ASSIGNING) && sDocument_id == id) {
     nsCOMPtr<nsIDocument> document = win->GetDoc();
     JS::Rooted<JS::Value> v(cx);
-    rv = WrapNative(cx, JS::CurrentGlobalOrNull(cx), document, document,
-                    &NS_GET_IID(nsIDOMDocument), &v, false);
+    nsresult rv = WrapNative(cx, JS::CurrentGlobalOrNull(cx), document, document,
+                             &NS_GET_IID(nsIDOMDocument), &v, false);
     NS_ENSURE_SUCCESS(rv, rv);
 
     // nsIDocument::WrapObject will handle defining the property.
     *objp = obj;
 
     // NB: We need to do this for any Xray wrapper.
     if (xpc::WrapperFactory::IsXrayWrapper(obj)) {
       *_retval = JS_WrapValue(cx, &v) &&
--- a/dom/base/nsDOMClassInfo.h
+++ b/dom/base/nsDOMClassInfo.h
@@ -253,16 +253,17 @@ protected:
   virtual ~nsWindowSH()
   {
   }
 
   static nsresult GlobalResolve(nsGlobalWindow *aWin, JSContext *cx,
                                 JS::Handle<JSObject*> obj, JS::Handle<jsid> id,
                                 JS::MutableHandle<JSPropertyDescriptor> desc);
 
+  friend class nsGlobalWindow;
 public:
   NS_IMETHOD PreCreate(nsISupports *nativeObj, JSContext *cx,
                        JSObject *globalObj, JSObject **parentObj) MOZ_OVERRIDE;
   NS_IMETHOD PostCreatePrototype(JSContext * cx, JSObject * proto) MOZ_OVERRIDE;
   NS_IMETHOD PostCreate(nsIXPConnectWrappedNative *wrapper, JSContext *cx,
                         JSObject *obj) MOZ_OVERRIDE;
   NS_IMETHOD Enumerate(nsIXPConnectWrappedNative *wrapper, JSContext *cx,
                        JSObject *obj, bool *_retval) MOZ_OVERRIDE;
--- a/dom/base/nsGlobalWindow.cpp
+++ b/dom/base/nsGlobalWindow.cpp
@@ -4047,16 +4047,35 @@ nsGlobalWindow::GetSupportedNames(nsTArr
     for (uint32_t i = 0; i < length; ++i, ++name) {
       nsCOMPtr<nsIDocShellTreeItem> item =
         windows->GetDocShellTreeItemAt(i);
       item->GetName(*name);
     }
   }
 }
 
+bool
+nsGlobalWindow::DoNewResolve(JSContext* aCx, JS::Handle<JSObject*> aObj,
+                             JS::Handle<jsid> aId,
+                             JS::MutableHandle<JSPropertyDescriptor> aDesc)
+{
+  MOZ_ASSERT(IsInnerWindow());
+
+  if (!JSID_IS_STRING(aId)) {
+    return true;
+  }
+
+  nsresult rv = nsWindowSH::GlobalResolve(this, aCx, aObj, aId, aDesc);
+  if (NS_FAILED(rv)) {
+    return Throw(aCx, rv);
+  }
+
+  return true;
+}
+
 nsIDOMOfflineResourceList*
 nsGlobalWindow::GetApplicationCache(ErrorResult& aError)
 {
   FORWARD_TO_INNER_OR_THROW(GetApplicationCache, (aError), aError, nullptr);
 
   if (!mApplicationCache) {
     nsCOMPtr<nsIWebNavigation> webNav(do_QueryInterface(GetDocShell()));
     if (!webNav) {
--- a/dom/base/nsGlobalWindow.h
+++ b/dom/base/nsGlobalWindow.h
@@ -470,16 +470,20 @@ public:
   // nsIInterfaceRequestor
   NS_DECL_NSIINTERFACEREQUESTOR
 
   // WebIDL interface.
   already_AddRefed<nsIDOMWindow> IndexedGetter(uint32_t aIndex, bool& aFound);
 
   void GetSupportedNames(nsTArray<nsString>& aNames);
 
+  bool DoNewResolve(JSContext* aCx, JS::Handle<JSObject*> aObj,
+                    JS::Handle<jsid> aId,
+                    JS::MutableHandle<JSPropertyDescriptor> aDesc);
+
   // Object Management
   nsGlobalWindow(nsGlobalWindow *aOuterWindow);
 
   static nsGlobalWindow *FromSupports(nsISupports *supports)
   {
     // Make sure this matches the casts we do in QueryInterface().
     return (nsGlobalWindow *)(mozilla::dom::EventTarget *)supports;
   }