Partially back out fix for bug 461563 to try to fix Txul regression on Windows.
authorPeter Van der Beken <peterv@propagandism.org>
Thu, 04 Dec 2008 17:48:32 +0100
changeset 22343 8b1b316eb0647e282fa7d86cec281a2e9435d4aa
parent 22342 2af723cd16800c607b143fe38fe3316660a26d59
child 22344 3dd567dd1322a222dbcaf368512d6167b2343ddd
push idunknown
push userunknown
push dateunknown
bugs461563
milestone1.9.2a1pre
Partially back out fix for bug 461563 to try to fix Txul regression on Windows.
dom/src/base/nsDOMClassInfo.cpp
dom/src/base/nsDOMClassInfo.h
--- a/dom/src/base/nsDOMClassInfo.cpp
+++ b/dom/src/base/nsDOMClassInfo.cpp
@@ -1631,28 +1631,39 @@ nsDOMClassInfo::DefineStaticJSVals(JSCon
 }
 
 // static
 nsresult
 nsDOMClassInfo::WrapNative(JSContext *cx, JSObject *scope, nsISupports *native,
                            const nsIID& aIID, jsval *vp,
                            nsIXPConnectJSObjectHolder **aHolder)
 {
+  *aHolder = nsnull;
+  
   if (!native) {
-    NS_ASSERTION(!aHolder || !*aHolder, "*aHolder should be null!");
-
     *vp = JSVAL_NULL;
 
     return NS_OK;
   }
 
   NS_ENSURE_TRUE(sXPConnect, NS_ERROR_UNEXPECTED);
 
-  return sXPConnect->WrapNativeToJSVal(cx, ::JS_GetGlobalForObject(cx, scope),
-                                       native, aIID, vp, aHolder);
+  nsCOMPtr<nsIXPConnectJSObjectHolder> holder;
+  nsresult rv = sXPConnect->WrapNative(cx, ::JS_GetGlobalForObject(cx, scope),
+                                       native, aIID, getter_AddRefs(holder));
+  NS_ENSURE_SUCCESS(rv, rv);
+
+  JSObject* obj = nsnull;
+  rv = holder->GetJSObject(&obj);
+  NS_ENSURE_SUCCESS(rv, rv);
+
+  *vp = OBJECT_TO_JSVAL(obj);
+  holder.swap(*aHolder);
+
+  return rv;
 }
 
 // static
 nsresult
 nsDOMClassInfo::ThrowJSException(JSContext *cx, nsresult aResult)
 {
   JSAutoRequest ar(cx);
 
@@ -7708,17 +7719,19 @@ nsArraySH::GetProperty(nsIXPConnectWrapp
 
     // Make sure rv == NS_OK here, so GetItemAt implementations that never fail
     // don't have to set rv.
     rv = NS_OK;
     nsISupports* array_item = GetItemAt(wrapper->Native(), n, &rv);
     NS_ENSURE_SUCCESS(rv, rv);
 
     if (array_item) {
-      rv = WrapNative(cx, obj, array_item, NS_GET_IID(nsISupports), vp);
+      nsCOMPtr<nsIXPConnectJSObjectHolder> holder;
+      rv = WrapNative(cx, obj, array_item, NS_GET_IID(nsISupports), vp,
+                      getter_AddRefs(holder));
       NS_ENSURE_SUCCESS(rv, rv);
 
       rv = NS_SUCCESS_I_DID_SOMETHING;
     }
   }
 
   return rv;
 }
