Changeset 27881 in webkit for trunk/JavaScriptCore/API


Ignore:
Timestamp:
Nov 17, 2007, 9:36:29 PM (18 years ago)
Author:
[email protected]
Message:

Prevent testapi from crashing if testapi.js can not be found by nil-checking the result of createStringWithContentsOfFile.

Reviewed by Sam Weinig.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/JavaScriptCore/API/testapi.c

    r27207 r27881  
    810810   
    811811    char* scriptUTF8 = createStringWithContentsOfFile("testapi.js");
    812     JSStringRef script = JSStringCreateWithUTF8CString(scriptUTF8);
    813     result = JSEvaluateScript(context, script, NULL, NULL, 1, &exception);
    814     if (JSValueIsUndefined(context, result))
    815         printf("PASS: Test script executed successfully.\n");
     812    if (!scriptUTF8)
     813        printf("FAIL: Test script could not be loaded.\n");
    816814    else {
    817         printf("FAIL: Test script returned unexcpected value:\n");
    818         JSStringRef exceptionIString = JSValueToStringCopy(context, exception, NULL);
    819         CFStringRef exceptionCF = JSStringCopyCFString(kCFAllocatorDefault, exceptionIString);
    820         CFShow(exceptionCF);
    821         CFRelease(exceptionCF);
    822         JSStringRelease(exceptionIString);
    823     }
    824     JSStringRelease(script);
    825     free(scriptUTF8);
     815        JSStringRef script = JSStringCreateWithUTF8CString(scriptUTF8);
     816        result = JSEvaluateScript(context, script, NULL, NULL, 1, &exception);
     817        if (JSValueIsUndefined(context, result))
     818            printf("PASS: Test script executed successfully.\n");
     819        else {
     820            printf("FAIL: Test script returned unexpected value:\n");
     821            JSStringRef exceptionIString = JSValueToStringCopy(context, exception, NULL);
     822            CFStringRef exceptionCF = JSStringCopyCFString(kCFAllocatorDefault, exceptionIString);
     823            CFShow(exceptionCF);
     824            CFRelease(exceptionCF);
     825            JSStringRelease(exceptionIString);
     826        }
     827        JSStringRelease(script);
     828        free(scriptUTF8);
     829    }
    826830
    827831    JSStringRelease(jsEmptyIString);
Note: See TracChangeset for help on using the changeset viewer.