Don't swallow errors in FindTearOff (bug 612225, r=gal).
authorLuke Wagner <lw@mozilla.com>
Fri, 07 Jan 2011 02:15:14 -0800
changeset 60212 daaf6a3b8782d1a17ecfe5556c576651f71f7130
parent 60211 e051f5f4c46a902f893c84485706b197accd6c1b
child 60213 220ced5ad4fb7452861bb48f9214edd4df7a6e7a
push id17881
push usercleary@mozilla.com
push dateFri, 07 Jan 2011 19:57:21 +0000
treeherdermozilla-central@54576be62860 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersgal
bugs612225
milestone2.0b9pre
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
Don't swallow errors in FindTearOff (bug 612225, r=gal).
js/src/xpconnect/src/xpcjsid.cpp
js/src/xpconnect/src/xpcwrappednative.cpp
js/src/xpconnect/src/xpcwrappednativejsops.cpp
--- a/js/src/xpconnect/src/xpcjsid.cpp
+++ b/js/src/xpconnect/src/xpcjsid.cpp
@@ -546,18 +546,21 @@ nsJSIID::HasInstance(nsIXPConnectWrapped
         }
 
         // Otherwise, we'll end up Querying the native object to be sure.
         XPCCallContext ccx(JS_CALLER, cx);
 
         AutoMarkingNativeInterfacePtr iface(ccx);
         iface = XPCNativeInterface::GetNewOrUsed(ccx, iid);
 
-        if(iface && other_wrapper->FindTearOff(ccx, iface))
+        nsresult findResult = NS_OK;
+        if(iface && other_wrapper->FindTearOff(ccx, iface, JS_FALSE, &findResult))
             *bp = JS_TRUE;
+        if (NS_FAILED(findResult) && findResult != NS_ERROR_NO_INTERFACE)
+            rv = findResult;
     }
     return rv;
 }
 
 #ifdef XPC_USE_SECURITY_CHECKED_COMPONENT
 /* string canCreateWrapper (in nsIIDPtr iid); */
 NS_IMETHODIMP
 nsJSIID::CanCreateWrapper(const nsIID * iid, char **_retval)
--- a/js/src/xpconnect/src/xpcwrappednative.cpp
+++ b/js/src/xpconnect/src/xpcwrappednative.cpp
@@ -1846,24 +1846,26 @@ XPCWrappedNative::FindTearOff(XPCCallCon
             to < end; 
             to++)
         {
             if(to->GetInterface() == aInterface)
             {
                 if(needJSObject && !to->GetJSObject())
                 {
                     AutoMarkingWrappedNativeTearOffPtr tearoff(ccx, to);
-                    rv = InitTearOffJSObject(ccx, to);
+                    JSBool ok = InitTearOffJSObject(ccx, to);
                     // During shutdown, we don't sweep tearoffs.  So make sure
                     // to unmark manually in case the auto-marker marked us.
                     // We shouldn't ever be getting here _during_ our
                     // Mark/Sweep cycle, so this should be safe.
                     to->Unmark();
-                    if(NS_FAILED(rv))
+                    if(!ok) {
                         to = nsnull;
+                        rv = NS_ERROR_OUT_OF_MEMORY;
+                    }
                 }
                 goto return_result;
             }
             if(!firstAvailable && to->IsAvailable())
                 firstAvailable = to;
         }
     }
 
--- a/js/src/xpconnect/src/xpcwrappednativejsops.cpp
+++ b/js/src/xpconnect/src/xpcwrappednativejsops.cpp
@@ -343,32 +343,37 @@ DefinePropertyIfFound(XPCCallContext& cc
         // interface and add a tearoff as necessary.
 
         if(wrapperToReflectInterfaceNames)
         {
             JSAutoByteString name;
             AutoMarkingNativeInterfacePtr iface2(ccx);
             XPCWrappedNativeTearOff* to;
             JSObject* jso;
+            nsresult rv = NS_OK;
 
             if(JSID_IS_STRING(id) &&
                name.encode(ccx, JSID_TO_STRING(id)) &&
                (iface2 = XPCNativeInterface::GetNewOrUsed(ccx, name.ptr()), iface2) &&
                nsnull != (to = wrapperToReflectInterfaceNames->
-                                    FindTearOff(ccx, iface2, JS_TRUE)) &&
+                                    FindTearOff(ccx, iface2, JS_TRUE, &rv)) &&
                nsnull != (jso = to->GetJSObject()))
 
             {
                 AutoResolveName arn(ccx, id);
                 if(resolved)
                     *resolved = JS_TRUE;
                 return JS_DefinePropertyById(ccx, obj, id, OBJECT_TO_JSVAL(jso),
                                              nsnull, nsnull,
                                              propFlags & ~JSPROP_ENUMERATE);
             }
+            else if(NS_FAILED(rv) && rv != NS_ERROR_NO_INTERFACE)
+            {
+                return Throw(rv, ccx);
+            }
         }
 
         // This *might* be a double wrapped JSObject
         if(wrapperToReflectDoubleWrap &&
            id == rt->GetStringID(XPCJSRuntime::IDX_WRAPPED_JSOBJECT) &&
            GetDoubleWrappedJSObject(ccx, wrapperToReflectDoubleWrap))
         {
             // We build and add a getter function.