@@ -7843,17 +7856,19 @@ nsNamedArraySH::GetProperty(nsIXPConnect
 {
   if (JSVAL_IS_STRING(id) && !ObjectIsNativeWrapper(cx, obj)) {
     nsresult rv = NS_OK;
     nsISupports* item = GetNamedItem(wrapper->Native(), nsDependentJSString(id),
                                      &rv);
     NS_ENSURE_SUCCESS(rv, rv);
 
     if (item) {
-      rv = WrapNative(cx, obj, item, NS_GET_IID(nsISupports), vp);
+      nsCOMPtr<nsIXPConnectJSObjectHolder> holder;
+      rv = WrapNative(cx, obj, item, NS_GET_IID(nsISupports), vp,
+                      getter_AddRefs(holder));
       NS_ENSURE_SUCCESS(rv, rv);
 
       rv = NS_SUCCESS_I_DID_SOMETHING;
     }
 
     // Don't fall through to nsArraySH::GetProperty() here
     return rv;
   }
@@ -8488,17 +8503,19 @@ nsHTMLDocumentSH::DocumentAllGetProperty
 
     nsCOMPtr<nsIDOMNode> node;
     nodeList->Item(JSVAL_TO_INT(id), getter_AddRefs(node));
 
     result = node;
   }
 
   if (result) {
-    rv = WrapNative(cx, obj, result, NS_GET_IID(nsISupports), vp);
+    nsCOMPtr<nsIXPConnectJSObjectHolder> holder;
+    rv = nsDOMClassInfo::WrapNative(cx, obj, result, NS_GET_IID(nsISupports),
+                                    vp, getter_AddRefs(holder));
     if (NS_FAILED(rv)) {
       nsDOMClassInfo::ThrowJSException(cx, rv);
 
       return JS_FALSE;
     }
   } else {
     *vp = JSVAL_VOID;
   }
@@ -8920,17 +8937,19 @@ nsHTMLDocumentSH::GetProperty(nsIXPConne
     nsCOMPtr<nsISupports> result;
 
     JSAutoRequest ar(cx);
 
     nsresult rv = ResolveImpl(cx, wrapper, id, getter_AddRefs(result));
     NS_ENSURE_SUCCESS(rv, rv);
 
     if (result) {
-      rv = WrapNative(cx, obj, result, NS_GET_IID(nsISupports), vp);
+      nsCOMPtr<nsIXPConnectJSObjectHolder> holder;
+      rv = WrapNative(cx, obj, result, NS_GET_IID(nsISupports), vp,
+                      getter_AddRefs(holder));
       if (NS_SUCCEEDED(rv)) {
         rv = NS_SUCCESS_I_DID_SOMETHING;
       }
       return rv;
     }
   }
 
   return nsDocumentSH::GetProperty(wrapper, cx, obj, id, vp, _retval);
@@ -9060,29 +9079,33 @@ nsHTMLFormElementSH::GetProperty(nsIXPCo
       nsCOMPtr<nsISupports> result;
 
       JSString *str = JSVAL_TO_STRING(id);
       FindNamedItem(form, str, getter_AddRefs(result));
 
       if (result) {
         // Wrap result, result can be either an element or a list of
         // elements
-        nsresult rv = WrapNative(cx, obj, result, NS_GET_IID(nsISupports), vp);
+        nsCOMPtr<nsIXPConnectJSObjectHolder> holder;
+        nsresult rv = WrapNative(cx, obj, result, NS_GET_IID(nsISupports), vp,
+                                 getter_AddRefs(holder));
         return NS_FAILED(rv) ? rv : NS_SUCCESS_I_DID_SOMETHING;
       }
     }
   } else {
     PRInt32 n = GetArrayIndexFromId(cx, id);
 
     if (n >= 0) {
       nsCOMPtr<nsIFormControl> control;
       form->GetElementAt(n, getter_AddRefs(control));
 
       if (control) {
-        nsresult rv = WrapNative(cx, obj, control, NS_GET_IID(nsISupports), vp);
+        nsCOMPtr<nsIXPConnectJSObjectHolder> holder;
+        nsresult rv = WrapNative(cx, obj, control, NS_GET_IID(nsISupports), vp,
+                                 getter_AddRefs(holder));
         return NS_FAILED(rv) ? rv : NS_SUCCESS_I_DID_SOMETHING;
       }
     }
   }
 
   return nsHTMLElementSH::GetProperty(wrapper, cx, obj, id, vp, _retval);;
 }
 
@@ -9179,17 +9202,19 @@ nsHTMLSelectElementSH::GetProperty(nsIXP
     nsCOMPtr<nsIDOMHTMLOptionsCollection> options;
     s->GetOptions(getter_AddRefs(options));
 
     if (options) {
       nsCOMPtr<nsIDOMNode> node;
 
       options->Item(n, getter_AddRefs(node));
 
-      rv = WrapNative(cx, obj, node, NS_GET_IID(nsIDOMNode), vp);
+      nsCOMPtr<nsIXPConnectJSObjectHolder> holder;
+      rv = WrapNative(cx, obj, node, NS_GET_IID(nsIDOMNode), vp,
+                      getter_AddRefs(holder));
       if (NS_SUCCEEDED(rv)) {
         rv = NS_SUCCESS_I_DID_SOMETHING;
       }
       return rv;
     }
   }
 
   return nsHTMLElementSH::GetProperty(wrapper, cx, obj, id, vp, _retval);;
--- a/dom/src/base/nsDOMClassInfo.h
+++ b/dom/src/base/nsDOMClassInfo.h
@@ -127,19 +127,19 @@ public:
   static nsIClassInfo *doCreate(nsDOMClassInfoData* aData)
   {
     return new nsDOMClassInfo(aData);
   }
 
   static nsresult WrapNative(JSContext *cx, JSObject *scope,
                              nsISupports *native, const nsIID& aIID,
                              jsval *vp,
-                             // If non-null aHolder will keep the jsval alive
-                             // while there's a ref to it
-                             nsIXPConnectJSObjectHolder** aHolder = nsnull);
+                             // aHolder keeps the jsval alive while
+                             // there's a ref to it
+                             nsIXPConnectJSObjectHolder** aHolder);
   static nsresult ThrowJSException(JSContext *cx, nsresult aResult);
 
   static nsresult InitDOMJSClass(JSContext *cx, JSObject *obj);
 
   static JSClass sDOMJSClass;
 
   /**
    * Get our JSClass pointer for the XPCNativeWrapper class