Bug 683802 - Remove XPC_JSArgumentFormatter and friends. r=mrbkap
authorBobby Holley <bobbyholley@gmail.com>
Sun, 25 Sep 2011 15:38:01 +0100
changeset 77536 95701554f3480e562c62b22ef4b0a122006b0ade
parent 77535 04dc934f61d5b15d53af6f95a9f2430f21de0ed7
child 77537 44d1fafa07d0ae0d3f4f0ee212ab060ab5b35d16
push id3
push userfelipc@gmail.com
push dateFri, 30 Sep 2011 20:09:13 +0000
reviewersmrbkap
bugs683802
milestone9.0a1
Bug 683802 - Remove XPC_JSArgumentFormatter and friends. r=mrbkap XPC_JSArgumentFormatter adds 3 special format string tokens to spidermonkey: %ip, %iv, and %is. These were unused outside of testing according to a free-text MXR search, and don't appear to be well-documented anywhere either. They also happen to be quite dangerous and easy to use improperly: we pass untyped variadic parameters to XPCConvert::JSData2Native with useAllocator==false. This causes JSData2Native to blindly cast the values to concrete class pointers (like nsAString*) and call methods on them.
js/src/xpconnect/src/xpccontext.cpp
js/src/xpconnect/src/xpcconvert.cpp
js/src/xpconnect/src/xpcprivate.h
--- a/js/src/xpconnect/src/xpccontext.cpp
+++ b/js/src/xpconnect/src/xpccontext.cpp
@@ -53,18 +53,16 @@ XPCContext::XPCContext(XPCJSRuntime* aRu
         mSecurityManager(nsnull),
         mException(nsnull),
         mCallingLangType(LANG_UNKNOWN),
         mSecurityManagerFlags(0)
 {
     MOZ_COUNT_CTOR(XPCContext);
 
     PR_INIT_CLIST(&mScopes);
-    for(const char** p =  XPC_ARG_FORMATTER_FORMAT_STRINGS; *p; p++)
-        JS_AddArgumentFormatter(mJSContext, *p, XPC_JSArgumentFormatter);
 
     NS_ASSERTION(!mJSContext->data2, "Must be null");
     mJSContext->data2 = this;
 }
 
 XPCContext::~XPCContext()
 {
     MOZ_COUNT_DTOR(XPCContext);
--- a/js/src/xpconnect/src/xpcconvert.cpp
+++ b/js/src/xpconnect/src/xpcconvert.cpp
@@ -1834,117 +1834,16 @@ XPCConvert::JSErrorToXPCException(XPCCal
     {
         rv = ConstructException(NS_ERROR_XPC_JAVASCRIPT_ERROR,
                                 nsnull, ifaceName, methodName, nsnull,
                                 exceptn, nsnull, nsnull);
     }
     return rv;
 }
 
-
-/***************************************************************************/
-
-/*
-** Note: on some platforms va_list is defined as an array,
-** and requires array notation.
-*/
-#ifdef HAVE_VA_COPY
-#define VARARGS_ASSIGN(foo, bar)	VA_COPY(foo,bar)
-#elif defined(HAVE_VA_LIST_AS_ARRAY)
-#define VARARGS_ASSIGN(foo, bar)	foo[0] = bar[0]
-#else
-#define VARARGS_ASSIGN(foo, bar)	(foo) = (bar)
-#endif
-
-// We assert below that these formats all begin with "%i".
-const char* XPC_ARG_FORMATTER_FORMAT_STRINGS[] = {"%ip", "%iv", "%is", nsnull};
-
-JSBool
-XPC_JSArgumentFormatter(JSContext *cx, const char *format,
-                        JSBool fromJS, jsval **vpp, va_list *app)
-{
-    XPCCallContext ccx(NATIVE_CALLER, cx);
-    if(!ccx.IsValid())
-        return JS_FALSE;
-
-    jsval *vp;
-    va_list ap;
-
-    vp = *vpp;
-    VARARGS_ASSIGN(ap, *app);
-
-    nsXPTType type;
-    const nsIID* iid;
-    void* p;
-
-    NS_ASSERTION(format[0] == '%' && format[1] == 'i', "bad format!");
-    char which = format[2];
-
-    if(fromJS)
-    {
-        switch(which)
-        {
-            case 'p':
-                type = nsXPTType((uint8)(TD_INTERFACE_TYPE | XPT_TDP_POINTER));                
-                iid = &NS_GET_IID(nsISupports);
-                break;
-            case 'v':
-                type = nsXPTType((uint8)(TD_INTERFACE_TYPE | XPT_TDP_POINTER));                
-                iid = &NS_GET_IID(nsIVariant);
-                break;
-            case 's':
-                type = nsXPTType((uint8)(TD_DOMSTRING | XPT_TDP_POINTER));                
-                iid = nsnull;
-                p = va_arg(ap, void *);
-                break;
-            default:
-                NS_ERROR("bad format!");
-                return JS_FALSE;
-        }
-
-        if(!XPCConvert::JSData2Native(ccx, &p, vp[0], type, JS_FALSE,
-                                      iid, nsnull))
-            return JS_FALSE;
-        
-        if(which != 's')
-            *va_arg(ap, void **) = p;
-    }
-    else
-    {
-        switch(which)
-        {
-            case 'p':
-                type = nsXPTType((uint8)(TD_INTERFACE_TYPE | XPT_TDP_POINTER));                
-                iid  = va_arg(ap, const nsIID*);
-                break;
-            case 'v':
-                type = nsXPTType((uint8)(TD_INTERFACE_TYPE | XPT_TDP_POINTER));                
-                iid = &NS_GET_IID(nsIVariant);
-                break;
-            case 's':
-                type = nsXPTType((uint8)(TD_DOMSTRING | XPT_TDP_POINTER));                
-                iid = nsnull;
-                break;
-            default:
-                NS_ERROR("bad format!");
-                return JS_FALSE;
-        }
-
-        // NOTE: MUST be retrieved *after* the iid in the 'p' case above.
-        p = va_arg(ap, void *);
-
-        ccx.SetScopeForNewJSObjects(JS_GetGlobalForScopeChain(cx));
-        if(!XPCConvert::NativeData2JS(ccx, &vp[0], &p, type, iid, nsnull))
-            return JS_FALSE;
-    }
-    *vpp = vp + 1;
-    VARARGS_ASSIGN(*app, ap);
-    return JS_TRUE;
-}
-
 /***************************************************************************/
 
 // array fun...
 
 #ifdef POPULATE
 #undef POPULATE
 #endif
 
--- a/js/src/xpconnect/src/xpcprivate.h
+++ b/js/src/xpconnect/src/xpcprivate.h
@@ -218,17 +218,16 @@ void DEBUG_CheckWrapperThreadSafety(cons
 #define XPC_NATIVE_SET_MAP_SIZE             64
 #define XPC_NATIVE_JSCLASS_MAP_SIZE         32
 #define XPC_THIS_TRANSLATOR_MAP_SIZE         8
 #define XPC_NATIVE_WRAPPER_MAP_SIZE         16
 #define XPC_WRAPPER_MAP_SIZE                16
 
 /***************************************************************************/
 // data declarations...
-extern const char* XPC_ARG_FORMATTER_FORMAT_STRINGS[]; // format strings
 extern const char XPC_CONTEXT_STACK_CONTRACTID[];
 extern const char XPC_RUNTIME_CONTRACTID[];
 extern const char XPC_EXCEPTION_CONTRACTID[];
 extern const char XPC_CONSOLE_CONTRACTID[];
 extern const char XPC_SCRIPT_ERROR_CONTRACTID[];
 extern const char XPC_ID_CONTRACTID[];
 extern const char XPC_XPCONNECT_CONTRACTID[];
 
@@ -3360,21 +3359,16 @@ public:
                                  nsStringBuffer** sharedBuffer);
 
     static void ShutdownDOMStringFinalizer();
 
 private:
     XPCStringConvert();         // not implemented
 };
 
-extern JSBool
-XPC_JSArgumentFormatter(JSContext *cx, const char *format,
-                        JSBool fromJS, jsval **vpp, va_list *app);
-
-
 /***************************************************************************/
 // code for throwing exceptions into JS
 
 class XPCThrower
 {
 public:
     static void Throw(nsresult rv, JSContext* cx);
     static void Throw(nsresult rv, XPCCallContext& ccx);