Bug 809674 - Fail at call time when invoking an XPCWrappedJS method with [implicit_jscontext] or [optional_argc] on esr. r=mrbkap a=akeybl
authorBobby Holley <bobbyholley@gmail.com>
Tue, 13 Nov 2012 15:13:37 -0800
changeset 82084 46a00740eb8a8165ceb7727516c63021182bd7a4
parent 82083 d51c1344f90cd61b99fd6beabef58738a915baf2
child 82085 b0b7f731ed02b5a5653ba79606369026c4f852e7
child 82088 e438eb7197d6521154ef8e91b9189a2f418ac2b6
push id336
push userbobbyholley@gmail.com
push dateTue, 13 Nov 2012 23:15:28 +0000
reviewersmrbkap, akeybl
bugs809674
milestone10.0.11esrpre
Bug 809674 - Fail at call time when invoking an XPCWrappedJS method with [implicit_jscontext] or [optional_argc] on esr. r=mrbkap a=akeybl
js/xpconnect/src/XPCWrappedJSClass.cpp
--- a/js/xpconnect/src/XPCWrappedJSClass.cpp
+++ b/js/xpconnect/src/XPCWrappedJSClass.cpp
@@ -1173,30 +1173,31 @@ class ContextPrincipalGuard
     ContextPrincipalGuard(XPCCallContext &ccx)
       : ssm(nsnull), ccx(ccx) {}
     void principalPushed(nsIScriptSecurityManager *ssm) { this->ssm = ssm; }
     ~ContextPrincipalGuard() { if (ssm) ssm->PopContextPrincipal(ccx); }
 };
 
 NS_IMETHODIMP
 nsXPCWrappedJSClass::CallMethod(nsXPCWrappedJS* wrapper, uint16 methodIndex,
-                                const XPTMethodDescriptor* info,
+                                const XPTMethodDescriptor* info_,
                                 nsXPTCMiniVariant* nativeParams)
 {
     jsval* sp = nsnull;
     jsval* argv = nsnull;
     uint8 i;
     uint8 argc=0;
     uint8 paramCount=0;
     nsresult retval = NS_ERROR_FAILURE;
     nsresult pending_result = NS_OK;
     JSBool success;
     JSBool readyToDoTheCall = JS_FALSE;
     nsID  param_iid;
     JSObject* obj;
+    const nsXPTMethodInfo* info = static_cast<const nsXPTMethodInfo*>(info_);
     const char* name = info->name;
     jsval fval;
     JSBool foundDependentParam;
     XPCContext* xpcc;
     JSContext* cx;
     JSObject* thisObj;
 
     // Make sure not to set the callee on ccx until after we've gone through
@@ -1209,16 +1210,27 @@ nsXPCWrappedJSClass::CallMethod(nsXPCWra
         return retval;
 
     xpcc = ccx.GetXPCContext();
     cx = ccx.GetJSContext();
 
     if (!cx || !xpcc || !IsReflectable(methodIndex))
         return NS_ERROR_FAILURE;
 
+    // [implicit_jscontext] and [optional_argc] have a different calling
+    // convention, which we don't support for JS-implemented components.
+    if (info->WantsOptArgc() || info->WantsContext()) {
+        const char *str = "IDL methods marked with [implicit_jscontext] "
+                          "or [optional_argc] may not be implemented in JS";
+        // Throw and warn for good measure.
+        JS_ReportError(cx, str);
+        NS_WARNING(str);
+        return NS_ERROR_FAILURE;
+    }
+
     obj = thisObj = wrapper->GetJSObject();
 
     JSAutoEnterCompartment ac;
     if (!ac.enter(cx, obj))
         return NS_ERROR_FAILURE;
 
     ccx.SetScopeForNewJSObjects(obj);