Changeset 15376 in webkit for trunk/JavaScriptCore/API/testapi.c
- Timestamp:
- Jul 12, 2006, 1:12:08 AM (19 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/JavaScriptCore/API/testapi.c
r15328 r15376 52 52 static void assertEqualsAsUTF8String(JSValueRef value, const char* expectedValue) 53 53 { 54 JS InternalStringRef valueAsString = JSValueCopyStringValue(context, value);55 56 size_t jsSize = JS InternalStringGetMaxLengthUTF8(valueAsString);54 JSStringRef valueAsString = JSValueToStringCopy(context, value); 55 56 size_t jsSize = JSStringGetMaximumUTF8CStringSize(valueAsString); 57 57 char jsBuffer[jsSize]; 58 JS InternalStringGetCharactersUTF8(valueAsString, jsBuffer, jsSize);58 JSStringGetUTF8CString(valueAsString, jsBuffer, jsSize); 59 59 60 60 if (strcmp(jsBuffer, expectedValue) != 0) … … 64 64 fprintf(stderr, "assertEqualsAsUTF8String failed: jsSize was too small\n"); 65 65 66 JS InternalStringRelease(valueAsString);66 JSStringRelease(valueAsString); 67 67 } 68 68 … … 70 70 static void assertEqualsAsCharactersPtr(JSValueRef value, const char* expectedValue) 71 71 { 72 JS InternalStringRef valueAsString = JSValueCopyStringValue(context, value);73 74 size_t jsLength = JS InternalStringGetLength(valueAsString);75 const JSChar* jsBuffer = JS InternalStringGetCharactersPtr(valueAsString);72 JSStringRef valueAsString = JSValueToStringCopy(context, value); 73 74 size_t jsLength = JSStringGetLength(valueAsString); 75 const JSChar* jsBuffer = JSStringGetCharactersPtr(valueAsString); 76 76 77 77 CFStringRef expectedValueAsCFString = CFStringCreateWithCString(kCFAllocatorDefault, … … 89 89 fprintf(stderr, "assertEqualsAsCharactersPtr failed: jsLength(%ld) != cfLength(%ld)\n", jsLength, cfLength); 90 90 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 96 static JSValueRef jsGlobalValue; // non-stack value for testing JSValueProtect() 121 97 122 98 /* MyObject pseudo-class */ … … 130 106 } 131 107 132 static bool MyObject_hasProperty(JSContextRef context, JSObjectRef object, JS InternalStringRef propertyName, JSValueRef* exception)133 { 134 UNUSED_PARAM(context); 135 UNUSED_PARAM(object); 136 137 if (JS InternalStringIsEqualUTF8(propertyName, "alwaysOne")138 || JS InternalStringIsEqualUTF8(propertyName, "cantFind")139 || JS InternalStringIsEqualUTF8(propertyName, "myPropertyName")) {108 static 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")) { 140 116 return true; 141 117 } … … 144 120 } 145 121 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); 122 static 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 142 static 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 154 static 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")) 153 160 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 }165 161 166 162 return false; 167 163 } 168 164 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 it177 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 192 165 static void MyObject_getPropertyList(JSContextRef context, JSObjectRef object, JSPropertyListRef propertyList, JSValueRef* exception) 193 166 { 194 167 UNUSED_PARAM(context); 195 168 196 JS InternalStringRef propertyName;197 198 propertyName = JS InternalStringCreateUTF8("alwaysOne");169 JSStringRef propertyName; 170 171 propertyName = JSStringCreateWithUTF8CString("alwaysOne"); 199 172 JSPropertyListAdd(propertyList, object, propertyName); 200 JS InternalStringRelease(propertyName);201 202 propertyName = JS InternalStringCreateUTF8("myPropertyName");173 JSStringRelease(propertyName); 174 175 propertyName = JSStringCreateWithUTF8CString("myPropertyName"); 203 176 JSPropertyListAdd(propertyList, object, propertyName); 204 JS InternalStringRelease(propertyName);177 JSStringRelease(propertyName); 205 178 } 206 179 … … 211 184 UNUSED_PARAM(thisObject); 212 185 213 if (argc > 0 && JSValueIsStrictEqual(context, argv[0], JS NumberMake(0)))214 return JS NumberMake(1);215 216 return JS UndefinedMake();186 if (argc > 0 && JSValueIsStrictEqual(context, argv[0], JSValueMakeNumber(0))) 187 return JSValueMakeNumber(1); 188 189 return JSValueMakeUndefined(); 217 190 } 218 191 … … 222 195 UNUSED_PARAM(object); 223 196 224 if (argc > 0 && JSValueIsStrictEqual(context, argv[0], JS NumberMake(0)))225 return JSValueToObject(context, JS NumberMake(1));226 227 return JSValueToObject(context, JS NumberMake(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 (type Code) {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 203 static JSValueRef MyObject_convertToType(JSContextRef context, JSObjectRef object, JSType type, JSValueRef* exception) 204 { 205 UNUSED_PARAM(context); 206 UNUSED_PARAM(object); 207 208 switch (type) { 236 209 case kJSTypeBoolean: 237 *returnValue = JSBooleanMake(false); // default object conversion is 'true' 238 return true; 210 return JSValueMakeBoolean(false); // default object conversion is 'true' 239 211 case kJSTypeNumber: 240 *returnValue = JSNumberMake(1); 241 return true; 212 return JSValueMakeNumber(1); 242 213 default: 243 214 break; 244 215 } 245 216 246 // string 247 return false;217 // string conversion -- forward to default object class 218 return NULL; 248 219 } 249 220 … … 286 257 287 258 if (argc > 0) { 288 JS InternalStringRef string = JSValueCopyStringValue(context, argv[0]);289 size_t sizeUTF8 = JS InternalStringGetMaxLengthUTF8(string);259 JSStringRef string = JSValueToStringCopy(context, argv[0]); 260 size_t sizeUTF8 = JSStringGetMaximumUTF8CStringSize(string); 290 261 char stringUTF8[sizeUTF8]; 291 JS InternalStringGetCharactersUTF8(string, stringUTF8, sizeUTF8);262 JSStringGetUTF8CString(string, stringUTF8, sizeUTF8); 292 263 printf("%s\n", stringUTF8); 293 JS InternalStringRelease(string);294 } 295 296 return JS UndefinedMake();264 JSStringRelease(string); 265 } 266 267 return JSValueMakeUndefined(); 297 268 } 298 269 … … 303 274 JSObjectRef result = JSObjectMake(context, NULL, 0); 304 275 if (argc > 0) { 305 JS InternalStringRef value = JSInternalStringCreateUTF8("value");276 JSStringRef value = JSStringCreateWithUTF8CString("value"); 306 277 JSObjectSetProperty(context, result, value, argv[0], kJSPropertyAttributeNone); 307 JS InternalStringRelease(value);278 JSStringRelease(value); 308 279 } 309 280 … … 320 291 context = JSContextCreate(NULL); 321 292 322 JSValueRef jsUndefined = JS UndefinedMake();323 JSValueRef jsNull = JS NullMake();324 JSValueRef jsTrue = JS BooleanMake(true);325 JSValueRef jsFalse = JS BooleanMake(false);326 JSValueRef jsZero = JS NumberMake(0);327 JSValueRef jsOne = JS NumberMake(1);328 JSValueRef jsOneThird = JS NumberMake(1.0 / 3.0);329 JSObjectRef jsObjectNoProto = JSObjectMake(context, NULL, JS NullMake());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()); 330 301 331 302 // FIXME: test funny utf8 characters 332 JS InternalStringRef jsEmptyIString = JSInternalStringCreateUTF8("");333 JSValueRef jsEmptyString = JS StringMake(jsEmptyIString);334 335 JS InternalStringRef jsOneIString = JSInternalStringCreateUTF8("1");336 JSValueRef jsOneString = JS StringMake(jsOneIString);303 JSStringRef jsEmptyIString = JSStringCreateWithUTF8CString(""); 304 JSValueRef jsEmptyString = JSValueMakeString(jsEmptyIString); 305 306 JSStringRef jsOneIString = JSStringCreateWithUTF8CString("1"); 307 JSValueRef jsOneString = JSValueMakeString(jsOneIString); 337 308 338 309 #if defined(__APPLE__) … … 345 316 kCFAllocatorNull); 346 317 347 JS InternalStringRef jsCFIString = JSInternalStringCreateCF(cfString);348 JSValueRef jsCFString = JS StringMake(jsCFIString);318 JSStringRef jsCFIString = JSStringCreateWithCFString(cfString); 319 JSValueRef jsCFString = JSValueMakeString(jsCFIString); 349 320 350 321 CFStringRef cfEmptyString = CFStringCreateWithCString(kCFAllocatorDefault, "", kCFStringEncodingUTF8); 351 322 352 JS InternalStringRef jsCFEmptyIString = JSInternalStringCreateCF(cfEmptyString);353 JSValueRef jsCFEmptyString = JS StringMake(jsCFEmptyIString);323 JSStringRef jsCFEmptyIString = JSStringCreateWithCFString(cfEmptyString); 324 JSValueRef jsCFEmptyString = JSValueMakeString(jsCFEmptyIString); 354 325 355 326 CFIndex cfStringLength = CFStringGetLength(cfString); … … 358 329 CFRangeMake(0, cfStringLength), 359 330 buffer); 360 JS InternalStringRef jsCFIStringWithCharacters = JSInternalStringCreate(buffer, cfStringLength);361 JSValueRef jsCFStringWithCharacters = JS StringMake(jsCFIStringWithCharacters);362 363 JS InternalStringRef jsCFEmptyIStringWithCharacters = JSInternalStringCreate(buffer, CFStringGetLength(cfEmptyString));364 JSValueRef jsCFEmptyStringWithCharacters = JS StringMake(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); 365 336 #endif // __APPLE__ 366 337 … … 435 406 #endif // __APPLE__ 436 407 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 453 408 assertEqualsAsUTF8String(jsUndefined, "undefined"); 454 409 assertEqualsAsUTF8String(jsNull, "null"); … … 474 429 475 430 #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); 478 433 assert(CFEqual(cfJSString, cfString)); 479 434 assert(CFEqual(cfJSEmptyString, cfEmptyString)); … … 486 441 487 442 jsGlobalValue = JSObjectMake(context, NULL, NULL); 488 JS GCProtect(jsGlobalValue);489 JSG CCollect();443 JSValueProtect(jsGlobalValue); 444 JSGarbageCollect(); 490 445 assert(JSValueIsObject(jsGlobalValue)); 491 JS GCUnprotect(jsGlobalValue);446 JSValueUnprotect(jsGlobalValue); 492 447 493 448 /* JSInterpreter.h */ … … 496 451 assert(JSValueIsObject(globalObject)); 497 452 498 JS InternalStringRef goodSyntax = JSInternalStringCreateUTF8("x = 1;");499 JS InternalStringRef badSyntax = JSInternalStringCreateUTF8("x := 1;");453 JSStringRef goodSyntax = JSStringCreateWithUTF8CString("x = 1;"); 454 JSStringRef badSyntax = JSStringCreateWithUTF8CString("x := 1;"); 500 455 assert(JSCheckSyntax(context, goodSyntax, NULL, 0, NULL)); 501 456 assert(!JSCheckSyntax(context, badSyntax, NULL, 0, NULL)); … … 515 470 assert(JSValueIsObject(exception)); 516 471 517 JS InternalStringRef array = JSInternalStringCreateUTF8("Array");472 JSStringRef array = JSStringCreateWithUTF8CString("Array"); 518 473 v = JSObjectGetProperty(context, globalObject, array); 519 474 assert(v); 520 475 JSObjectRef arrayConstructor = JSValueToObject(context, v); 521 JS InternalStringRelease(array);476 JSStringRelease(array); 522 477 result = JSObjectCallAsConstructor(context, arrayConstructor, 0, NULL, NULL); 523 478 assert(result); 524 assert(JSValueIsInstanceOf (context, result, arrayConstructor));525 assert(!JSValueIsInstanceOf (context, JSNullMake(), arrayConstructor));526 527 JS InternalStringRef functionBody;479 assert(JSValueIsInstanceOfConstructor(context, result, arrayConstructor)); 480 assert(!JSValueIsInstanceOfConstructor(context, JSValueMakeNull(), arrayConstructor)); 481 482 JSStringRef functionBody; 528 483 529 484 exception = NULL; 530 functionBody = JS InternalStringCreateUTF8("rreturn Array;");531 JS InternalStringRef line = JSInternalStringCreateUTF8("line");532 assert(!JS FunctionMakeWithBody(context, functionBody, NULL, 1, &exception));485 functionBody = JSStringCreateWithUTF8CString("rreturn Array;"); 486 JSStringRef line = JSStringCreateWithUTF8CString("line"); 487 assert(!JSObjectMakeFunctionWithBody(context, functionBody, NULL, 1, &exception)); 533 488 assert(JSValueIsObject(exception)); 534 489 v = JSObjectGetProperty(context, JSValueToObject(context, exception), line); 535 490 assert(v); 536 491 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 JS InternalStringRelease(functionBody);538 JS InternalStringRelease(line);539 540 functionBody = JS InternalStringCreateUTF8("return Array;");541 JSObjectRef function = JS FunctionMakeWithBody(context, functionBody, NULL, 1, NULL);542 JS InternalStringRelease(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); 543 498 544 499 assert(JSObjectIsFunction(function)); … … 548 503 JSObjectRef myObject = JSObjectMake(context, MyObject_class(context), NULL); 549 504 assert(didInitialize); 550 JS InternalStringRef myObjectIString = JSInternalStringCreateUTF8("MyObject");505 JSStringRef myObjectIString = JSStringCreateWithUTF8CString("MyObject"); 551 506 JSObjectSetProperty(context, globalObject, myObjectIString, myObject, kJSPropertyAttributeNone); 552 JS InternalStringRelease(myObjectIString);553 554 JS InternalStringRef print = JSInternalStringCreateUTF8("print");555 JSObjectRef printFunction = JS FunctionMake(context, print_callAsFunction);507 JSStringRelease(myObjectIString); 508 509 JSStringRef print = JSStringCreateWithUTF8CString("print"); 510 JSObjectRef printFunction = JSObjectMakeFunction(context, print_callAsFunction); 556 511 JSObjectSetProperty(context, globalObject, print, printFunction, kJSPropertyAttributeNone); 557 JS InternalStringRelease(print);512 JSStringRelease(print); 558 513 559 514 assert(JSObjectSetPrivate(printFunction, (void*)1)); 560 515 assert(JSObjectGetPrivate(printFunction) == (void*)1); 561 516 562 JS InternalStringRef myConstructorIString = JSInternalStringCreateUTF8("MyConstructor");563 JSObjectRef myConstructor = JS ConstructorMake(context, myConstructor_callAsConstructor);517 JSStringRef myConstructorIString = JSStringCreateWithUTF8CString("MyConstructor"); 518 JSObjectRef myConstructor = JSObjectMakeConstructor(context, myConstructor_callAsConstructor); 564 519 JSObjectSetProperty(context, globalObject, myConstructorIString, myConstructor, kJSPropertyAttributeNone); 565 JS InternalStringRelease(myConstructorIString);520 JSStringRelease(myConstructorIString); 566 521 567 522 assert(JSObjectSetPrivate(myConstructor, (void*)1)); … … 569 524 570 525 o = JSObjectMake(context, NULL, NULL); 571 JSObjectSetProperty(context, o, jsOneIString, JS NumberMake(1), kJSPropertyAttributeNone);572 JSObjectSetProperty(context, o, jsCFIString, JS NumberMake(1), kJSPropertyAttributeDontEnum);526 JSObjectSetProperty(context, o, jsOneIString, JSValueMakeNumber(1), kJSPropertyAttributeNone); 527 JSObjectSetProperty(context, o, jsCFIString, JSValueMakeNumber(1), kJSPropertyAttributeDontEnum); 573 528 JSPropertyEnumeratorRef enumerator = JSObjectCreatePropertyEnumerator(context, o); 574 529 int count = 0; 575 while (JSPropertyEnumeratorGetNext (enumerator))530 while (JSPropertyEnumeratorGetNextName(enumerator)) 576 531 ++count; 577 532 JSPropertyEnumeratorRelease(enumerator); … … 581 536 JSClassRelease(nullCallbacksClass); 582 537 583 functionBody = JS InternalStringCreateUTF8("return this;");584 function = JS FunctionMakeWithBody(context, functionBody, NULL, 1, NULL);585 JS InternalStringRelease(functionBody);538 functionBody = JSStringCreateWithUTF8CString("return this;"); 539 function = JSObjectMakeFunctionWithBody(context, functionBody, NULL, 1, NULL); 540 JSStringRelease(functionBody); 586 541 v = JSObjectCallAsFunction(context, function, NULL, 0, NULL, NULL); 587 542 assert(JSValueIsEqual(context, v, globalObject)); … … 590 545 591 546 char* scriptUTF8 = createStringWithContentsOfFile("testapi.js"); 592 JS InternalStringRef script = JSInternalStringCreateUTF8(scriptUTF8);547 JSStringRef script = JSStringCreateWithUTF8CString(scriptUTF8); 593 548 result = JSEvaluate(context, script, NULL, NULL, 1, &exception); 594 549 if (JSValueIsUndefined(result)) … … 596 551 else { 597 552 printf("FAIL: Test script returned unexcpected value:\n"); 598 JS InternalStringRef exceptionIString = JSValueCopyStringValue(context, exception);599 CFStringRef exceptionCF = CFStringCreateWithJSInternalString(kCFAllocatorDefault, exceptionIString);553 JSStringRef exceptionIString = JSValueToStringCopy(context, exception); 554 CFStringRef exceptionCF = JSStringCopyCFString(kCFAllocatorDefault, exceptionIString); 600 555 CFShow(exceptionCF); 601 556 CFRelease(exceptionCF); 602 JS InternalStringRelease(exceptionIString);603 } 604 JS InternalStringRelease(script);557 JSStringRelease(exceptionIString); 558 } 559 JSStringRelease(script); 605 560 free(scriptUTF8); 606 561 … … 608 563 JSObjectMake(context, MyObject_class(context), 0); 609 564 JSObjectMake(context, MyObject_class(context), 0); 610 JSG CCollect();565 JSGarbageCollect(); 611 566 assert(didFinalize); 612 567 613 JS InternalStringRelease(jsEmptyIString);614 JS InternalStringRelease(jsOneIString);615 #if defined(__APPLE__) 616 JS InternalStringRelease(jsCFIString);617 JS InternalStringRelease(jsCFEmptyIString);618 JS InternalStringRelease(jsCFIStringWithCharacters);619 JS InternalStringRelease(jsCFEmptyIStringWithCharacters);620 #endif // __APPLE__ 621 JS InternalStringRelease(goodSyntax);622 JS InternalStringRelease(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); 623 578 624 579 JSContextDestroy(context);
Note:
See TracChangeset
for help on using the changeset viewer.