Changeset 15376 in webkit for trunk/JavaScriptCore/API/testapi.c


Ignore:
Timestamp:
Jul 12, 2006, 1:12:08 AM (19 years ago)
Author:
ggaren
Message:

Reviewed by Maciej.


  • Implemented a vast number of renames and comment clarifications suggested during API review.


JSInternalString -> JSString
JS*Make -> JSValueMake*, JSObjectMake*
JSTypeCode -> JSType
JSValueIsInstanceOf -> JSValueIsInstanceOfConstructor (reads strangely well in client code)
JSGC*Protect -> JSValue*Protect
JS*Callback -> JSObject*Callback
JSGetPropertyListCallback -> JSObjectAddPropertiesToListCallback
JSPropertyEnumeratorGetNext -> JSPropertyEnumeratorGetNextName
JSString* ->

JSStringCreateWithUTF8CString, JSStringGetUTF8CString,
JSStringGetMaximumUTF8CStringSize JSStringIsEqualToUTF8CString,
JSStringCreateWithCFString, JSStringCopyCFString, JSStringCreateWithCharacters.


  • Changed functions taking a JSValue out arg and returning a bool indicating whether it was set to simply return a JSValue or NULL.


  • Removed JSStringGetCharacters because it's more documentation than code, and it's just a glorified memcpy built on existing API functionality.


  • Moved standard library includes into the headers that actually require them.


  • Standardized use of the phrase "Create Rule."


  • Removed JSLock from make functions that don't allocate.


  • Added exception handling to JSValueToBoolean, since we now allow callback objects to throw exceptions upon converting to boolean.


  • Renamed JSGCCollect to JSGarbageCollect.
File:
1 edited

