Bug 477128 - Don't throw if XPCNativeWrapper is called as a function but passed a primitive value to allow for safe primitive testing. r+sr=jst
authorBlake Kaplan <mrbkap@gmail.com>
Tue, 10 Feb 2009 12:06:56 -0800
changeset 24834 4e892b36c3f57bf77fae370f57b9218c635868bf
parent 24833 4233c31e67d8a26f0ba0457ce16dc852bce4ffe6
child 24835 70ae20e89604399a6c65f43cc377c820c1310020
push idunknown
push userunknown
push dateunknown
bugs477128
milestone1.9.2a1pre
Bug 477128 - Don't throw if XPCNativeWrapper is called as a function but passed a primitive value to allow for safe primitive testing. r+sr=jst
js/src/xpconnect/src/XPCNativeWrapper.cpp
--- a/js/src/xpconnect/src/XPCNativeWrapper.cpp
+++ b/js/src/xpconnect/src/XPCNativeWrapper.cpp
@@ -875,17 +875,23 @@ XPCNativeWrapperCtor(JSContext *cx, JSOb
 
   // |obj| almost always has the wrong proto and parent so we have to create
   // our own object anyway.  Set |obj| to null so we don't use it by accident.
   obj = nsnull;
 
   jsval native = argv[0];
 
   if (JSVAL_IS_PRIMITIVE(native)) {
-    return ThrowException(NS_ERROR_XPC_BAD_CONVERT_JS, cx);
+    JSStackFrame *fp = nsnull;
+    if (JS_FrameIterator(cx, &fp) && JS_IsConstructorFrame(cx, fp)) {
+      return ThrowException(NS_ERROR_ILLEGAL_VALUE, cx);
+    }
+
+    *rval = native;
+    return JS_TRUE;
   }
 
   JSObject *nativeObj = JSVAL_TO_OBJECT(native);
 
   // Unwrap a cross origin wrapper, since we're more restrictive than it is.
   if (STOBJ_GET_CLASS(nativeObj) == &sXPC_XOW_JSClass.base) {
     jsval v;
     if (!::JS_GetReservedSlot(cx, nativeObj, XPCWrapper::sWrappedObjSlot, &v)) {