Fix for bug 471395 ( "Illegal Value" exception when accessing XHR request within an extension). r=mrbkap, sr=jst.
authorPeter Van der Beken <peterv@propagandism.org>
Tue, 24 Feb 2009 17:44:31 +0100
changeset 23422 9ae1b088d9e4652cf9eeb798484ff31c6bbf820d
parent 23421 03324648db5415fc6151fa301598cd608e666f98
child 23423 5ee71b8d3cdbaf421a0e0f9bd0bacee2d2590704
push id766
push userpvanderbeken@mozilla.com
push dateWed, 25 Feb 2009 10:30:35 +0000
reviewersmrbkap, jst
bugs471395
milestone1.9.1b3pre
Fix for bug 471395 ( "Illegal Value" exception when accessing XHR request within an extension). r=mrbkap, sr=jst.
js/src/xpconnect/src/XPCNativeWrapper.cpp
--- a/js/src/xpconnect/src/XPCNativeWrapper.cpp
+++ b/js/src/xpconnect/src/XPCNativeWrapper.cpp
@@ -1193,17 +1193,26 @@ XPCNativeWrapper::GetNewOrUsed(JSContext
     }
   }
 
   // Prevent wrapping a double-wrapped JS object in an
   // XPCNativeWrapper!
   nsCOMPtr<nsIXPConnectWrappedJS> xpcwrappedjs(do_QueryWrappedNative(wrapper));
 
   if (xpcwrappedjs) {
-    XPCThrower::Throw(NS_ERROR_INVALID_ARG, cx);
+    JSObject *flat = wrapper->GetFlatJSObject();
+    jsval v = OBJECT_TO_JSVAL(flat);
+
+    XPCCallContext ccx(JS_CALLER, cx);
+
+    // Make sure v doesn't get collected while we're re-wrapping it.
+    AUTO_MARK_JSVAL(ccx, v);
+
+    if (XPC_SJOW_Construct(cx, nsnull, 1, &v, &v))
+        return JSVAL_TO_OBJECT(v);
 
     return nsnull;
   }
 
   JSObject *obj = wrapper->GetWrapper();
   if (obj) {
     return obj;
   }