Legend:

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

    r15328 r15376  
    5252static void assertEqualsAsUTF8String(JSValueRef value, const char* expectedValue)
    5353{
    54     JSInternalStringRef valueAsString = JSValueCopyStringValue(context, value);
    55 
    56     size_t jsSize = JSInternalStringGetMaxLengthUTF8(valueAsString);
     54    JSStringRef valueAsString = JSValueToStringCopy(context, value);
     55
     56    size_t jsSize = JSStringGetMaximumUTF8CStringSize(valueAsString);
    5757    char jsBuffer[jsSize];
    58     JSInternalStringGetCharactersUTF8(valueAsString, jsBuffer, jsSize);
     58    JSStringGetUTF8CString(valueAsString, jsBuffer, jsSize);
    5959   
    6060    if (strcmp(jsBuffer, expectedValue) != 0)
     
    6464        fprintf(stderr, "assertEqualsAsUTF8String failed: jsSize was too small\n");
    6565
    66     JSInternalStringRelease(valueAsString);
     66    JSStringRelease(valueAsString);
    6767}
    6868
     
    7070static void assertEqualsAsCharactersPtr(JSValueRef value, const char* expectedValue)
    7171{
    72     JSInternalStringRef valueAsString = JSValueCopyStringValue(context, value);
    73 
    74     size_t jsLength = JSInternalStringGetLength(valueAsString);
    75     const JSChar* jsBuffer = JSInternalStringGetCharactersPtr(valueAsString);
     72    JSStringRef valueAsString = JSValueToStringCopy(context, value);
     73
     74    size_t jsLength = JSStringGetLength(valueAsString);
     75    const JSChar* jsBuffer = JSStringGetCharactersPtr(valueAsString);
    7676
    7777    CFStringRef expectedValueAsCFString = CFStringCreateWithCString(kCFAllocatorDefault,
     
    8989        fprintf(stderr, "assertEqualsAsCharactersPtr failed: jsLength(%ld) != cfLength(%ld)\n", jsLength, cfLength);
    9090   
    91     JSInternalStringRelease(valueAsString);
    92 }
    93 
    94 static void assertEqualsAsCharacters(JSValueRef value, const char* expectedValue)
    95 {
    96     JSInternalStringRef valueAsString = JSValueCopyStringValue(context, value);
    97    
    98     size_t jsLength = JSInternalStringGetLength(valueAsString);
    99     JSChar jsBuffer[jsLength];
    100     JSInternalStringGetCharacters(valueAsString, jsBuffer, jsLength);
    101    
    102     CFStringRef expectedValueAsCFString = CFStringCreateWithCString(kCFAllocatorDefault,
    103                                                                     expectedValue,
    104                                                                     kCFStringEncodingUTF8);   
    105     CFIndex cfLength = CFStringGetLength(expectedValueAsCFString);
    106     UniChar cfBuffer[cfLength];
    107     CFStringGetCharacters(expectedValueAsCFString, CFRangeMake(0, cfLength), cfBuffer);
    108     CFRelease(expectedValueAsCFString);
    109    
    110     if (memcmp(jsBuffer, cfBuffer, cfLength * sizeof(UniChar)) != 0)
    111         fprintf(stderr, "assertEqualsAsCharacters failed: jsBuffer != cfBuffer\n");
    112    
    113     if (jsLength != (size_t)cfLength)
    114         fprintf(stderr, "assertEqualsAsCharacters failed: jsLength(%ld) != cfLength(%ld)\n", jsLength, cfLength);
    115    
    116     JSInternalStringRelease(valueAsString);
    117 }
    118 #endif // __APPLE__
    119 
    120 static JSValueRef jsGlobalValue; // non-stack value for testing JSGCProtect()
     91    JSStringRelease(valueAsString);
     92}
     93
     94#endif // __APPLE__
     95
     96static JSValueRef jsGlobalValue; // non-stack value for testing JSValueProtect()
    12197
    12298/* MyObject pseudo-class */
     
    130106}
    131107
    132 static bool MyObject_hasProperty(JSContextRef context, JSObjectRef object, JSInternalStringRef propertyName, JSValueRef* exception)
    133 {
    134     UNUSED_PARAM(context);
    135     UNUSED_PARAM(object);
    136 
    137     if (JSInternalStringIsEqualUTF8(propertyName, "alwaysOne")
    138         || JSInternalStringIsEqualUTF8(propertyName, "cantFind")
    139         || JSInternalStringIsEqualUTF8(propertyName, "myPropertyName")) {
     108static bool MyObject_hasProperty(JSContextRef context, JSObjectRef object, JSStringRef propertyName, JSValueRef* exception)
     109{
     110    UNUSED_PARAM(context);
     111    UNUSED_PARAM(object);
     112
     113    if (JSStringIsEqualToUTF8CString(propertyName, "alwaysOne")
     114        || JSStringIsEqualToUTF8CString(propertyName, "cantFind")
     115        || JSStringIsEqualToUTF8CString(propertyName, "myPropertyName")) {
    140116        return true;
    141117    }
     
    144120}
    145121
    146 static bool MyObject_getProperty(JSContextRef context, JSObjectRef object, JSInternalStringRef propertyName, JSValueRef* returnValue, JSValueRef* exception)
    147 {
    148     UNUSED_PARAM(context);
    149     UNUSED_PARAM(object);
    150    
    151     if (JSInternalStringIsEqualUTF8(propertyName, "alwaysOne")) {
    152         *returnValue = JSNumberMake(1);
     122static JSValueRef MyObject_getProperty(JSContextRef context, JSObjectRef object, JSStringRef propertyName, JSValueRef* exception)
     123{
     124    UNUSED_PARAM(context);
     125    UNUSED_PARAM(object);
     126   
     127    if (JSStringIsEqualToUTF8CString(propertyName, "alwaysOne")) {
     128        return JSValueMakeNumber(1);
     129    }
     130   
     131    if (JSStringIsEqualToUTF8CString(propertyName, "myPropertyName")) {
     132        return JSValueMakeNumber(1);
     133    }
     134
     135    if (JSStringIsEqualToUTF8CString(propertyName, "cantFind")) {
     136        return JSValueMakeUndefined();
     137    }
     138   
     139    return NULL;
     140}
     141
     142static bool MyObject_setProperty(JSContextRef context, JSObjectRef object, JSStringRef propertyName, JSValueRef value, JSValueRef* exception)
     143{
     144    UNUSED_PARAM(context);
     145    UNUSED_PARAM(object);
     146    UNUSED_PARAM(value);
     147
     148    if (JSStringIsEqualToUTF8CString(propertyName, "cantSet"))
     149        return true; // pretend we set the property in order to swallow it
     150   
     151    return false;
     152}
     153
     154static bool MyObject_deleteProperty(JSContextRef context, JSObjectRef object, JSStringRef propertyName, JSValueRef* exception)
     155{
     156    UNUSED_PARAM(context);
     157    UNUSED_PARAM(object);
     158   
     159    if (JSStringIsEqualToUTF8CString(propertyName, "cantDelete"))
    153160        return true;
    154     }
    155    
    156     if (JSInternalStringIsEqualUTF8(propertyName, "myPropertyName")) {
    157         *returnValue = JSNumberMake(1);
    158         return true;
    159     }
    160 
    161     if (JSInternalStringIsEqualUTF8(propertyName, "cantFind")) {
    162         *returnValue = JSUndefinedMake();
    163         return true;
    164     }
    165161   
    166162    return false;
    167163}
    168164
    169 static bool MyObject_setProperty(JSContextRef context, JSObjectRef object, JSInternalStringRef propertyName, JSValueRef value, JSValueRef* exception)
    170 {
    171     UNUSED_PARAM(context);
    172     UNUSED_PARAM(object);
    173     UNUSED_PARAM(value);
    174 
    175     if (JSInternalStringIsEqualUTF8(propertyName, "cantSet"))
    176         return true; // pretend we set the property in order to swallow it
    177    
    178     return false;
    179 }
    180 
    181 static bool MyObject_deleteProperty(JSContextRef context, JSObjectRef object, JSInternalStringRef propertyName, JSValueRef* exception)
    182 {
    183     UNUSED_PARAM(context);
    184     UNUSED_PARAM(object);
    185    
    186     if (JSInternalStringIsEqualUTF8(propertyName, "cantDelete"))
    187         return true;
    188    
    189     return false;
    190 }
    191 
    192165static void MyObject_getPropertyList(JSContextRef context, JSObjectRef object, JSPropertyListRef propertyList, JSValueRef* exception)
    193166{
    194167    UNUSED_PARAM(context);
    195168   
    196     JSInternalStringRef propertyName;
    197    
    198     propertyName = JSInternalStringCreateUTF8("alwaysOne");
     169    JSStringRef propertyName;
     170   
     171    propertyName = JSStringCreateWithUTF8CString("alwaysOne");
    199172    JSPropertyListAdd(propertyList, object, propertyName);
    200     JSInternalStringRelease(propertyName);
    201    
    202     propertyName = JSInternalStringCreateUTF8("myPropertyName");
     173    JSStringRelease(propertyName);
     174   
     175    propertyName = JSStringCreateWithUTF8CString("myPropertyName");
    203176    JSPropertyListAdd(propertyList, object, propertyName);
    204     JSInternalStringRelease(propertyName);
     177    JSStringRelease(propertyName);
    205178}
    206179
     
    211184    UNUSED_PARAM(thisObject);
    212185
    213     if (argc > 0 && JSValueIsStrictEqual(context, argv[0], JSNumberMake(0)))
    214         return JSNumberMake(1);
    215    
    216     return JSUndefinedMake();
     186    if (argc > 0 && JSValueIsStrictEqual(context, argv[0], JSValueMakeNumber(0)))
     187        return JSValueMakeNumber(1);
     188   
     189    return JSValueMakeUndefined();
    217190}
    218191
     
    222195    UNUSED_PARAM(object);
    223196
    224     if (argc > 0 && JSValueIsStrictEqual(context, argv[0], JSNumberMake(0)))
    225         return JSValueToObject(context, JSNumberMake(1));
    226    
    227     return JSValueToObject(context, JSNumberMake(0));
    228 }
    229 
    230 static bool MyObject_convertToType(JSContextRef context, JSObjectRef object, JSTypeCode typeCode, JSValueRef* returnValue, JSValueRef* exception)
    231 {
    232     UNUSED_PARAM(context);
    233     UNUSED_PARAM(object);
    234    
    235     switch (typeCode) {
     197    if (argc > 0 && JSValueIsStrictEqual(context, argv[0], JSValueMakeNumber(0)))
     198        return JSValueToObject(context, JSValueMakeNumber(1));
     199   
     200    return JSValueToObject(context, JSValueMakeNumber(0));
     201}
     202
     203static JSValueRef MyObject_convertToType(JSContextRef context, JSObjectRef object, JSType type, JSValueRef* exception)
     204{
     205    UNUSED_PARAM(context);
     206    UNUSED_PARAM(object);
     207   
     208    switch (type) {
    236209    case kJSTypeBoolean:
    237         *returnValue = JSBooleanMake(false); // default object conversion is 'true'
    238         return true;
     210        return JSValueMakeBoolean(false); // default object conversion is 'true'
    239211    case kJSTypeNumber:
    240         *returnValue = JSNumberMake(1);
    241         return true;
     212        return JSValueMakeNumber(1);
    242213    default:
    243214        break;
    244215    }
    245216
    246     // string
    247     return false;
     217    // string conversion -- forward to default object class
     218    return NULL;
    248219}
    249220
     
    286257   
    287258    if (argc > 0) {
    288         JSInternalStringRef string = JSValueCopyStringValue(context, argv[0]);
    289         size_t sizeUTF8 = JSInternalStringGetMaxLengthUTF8(string);
     259        JSStringRef string = JSValueToStringCopy(context, argv[0]);
     260        size_t sizeUTF8 = JSStringGetMaximumUTF8CStringSize(string);
    290261        char stringUTF8[sizeUTF8];
    291         JSInternalStringGetCharactersUTF8(string, stringUTF8, sizeUTF8);
     262        JSStringGetUTF8CString(string, stringUTF8, sizeUTF8);
    292263        printf("%s\n", stringUTF8);
    293         JSInternalStringRelease(string);
    294     }
    295    
    296     return JSUndefinedMake();
     264        JSStringRelease(string);
     265    }
     266   
     267    return JSValueMakeUndefined();
    297268}
    298269
     
    303274    JSObjectRef result = JSObjectMake(context, NULL, 0);
    304275    if (argc > 0) {
    305         JSInternalStringRef value = JSInternalStringCreateUTF8("value");
     276        JSStringRef value = JSStringCreateWithUTF8CString("value");
    306277        JSObjectSetProperty(context, result, value, argv[0], kJSPropertyAttributeNone);
    307         JSInternalStringRelease(value);
     278        JSStringRelease(value);
    308279    }
    309280   
     
    320291    context = JSContextCreate(NULL);
    321292
    322     JSValueRef jsUndefined = JSUndefinedMake();
    323     JSValueRef jsNull = JSNullMake();
    324     JSValueRef jsTrue = JSBooleanMake(true);
    325     JSValueRef jsFalse = JSBooleanMake(false);
    326     JSValueRef jsZero = JSNumberMake(0);
    327     JSValueRef jsOne = JSNumberMake(1);
    328     JSValueRef jsOneThird = JSNumberMake(1.0 / 3.0);
    329     JSObjectRef jsObjectNoProto = JSObjectMake(context, NULL, JSNullMake());
     293    JSValueRef jsUndefined = JSValueMakeUndefined();
     294    JSValueRef jsNull = JSValueMakeNull();
     295    JSValueRef jsTrue = JSValueMakeBoolean(true);
     296    JSValueRef jsFalse = JSValueMakeBoolean(false);
     297    JSValueRef jsZero = JSValueMakeNumber(0);
     298    JSValueRef jsOne = JSValueMakeNumber(1);
     299    JSValueRef jsOneThird = JSValueMakeNumber(1.0 / 3.0);
     300    JSObjectRef jsObjectNoProto = JSObjectMake(context, NULL, JSValueMakeNull());
    330301
    331302    // FIXME: test funny utf8 characters
    332     JSInternalStringRef jsEmptyIString = JSInternalStringCreateUTF8("");
    333     JSValueRef jsEmptyString = JSStringMake(jsEmptyIString);
    334    
    335     JSInternalStringRef jsOneIString = JSInternalStringCreateUTF8("1");
    336     JSValueRef jsOneString = JSStringMake(jsOneIString);
     303    JSStringRef jsEmptyIString = JSStringCreateWithUTF8CString("");
     304    JSValueRef jsEmptyString = JSValueMakeString(jsEmptyIString);
     305   
     306    JSStringRef jsOneIString = JSStringCreateWithUTF8CString("1");
     307    JSValueRef jsOneString = JSValueMakeString(jsOneIString);
    337308
    338309#if defined(__APPLE__)
     
    345316                                                          kCFAllocatorNull);
    346317
    347     JSInternalStringRef jsCFIString = JSInternalStringCreateCF(cfString);
    348     JSValueRef jsCFString = JSStringMake(jsCFIString);
     318    JSStringRef jsCFIString = JSStringCreateWithCFString(cfString);
     319    JSValueRef jsCFString = JSValueMakeString(jsCFIString);
    349320   
    350321    CFStringRef cfEmptyString = CFStringCreateWithCString(kCFAllocatorDefault, "", kCFStringEncodingUTF8);
    351322   
    352     JSInternalStringRef jsCFEmptyIString = JSInternalStringCreateCF(cfEmptyString);
    353     JSValueRef jsCFEmptyString = JSStringMake(jsCFEmptyIString);
     323    JSStringRef jsCFEmptyIString = JSStringCreateWithCFString(cfEmptyString);
     324    JSValueRef jsCFEmptyString = JSValueMakeString(jsCFEmptyIString);
    354325
    355326    CFIndex cfStringLength = CFStringGetLength(cfString);
     
    358329                          CFRangeMake(0, cfStringLength),
    359330                          buffer);
    360     JSInternalStringRef jsCFIStringWithCharacters = JSInternalStringCreate(buffer, cfStringLength);
    361     JSValueRef jsCFStringWithCharacters = JSStringMake(jsCFIStringWithCharacters);
    362    
    363     JSInternalStringRef jsCFEmptyIStringWithCharacters = JSInternalStringCreate(buffer, CFStringGetLength(cfEmptyString));
    364     JSValueRef jsCFEmptyStringWithCharacters = JSStringMake(jsCFEmptyIStringWithCharacters);
     331    JSStringRef jsCFIStringWithCharacters = JSStringCreateWithCharacters(buffer, cfStringLength);
     332    JSValueRef jsCFStringWithCharacters = JSValueMakeString(jsCFIStringWithCharacters);
     333   
     334    JSStringRef jsCFEmptyIStringWithCharacters = JSStringCreateWithCharacters(buffer, CFStringGetLength(cfEmptyString));
     335    JSValueRef jsCFEmptyStringWithCharacters = JSValueMakeString(jsCFEmptyIStringWithCharacters);
    365336#endif // __APPLE__
    366337
     
    435406#endif // __APPLE__
    436407   
    437     assertEqualsAsCharacters(jsUndefined, "undefined");
    438     assertEqualsAsCharacters(jsNull, "null");
    439     assertEqualsAsCharacters(jsTrue, "true");
    440     assertEqualsAsCharacters(jsFalse, "false");
    441     assertEqualsAsCharacters(jsZero, "0");
    442     assertEqualsAsCharacters(jsOne, "1");
    443     assertEqualsAsCharacters(jsOneThird, "0.3333333333333333");
    444     assertEqualsAsCharacters(jsEmptyString, "");
    445     assertEqualsAsCharacters(jsOneString, "1");
    446 #if defined(__APPLE__)
    447     assertEqualsAsCharacters(jsCFString, "A");
    448     assertEqualsAsCharacters(jsCFStringWithCharacters, "A");
    449     assertEqualsAsCharacters(jsCFEmptyString, "");
    450     assertEqualsAsCharacters(jsCFEmptyStringWithCharacters, "");
    451 #endif // __APPLE__
    452    
    453408    assertEqualsAsUTF8String(jsUndefined, "undefined");
    454409    assertEqualsAsUTF8String(jsNull, "null");
     
    474429   
    475430#if defined(__APPLE__)
    476     CFStringRef cfJSString = CFStringCreateWithJSInternalString(kCFAllocatorDefault, jsCFIString);
    477     CFStringRef cfJSEmptyString = CFStringCreateWithJSInternalString(kCFAllocatorDefault, jsCFEmptyIString);
     431    CFStringRef cfJSString = JSStringCopyCFString(kCFAllocatorDefault, jsCFIString);
     432    CFStringRef cfJSEmptyString = JSStringCopyCFString(kCFAllocatorDefault, jsCFEmptyIString);
    478433    assert(CFEqual(cfJSString, cfString));
    479434    assert(CFEqual(cfJSEmptyString, cfEmptyString));
     
    486441   
    487442    jsGlobalValue = JSObjectMake(context, NULL, NULL);
    488     JSGCProtect(jsGlobalValue);
    489     JSGCCollect();
     443    JSValueProtect(jsGlobalValue);
     444    JSGarbageCollect();
    490445    assert(JSValueIsObject(jsGlobalValue));
    491     JSGCUnprotect(jsGlobalValue);
     446    JSValueUnprotect(jsGlobalValue);
    492447
    493448    /* JSInterpreter.h */
     
    496451    assert(JSValueIsObject(globalObject));
    497452
    498     JSInternalStringRef goodSyntax = JSInternalStringCreateUTF8("x = 1;");
    499     JSInternalStringRef badSyntax = JSInternalStringCreateUTF8("x := 1;");
     453    JSStringRef goodSyntax = JSStringCreateWithUTF8CString("x = 1;");
     454    JSStringRef badSyntax = JSStringCreateWithUTF8CString("x := 1;");
    500455    assert(JSCheckSyntax(context, goodSyntax, NULL, 0, NULL));
    501456    assert(!JSCheckSyntax(context, badSyntax, NULL, 0, NULL));
     
    515470    assert(JSValueIsObject(exception));
    516471   
    517     JSInternalStringRef array = JSInternalStringCreateUTF8("Array");
     472    JSStringRef array = JSStringCreateWithUTF8CString("Array");
    518473    v = JSObjectGetProperty(context, globalObject, array);
    519474    assert(v);
    520475    JSObjectRef arrayConstructor = JSValueToObject(context, v);
    521     JSInternalStringRelease(array);
     476    JSStringRelease(array);
    522477    result = JSObjectCallAsConstructor(context, arrayConstructor, 0, NULL, NULL);
    523478    assert(result);
    524     assert(JSValueIsInstanceOf(context, result, arrayConstructor));
    525     assert(!JSValueIsInstanceOf(context, JSNullMake(), arrayConstructor));
    526    
    527     JSInternalStringRef functionBody;
     479    assert(JSValueIsInstanceOfConstructor(context, result, arrayConstructor));
     480    assert(!JSValueIsInstanceOfConstructor(context, JSValueMakeNull(), arrayConstructor));
     481   
     482    JSStringRef functionBody;
    528483   
    529484    exception = NULL;
    530     functionBody = JSInternalStringCreateUTF8("rreturn Array;");
    531     JSInternalStringRef line = JSInternalStringCreateUTF8("line");
    532     assert(!JSFunctionMakeWithBody(context, functionBody, NULL, 1, &exception));
     485    functionBody = JSStringCreateWithUTF8CString("rreturn Array;");
     486    JSStringRef line = JSStringCreateWithUTF8CString("line");
     487    assert(!JSObjectMakeFunctionWithBody(context, functionBody, NULL, 1, &exception));
    533488    assert(JSValueIsObject(exception));
    534489    v = JSObjectGetProperty(context, JSValueToObject(context, exception), line);
    535490    assert(v);
    536491    assertEqualsAsNumber(v, 2); // FIXME: Lexer::setCode bumps startingLineNumber by 1 -- we need to change internal callers so that it doesn't have to (saying '0' to mean '1' in the API would be really confusing -- it's really confusing internally, in fact)
    537     JSInternalStringRelease(functionBody);
    538     JSInternalStringRelease(line);
    539 
    540     functionBody = JSInternalStringCreateUTF8("return Array;");
    541     JSObjectRef function = JSFunctionMakeWithBody(context, functionBody, NULL, 1, NULL);
    542     JSInternalStringRelease(functionBody);
     492    JSStringRelease(functionBody);
     493    JSStringRelease(line);
     494
     495    functionBody = JSStringCreateWithUTF8CString("return Array;");
     496    JSObjectRef function = JSObjectMakeFunctionWithBody(context, functionBody, NULL, 1, NULL);
     497    JSStringRelease(functionBody);
    543498
    544499    assert(JSObjectIsFunction(function));
     
    548503    JSObjectRef myObject = JSObjectMake(context, MyObject_class(context), NULL);
    549504    assert(didInitialize);
    550     JSInternalStringRef myObjectIString = JSInternalStringCreateUTF8("MyObject");
     505    JSStringRef myObjectIString = JSStringCreateWithUTF8CString("MyObject");
    551506    JSObjectSetProperty(context, globalObject, myObjectIString, myObject, kJSPropertyAttributeNone);
    552     JSInternalStringRelease(myObjectIString);
    553 
    554     JSInternalStringRef print = JSInternalStringCreateUTF8("print");
    555     JSObjectRef printFunction = JSFunctionMake(context, print_callAsFunction);
     507    JSStringRelease(myObjectIString);
     508
     509    JSStringRef print = JSStringCreateWithUTF8CString("print");
     510    JSObjectRef printFunction = JSObjectMakeFunction(context, print_callAsFunction);
    556511    JSObjectSetProperty(context, globalObject, print, printFunction, kJSPropertyAttributeNone);
    557     JSInternalStringRelease(print);
     512    JSStringRelease(print);
    558513   
    559514    assert(JSObjectSetPrivate(printFunction, (void*)1));
    560515    assert(JSObjectGetPrivate(printFunction) == (void*)1);
    561516
    562     JSInternalStringRef myConstructorIString = JSInternalStringCreateUTF8("MyConstructor");
    563     JSObjectRef myConstructor = JSConstructorMake(context, myConstructor_callAsConstructor);
     517    JSStringRef myConstructorIString = JSStringCreateWithUTF8CString("MyConstructor");
     518    JSObjectRef myConstructor = JSObjectMakeConstructor(context, myConstructor_callAsConstructor);
    564519    JSObjectSetProperty(context, globalObject, myConstructorIString, myConstructor, kJSPropertyAttributeNone);
    565     JSInternalStringRelease(myConstructorIString);
     520    JSStringRelease(myConstructorIString);
    566521   
    567522    assert(JSObjectSetPrivate(myConstructor, (void*)1));
     
    569524   
    570525    o = JSObjectMake(context, NULL, NULL);
    571     JSObjectSetProperty(context, o, jsOneIString, JSNumberMake(1), kJSPropertyAttributeNone);
    572     JSObjectSetProperty(context, o, jsCFIString,  JSNumberMake(1), kJSPropertyAttributeDontEnum);
     526    JSObjectSetProperty(context, o, jsOneIString, JSValueMakeNumber(1), kJSPropertyAttributeNone);
     527    JSObjectSetProperty(context, o, jsCFIString,  JSValueMakeNumber(1), kJSPropertyAttributeDontEnum);
    573528    JSPropertyEnumeratorRef enumerator = JSObjectCreatePropertyEnumerator(context, o);
    574529    int count = 0;
    575     while (JSPropertyEnumeratorGetNext(enumerator))
     530    while (JSPropertyEnumeratorGetNextName(enumerator))
    576531        ++count;
    577532    JSPropertyEnumeratorRelease(enumerator);
     
    581536    JSClassRelease(nullCallbacksClass);
    582537   
    583     functionBody = JSInternalStringCreateUTF8("return this;");
    584     function = JSFunctionMakeWithBody(context, functionBody, NULL, 1, NULL);
    585     JSInternalStringRelease(functionBody);
     538    functionBody = JSStringCreateWithUTF8CString("return this;");
     539    function = JSObjectMakeFunctionWithBody(context, functionBody, NULL, 1, NULL);
     540    JSStringRelease(functionBody);
    586541    v = JSObjectCallAsFunction(context, function, NULL, 0, NULL, NULL);
    587542    assert(JSValueIsEqual(context, v, globalObject));
     
    590545   
    591546    char* scriptUTF8 = createStringWithContentsOfFile("testapi.js");
    592     JSInternalStringRef script = JSInternalStringCreateUTF8(scriptUTF8);
     547    JSStringRef script = JSStringCreateWithUTF8CString(scriptUTF8);
    593548    result = JSEvaluate(context, script, NULL, NULL, 1, &exception);
    594549    if (JSValueIsUndefined(result))
     
    596551    else {
    597552        printf("FAIL: Test script returned unexcpected value:\n");
    598         JSInternalStringRef exceptionIString = JSValueCopyStringValue(context, exception);
    599         CFStringRef exceptionCF = CFStringCreateWithJSInternalString(kCFAllocatorDefault, exceptionIString);
     553        JSStringRef exceptionIString = JSValueToStringCopy(context, exception);
     554        CFStringRef exceptionCF = JSStringCopyCFString(kCFAllocatorDefault, exceptionIString);
    600555        CFShow(exceptionCF);
    601556        CFRelease(exceptionCF);
    602         JSInternalStringRelease(exceptionIString);
    603     }
    604     JSInternalStringRelease(script);
     557        JSStringRelease(exceptionIString);
     558    }
     559    JSStringRelease(script);
    605560    free(scriptUTF8);
    606561
     
    608563    JSObjectMake(context, MyObject_class(context), 0);
    609564    JSObjectMake(context, MyObject_class(context), 0);
    610     JSGCCollect();
     565    JSGarbageCollect();
    611566    assert(didFinalize);
    612567
    613     JSInternalStringRelease(jsEmptyIString);
    614     JSInternalStringRelease(jsOneIString);
    615 #if defined(__APPLE__)
    616     JSInternalStringRelease(jsCFIString);
    617     JSInternalStringRelease(jsCFEmptyIString);
    618     JSInternalStringRelease(jsCFIStringWithCharacters);
    619     JSInternalStringRelease(jsCFEmptyIStringWithCharacters);
    620 #endif // __APPLE__
    621     JSInternalStringRelease(goodSyntax);
    622     JSInternalStringRelease(badSyntax);
     568    JSStringRelease(jsEmptyIString);
     569    JSStringRelease(jsOneIString);
     570#if defined(__APPLE__)
     571    JSStringRelease(jsCFIString);
     572    JSStringRelease(jsCFEmptyIString);
     573    JSStringRelease(jsCFIStringWithCharacters);
     574    JSStringRelease(jsCFEmptyIStringWithCharacters);
     575#endif // __APPLE__
     576    JSStringRelease(goodSyntax);
     577    JSStringRelease(badSyntax);
    623578   
    624579    JSContextDestroy(context);
Note: See TracChangeset for help on using the changeset viewer.