Bug 809674 - Fail at call time when invoking an XPCWrappedJS method with [implicit_jscontext] or [optional_argc]. r=mrbkap
☠☠ backed out by d56d537a1843 ☠ ☠
authorBobby Holley <bobbyholley@gmail.com>
Mon, 12 Nov 2012 16:17:24 -0800
changeset 113038 bcb591d32bd65872c8ed7fe46fdbc4a3d6467f89
parent 113037 9d13fb8bd7f5187a0d76380d619e56e45d2e69e4
child 113039 3de447b1c39655778504203e2b3e8547b726d199
push id23848
push useremorley@mozilla.com
push dateTue, 13 Nov 2012 16:29:34 +0000
treeherdermozilla-central@d56d537a1843 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmrbkap
bugs809674
milestone19.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 809674 - Fail at call time when invoking an XPCWrappedJS method with [implicit_jscontext] or [optional_argc]. r=mrbkap I think this is the path of least resistance here.
js/xpconnect/src/XPCWrappedJSClass.cpp
--- a/js/xpconnect/src/XPCWrappedJSClass.cpp
+++ b/js/xpconnect/src/XPCWrappedJSClass.cpp
@@ -1108,27 +1108,28 @@ nsXPCWrappedJSClass::CheckForException(X
             return pending_result;
         }
     }
     return NS_ERROR_FAILURE;
 }
 
 NS_IMETHODIMP
 nsXPCWrappedJSClass::CallMethod(nsXPCWrappedJS* wrapper, uint16_t methodIndex,
-                                const XPTMethodDescriptor* info,
+                                const XPTMethodDescriptor* info_,
                                 nsXPTCMiniVariant* nativeParams)
 {
     jsval* sp = nullptr;
     jsval* argv = nullptr;
     uint8_t i;
     nsresult retval = NS_ERROR_FAILURE;
     nsresult pending_result = NS_OK;
     JSBool success;
     JSBool readyToDoTheCall = false;
     nsID  param_iid;
+    const nsXPTMethodInfo* info = static_cast<const nsXPTMethodInfo*>(info_);
     const char* name = info->name;
     jsval fval;
     JSBool foundDependentParam;
 
     // Make sure not to set the callee on ccx until after we've gone through
     // the whole nsIXPCFunctionThisTranslator bit.  That code uses ccx to
     // convert natives to JSObjects, but we do NOT plan to pass those JSObjects
     // to our real callee.
@@ -1138,16 +1139,27 @@ nsXPCWrappedJSClass::CallMethod(nsXPCWra
         return retval;
 
     XPCContext *xpcc = ccx.GetXPCContext();
     JSContext *cx = xpc_UnmarkGrayContext(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;
+    }
+
     JSObject *obj = wrapper->GetJSObject();
     JSObject *thisObj = obj;
 
     JSAutoCompartment ac(cx, obj);
     ccx.SetScopeForNewJSObjects(obj);
 
     JS::AutoValueVector args(cx);
     AutoScriptEvaluate scriptEval(cx);