From f1c331f2c5b5df607edb581cf7711b7f40d2fb09 Mon Sep 17 00:00:00 2001 From: Eric Wing Date: Mon, 19 May 2014 17:42:00 -0700 Subject: [PATCH] JavaScriptCore: Returning NULL for wrapper functions that expect JSValueRef may crash program. According to this: http://parmanoir.com/Taming_JavascriptCore_within_and_without_WebView Returning NULL instead of an actual JSValueRef for a return value of a function could lead to crashes. I think I have seen related weirdness in the past when I failed to return a proper type to JSCore which resulted in very hard to understand behavior. So this patch changes those return NULLs to return JSValueMakeUndefined(). I thought about JSObjectMakeError, but I don't fully understand the intent of the Error object and can't find any relevant real world examples of it being used. However, everybody seems to be using JSValueMakeUndefined(). This patch should be low impact since this is only triggered on an error condition. --- Lib/javascript/jsc/javascriptcode.swg | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/Lib/javascript/jsc/javascriptcode.swg b/Lib/javascript/jsc/javascriptcode.swg index 3fe9d49e9..f8c5a200f 100644 --- a/Lib/javascript/jsc/javascriptcode.swg +++ b/Lib/javascript/jsc/javascriptcode.swg @@ -17,7 +17,7 @@ static JSObjectRef $jswrapper(JSContextRef context, JSObjectRef thisObject, size return SWIG_JSC_NewPointerObj(context, result, SWIGTYPE_$jsmangledtype, SWIG_POINTER_OWN); goto fail; fail: - return NULL; + return JSValueMakeUndefined(context); } %} @@ -78,7 +78,7 @@ static JSObjectRef $jswrapper(JSContextRef context, JSObjectRef thisObject, size goto fail; fail: - return NULL; + return JSValueMakeUndefined(context); } %} @@ -159,7 +159,7 @@ static JSValueRef $jswrapper(JSContextRef context, JSObjectRef thisObject, JSStr goto fail; fail: - return NULL; + return JSValueMakeUndefined(context); } %} @@ -204,7 +204,7 @@ static JSValueRef $jswrapper(JSContextRef context, JSObjectRef function, JSObjec goto fail; fail: - return NULL; + return JSValueMakeUndefined(context); } %} @@ -229,7 +229,7 @@ static JSValueRef $jswrapper(JSContextRef context, JSObjectRef function, JSObjec goto fail; fail: - return NULL; + return JSValueMakeUndefined(context); } %}