Prevent testapi from crashing if testapi.js can not be found by nil-checking the...
authormrowe@apple.com <mrowe@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sun, 18 Nov 2007 05:36:29 +0000 (05:36 +0000)
committermrowe@apple.com <mrowe@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sun, 18 Nov 2007 05:36:29 +0000 (05:36 +0000)
Reviewed by Sam Weinig.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@27881 268f45cc-cd09-0410-ab3c-d52691b4dbfc

JavaScriptCore/API/testapi.c
JavaScriptCore/ChangeLog

index 8c95099..6029d92 100644 (file)
@@ -809,20 +809,24 @@ int main(int argc, char* argv[])
     ASSERT(JSValueIsEqual(context, v, o, NULL));
     
     char* scriptUTF8 = createStringWithContentsOfFile("testapi.js");
-    JSStringRef script = JSStringCreateWithUTF8CString(scriptUTF8);
-    result = JSEvaluateScript(context, script, NULL, NULL, 1, &exception);
-    if (JSValueIsUndefined(context, result))
-        printf("PASS: Test script executed successfully.\n");
+    if (!scriptUTF8)
+        printf("FAIL: Test script could not be loaded.\n");
     else {
-        printf("FAIL: Test script returned unexcpected value:\n");
-        JSStringRef exceptionIString = JSValueToStringCopy(context, exception, NULL);
-        CFStringRef exceptionCF = JSStringCopyCFString(kCFAllocatorDefault, exceptionIString);
-        CFShow(exceptionCF);
-        CFRelease(exceptionCF);
-        JSStringRelease(exceptionIString);
+        JSStringRef script = JSStringCreateWithUTF8CString(scriptUTF8);
+        result = JSEvaluateScript(context, script, NULL, NULL, 1, &exception);
+        if (JSValueIsUndefined(context, result))
+            printf("PASS: Test script executed successfully.\n");
+        else {
+            printf("FAIL: Test script returned unexpected value:\n");
+            JSStringRef exceptionIString = JSValueToStringCopy(context, exception, NULL);
+            CFStringRef exceptionCF = JSStringCopyCFString(kCFAllocatorDefault, exceptionIString);
+            CFShow(exceptionCF);
+            CFRelease(exceptionCF);
+            JSStringRelease(exceptionIString);
+        }
+        JSStringRelease(script);
+        free(scriptUTF8);
     }
-    JSStringRelease(script);
-    free(scriptUTF8);
 
     JSStringRelease(jsEmptyIString);
     JSStringRelease(jsOneIString);
index 67bed17..8e49d56 100644 (file)
@@ -1,3 +1,12 @@
+2007-11-17  Mark Rowe  <mrowe@apple.com>
+
+        Reviewed by Sam Weinig.
+
+        Prevent testapi from crashing if testapi.js can not be found by nil-checking the result of createStringWithContentsOfFile.
+
+        * API/testapi.c:
+        (main):
+
 2007-11-17  Alp Toker  <alp@atoker.com>
 
         Reviewed by Eric.