From 567673e3cf79ced3eb9f62130f8facc0cf36a087 Mon Sep 17 00:00:00 2001 From: "mrbkap%gmail.com" Date: Tue, 17 Mar 2009 21:42:09 +0000 Subject: [PATCH] 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 a=dveditz git-svn-id: svn://10.0.0.236/trunk@256562 18797224-902f-48f8-a5cc-f745e15eee43 --- mozilla/js/src/xpconnect/src/XPCNativeWrapper.cpp | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/mozilla/js/src/xpconnect/src/XPCNativeWrapper.cpp b/mozilla/js/src/xpconnect/src/XPCNativeWrapper.cpp index a82137612e7..fbaa263ccbe 100644 --- a/mozilla/js/src/xpconnect/src/XPCNativeWrapper.cpp +++ b/mozilla/js/src/xpconnect/src/XPCNativeWrapper.cpp @@ -807,7 +807,13 @@ XPCNativeWrapperCtor(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, 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);