Backed out changeset 91885eced736 (bug 983989)
authorEd Morley <emorley@mozilla.com>
Thu, 10 Apr 2014 15:48:08 +0100
changeset 178008 a564815d922aa840ad3be5630855384ca57f140a
parent 178007 6aa22b66e4a7394e7cdeb2351cef17f78f2d259f
child 178009 7702bc193de211f1057a2629bb55d4ae007fe1ef
push id26569
push userryanvm@gmail.com
push dateFri, 11 Apr 2014 04:11:36 +0000
treeherdermozilla-central@783c5013dbec [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
bugs983989
milestone31.0a1
backs out91885eced7366abaeb50933aff8753325d9327c4
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
Backed out changeset 91885eced736 (bug 983989)
js/xpconnect/src/XPCConvert.cpp
--- a/js/xpconnect/src/XPCConvert.cpp
+++ b/js/xpconnect/src/XPCConvert.cpp
@@ -100,179 +100,160 @@ XPCConvert::NativeData2JS(MutableHandleV
 {
     NS_PRECONDITION(s, "bad param");
 
     AutoJSContext cx;
     if (pErr)
         *pErr = NS_ERROR_XPC_BAD_CONVERT_NATIVE;
 
     switch (type.TagPart()) {
-    case nsXPTType::T_I8    :
-        d.setInt32(*((int8_t*)s));
-        return true;
-    case nsXPTType::T_I16   :
-        d.setInt32(*((int16_t*)s));
-        return true;
-    case nsXPTType::T_I32   :
-        d.setInt32(*((int32_t*)s));
-        return true;
-    case nsXPTType::T_I64   :
-        d.setNumber(double(*((int64_t*)s)));
-        return true;
-    case nsXPTType::T_U8    :
-        d.setInt32(*((uint8_t*)s));
-        return true;
-    case nsXPTType::T_U16   :
-        d.setInt32(*((uint16_t*)s));
-        return true;
-    case nsXPTType::T_U32   :
-        d.setNumber(*((uint32_t*)s));
-        return true;
-    case nsXPTType::T_U64   :
-        d.setNumber(double(*((uint64_t*)s)));
-        return true;
-    case nsXPTType::T_FLOAT :
-        d.setNumber(*((float*)s));
-        return true;
-    case nsXPTType::T_DOUBLE:
-        d.setNumber(*((double*)s));
-        return true;
+    case nsXPTType::T_I8    : d.setInt32(*((int8_t*)s));             break;
+    case nsXPTType::T_I16   : d.setInt32(*((int16_t*)s));            break;
+    case nsXPTType::T_I32   : d.setInt32(*((int32_t*)s));            break;
+    case nsXPTType::T_I64   : d.setNumber(double(*((int64_t*)s)));   break;
+    case nsXPTType::T_U8    : d.setInt32(*((uint8_t*)s));            break;
+    case nsXPTType::T_U16   : d.setInt32(*((uint16_t*)s));           break;
+    case nsXPTType::T_U32   : d.setNumber(*((uint32_t*)s));          break;
+    case nsXPTType::T_U64   : d.setNumber(double(*((uint64_t*)s)));  break;
+    case nsXPTType::T_FLOAT : d.setNumber(*((float*)s));             break;
+    case nsXPTType::T_DOUBLE: d.setNumber(*((double*)s));            break;
     case nsXPTType::T_BOOL  :
     {
         bool b = *((bool*)s);
 
         NS_WARN_IF_FALSE(b == 1 || b == 0,
                          "Passing a malformed bool through XPConnect");
         d.setBoolean(b);
-        return true;
+        break;
     }
     case nsXPTType::T_CHAR  :
     {
         char* p = (char*)s;
         if (!p)
             return false;
 
 #ifdef STRICT_CHECK_OF_UNICODE
         MOZ_ASSERT(! ILLEGAL_CHAR_RANGE(p) , "passing non ASCII data");
 #endif // STRICT_CHECK_OF_UNICODE
 
         JSString* str;
         if (!(str = JS_NewStringCopyN(cx, p, 1)))
             return false;
         d.setString(str);
-        return true;
+        break;
     }
     case nsXPTType::T_WCHAR :
     {
         jschar* p = (jschar*)s;
         if (!p)
             return false;
         JSString* str;
         if (!(str = JS_NewUCStringCopyN(cx, p, 1)))
             return false;
         d.setString(str);
-        return true;
+        break;
     }
 
     case nsXPTType::T_JSVAL :
     {
         d.set(*((Value*)s));
         if (!JS_WrapValue(cx, d))
             return false;
-        return true;
+        break;
     }
 
+    default:
+
+    // set the default result
+    d.setNull();
+
+    switch (type.TagPart()) {
     case nsXPTType::T_VOID:
         XPC_LOG_ERROR(("XPCConvert::NativeData2JS : void* params not supported"));
         return false;
 
     case nsXPTType::T_IID:
     {
         nsID* iid2 = *((nsID**)s);
-        if (!iid2) {
-            d.setNull();
-            return true;
-        }
+        if (!iid2)
+            break;
         RootedObject scope(cx, JS::CurrentGlobalOrNull(cx));
         JSObject* obj;
         if (!(obj = xpc_NewIDObject(cx, scope, *iid2)))
             return false;
         d.setObject(*obj);
-        return true;
+        break;
     }
 
     case nsXPTType::T_ASTRING:
         // Fall through to T_DOMSTRING case
 
     case nsXPTType::T_DOMSTRING:
     {
         const nsAString* p = *((const nsAString**)s);
-        if (!p || p->IsVoid()) {
-            d.setNull();
-            return true;
+        if (!p)
+            break;
+
+        if (!p->IsVoid()) {
+            nsStringBuffer* buf;
+            if (!XPCStringConvert::ReadableToJSVal(cx, *p, &buf, d))
+                return false;
+            if (buf)
+                buf->AddRef();
         }
 
-        nsStringBuffer* buf;
-        if (!XPCStringConvert::ReadableToJSVal(cx, *p, &buf, d))
-            return false;
-        if (buf)
-            buf->AddRef();
-        return true;
+        // *d is defaulted to JSVAL_NULL so no need to set it
+        // again if p is a "void" string
+        MOZ_ASSERT_IF(p->IsVoid(), d.isNull());
+        break;
     }
 
     case nsXPTType::T_CHAR_STR:
     {
         char* p = *((char**)s);
-        if (!p) {
-            d.setNull();
-            return true;
-        }
+        if (!p)
+            break;
 
 #ifdef STRICT_CHECK_OF_UNICODE
         bool isAscii = true;
         char* t;
         for (t=p; *t && isAscii ; t++) {
           if (ILLEGAL_CHAR_RANGE(*t))
               isAscii = false;
         }
         MOZ_ASSERT(isAscii, "passing non ASCII data");
 #endif // STRICT_CHECK_OF_UNICODE
         JSString* str;
         if (!(str = JS_NewStringCopyZ(cx, p)))
             return false;
         d.setString(str);
-        return true;
+        break;
     }
 
     case nsXPTType::T_WCHAR_STR:
     {
         jschar* p = *((jschar**)s);
-        if (!p) {
-            d.setNull();
-            return true;
-        }
-
+        if (!p)
+            break;
         JSString* str;
         if (!(str = JS_NewUCStringCopyZ(cx, p)))
             return false;
         d.setString(str);
-        return true;
+        break;
     }
     case nsXPTType::T_UTF8STRING:
     {
         const nsACString* utf8String = *((const nsACString**)s);
 
-        if (!utf8String || utf8String->IsVoid()) {
-            d.setNull();
-            return true;
-        }
+        if (!utf8String || utf8String->IsVoid())
+            break;
 
         if (utf8String->IsEmpty()) {
             d.set(JS_GetEmptyStringValue(cx));
-            return true;
+            break;
         }
 
         const uint32_t len = CalcUTF8ToUnicodeLength(*utf8String);
         // The cString is not empty at this point, but the calculated
         // UTF-16 length is zero, meaning no valid conversion exists.
         if (!len)
             return false;
 
@@ -296,65 +277,71 @@ XPCConvert::NativeData2JS(MutableHandleV
         // to free the buffer.
         JSString* str = JS_NewUCString(cx, (jschar*)buffer, len);
         if (!str) {
             JS_free(cx, buffer);
             return false;
         }
 
         d.setString(str);
-        return true;
+        break;
     }
     case nsXPTType::T_CSTRING:
     {
         const nsACString* cString = *((const nsACString**)s);
 
-        if (!cString || cString->IsVoid()) {
-            d.setNull();
-            return true;
-        }
+        if (!cString || cString->IsVoid())
+            break;
 
         // c-strings (binary blobs) are deliberately not converted from
         // UTF-8 to UTF-16. T_UTF8Sting is for UTF-8 encoded strings
         // with automatic conversion.
         JSString* str = JS_NewStringCopyN(cx, cString->Data(),
                                           cString->Length());
         if (!str)
             return false;
 
         d.setString(str);
-        return true;
+        break;
     }
 
     case nsXPTType::T_INTERFACE:
     case nsXPTType::T_INTERFACE_IS:
     {
         nsISupports* iface = *((nsISupports**)s);
-        if (!iface) {
-            d.setNull();
-            return true;
-        }
+        if (iface) {
+            if (iid->Equals(NS_GET_IID(nsIVariant))) {
+                nsCOMPtr<nsIVariant> variant = do_QueryInterface(iface);
+                if (!variant)
+                    return false;
 
-        if (iid->Equals(NS_GET_IID(nsIVariant))) {
-            nsCOMPtr<nsIVariant> variant = do_QueryInterface(iface);
-            if (!variant)
+                return XPCVariant::VariantDataToJS(variant,
+                                                   pErr, d);
+            }
+            // else...
+            xpcObjectHelper helper(iface);
+            if (!NativeInterface2JSObject(d, nullptr, helper, iid,
+                                          nullptr, true, pErr))
                 return false;
 
-            return XPCVariant::VariantDataToJS(variant,
-                                               pErr, d);
+#ifdef DEBUG
+            JSObject* jsobj = d.toObjectOrNull();
+            if (jsobj && !js::GetObjectParent(jsobj))
+                MOZ_ASSERT(js::GetObjectClass(jsobj)->flags & JSCLASS_IS_GLOBAL,
+                           "Why did we recreate this wrapper?");
+#endif
         }
-        // else...
-        xpcObjectHelper helper(iface);
-        return NativeInterface2JSObject(d, nullptr, helper, iid, nullptr, true, pErr);
+        break;
     }
 
     default:
         NS_ERROR("bad type");
         return false;
     }
+    }
     return true;
 }
 
 /***************************************************************************/
 
 #ifdef DEBUG
 static bool
 CheckJSCharInCharRange(jschar c)