Bug 683802 - Add jsval to the XPTCMiniVariant union for type safety. r=mrbkap
authorBobby Holley <bobbyholley@gmail.com>
Fri, 23 Sep 2011 14:50:28 -0700
changeset 78781 5ab48d3bf0bd4ca4927916adfb73f11f5edc2f14
parent 78780 36aa31a60a664fdb3e4ce0b25c7f8e80937c68da
child 78782 90de2e5fd0ac760d70e9cb1f95bdc93c7b467e8b
push id78
push userclegnitto@mozilla.com
push dateFri, 16 Dec 2011 17:32:24 +0000
treeherdermozilla-release@79d24e644fdd [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmrbkap
bugs683802
milestone9.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 683802 - Add jsval to the XPTCMiniVariant union for type safety. r=mrbkap
js/src/xpconnect/src/xpcwrappednative.cpp
xpcom/reflect/xptcall/public/xptcall.h
--- a/js/src/xpconnect/src/xpcwrappednative.cpp
+++ b/js/src/xpconnect/src/xpcwrappednative.cpp
@@ -2843,22 +2843,19 @@ CallMethodHelper::ConvertIndependentPara
 
     if (!GetOutParamSource(i, &src))
         return JS_FALSE;
 
     // The JSVal proper is always stored within the 'val' union and passed
     // indirectly, regardless of in/out-ness.
     if(type_tag == nsXPTType::T_JSVAL)
     {
-        // Assign the value
-        JS_STATIC_ASSERT(sizeof(jsval) <= sizeof(dp->val));
-        jsval *rootp = (jsval *)&dp->val;
-        dp->ptr = rootp;
-        *rootp = JSVAL_VOID;
-        if(!JS_AddValueRoot(mCallContext, rootp))
+        // Root the value.
+        dp->val.j = JSVAL_VOID;
+        if (!JS_AddValueRoot(mCallContext, &dp->val.j))
             return JS_FALSE;
         dp->SetValIsJSRoot();
     }
 
     if(paramInfo.IsOut())
     {
         if(type.IsPointer() &&
            type_tag != nsXPTType::T_INTERFACE &&
--- a/xpcom/reflect/xptcall/public/xptcall.h
+++ b/xpcom/reflect/xptcall/public/xptcall.h
@@ -47,16 +47,17 @@
 # define NS_InvokeByIndex      NS_InvokeByIndex_P
 #endif
 
 #include "prtypes.h"
 #include "nscore.h"
 #include "nsISupports.h"
 #include "xpt_struct.h"
 #include "xptinfo.h"
+#include "jsapi.h"
 
 struct nsXPTCMiniVariant
 {
 // No ctors or dtors so that we can use arrays of these on the stack
 // with no penalty.
     union
     {
         PRInt8    i8;
@@ -68,16 +69,21 @@ struct nsXPTCMiniVariant
         PRUint32  u32;
         PRUint64  u64;
         float     f;
         double    d;
         PRBool    b;
         char      c;
         PRUnichar wc;
         void*     p;
+
+        // Types below here are unknown to the assembly implementations, and
+        // therefore _must_ be passed with indirect semantics. We put them in
+        // the union here for type safety, so that we can avoid void* tricks.
+        jsval j;
     } val;
 };
 
 struct nsXPTCVariant : public nsXPTCMiniVariant
 {
 // No ctors or dtors so that we can use arrays of these on the stack
 // with no penalty.