Changeset 15404 in webkit for trunk/JavaScriptCore/API/testapi.c
- Timestamp:
- Jul 13, 2006, 1:56:52 AM (19 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/JavaScriptCore/API/testapi.c
r15385 r15404 39 39 static void assertEqualsAsBoolean(JSValueRef value, bool expectedValue) 40 40 { 41 if (JSValueToBoolean(context, value ) != expectedValue)41 if (JSValueToBoolean(context, value, NULL) != expectedValue) 42 42 fprintf(stderr, "assertEqualsAsBoolean failed: %p, %d\n", value, expectedValue); 43 43 } … … 45 45 static void assertEqualsAsNumber(JSValueRef value, double expectedValue) 46 46 { 47 double number = JSValueToNumber(context, value );47 double number = JSValueToNumber(context, value, NULL); 48 48 if (number != expectedValue && !(isnan(number) && isnan(expectedValue))) 49 49 fprintf(stderr, "assertEqualsAsNumber failed: %p, %lf\n", value, expectedValue); … … 52 52 static void assertEqualsAsUTF8String(JSValueRef value, const char* expectedValue) 53 53 { 54 JSStringRef valueAsString = JSValueToStringCopy(context, value );54 JSStringRef valueAsString = JSValueToStringCopy(context, value, NULL); 55 55 56 56 size_t jsSize = JSStringGetMaximumUTF8CStringSize(valueAsString); … … 70 70 static void assertEqualsAsCharactersPtr(JSValueRef value, const char* expectedValue) 71 71 { 72 JSStringRef valueAsString = JSValueToStringCopy(context, value );72 JSStringRef valueAsString = JSValueToStringCopy(context, value, NULL); 73 73 74 74 size_t jsLength = JSStringGetLength(valueAsString); … … 196 196 197 197 if (argc > 0 && JSValueIsStrictEqual(context, argv[0], JSValueMakeNumber(0))) 198 return JSValueToObject(context, JSValueMakeNumber(1) );199 200 return JSValueToObject(context, JSValueMakeNumber(0) );198 return JSValueToObject(context, JSValueMakeNumber(1), NULL); 199 200 return JSValueToObject(context, JSValueMakeNumber(0), NULL); 201 201 } 202 202 … … 206 206 207 207 JSStringRef numberString = JSStringCreateWithUTF8CString("Number"); 208 JSObjectRef numberConstructor = JSValueToObject(context, JSObjectGetProperty(context, JSContextGetGlobalObject(context), numberString) );208 JSObjectRef numberConstructor = JSValueToObject(context, JSObjectGetProperty(context, JSContextGetGlobalObject(context), numberString), NULL); 209 209 JSStringRelease(numberString); 210 210 … … 219 219 switch (type) { 220 220 case kJSTypeBoolean: 221 return JSValueMakeBoolean(false); // default object conversion is 'true' 221 *exception = JSValueMakeNumber(2); 222 return NULL; 222 223 case kJSTypeNumber: 223 224 return JSValueMakeNumber(1); … … 269 270 270 271 if (argc > 0) { 271 JSStringRef string = JSValueToStringCopy(context, argv[0] );272 JSStringRef string = JSValueToStringCopy(context, argv[0], NULL); 272 273 size_t sizeUTF8 = JSStringGetMaximumUTF8CStringSize(string); 273 274 char stringUTF8[sizeUTF8]; … … 302 303 303 304 context = JSContextCreate(NULL); 304 305 306 JSObjectRef globalObject = JSContextGetGlobalObject(context); 307 assert(JSValueIsObject(globalObject)); 308 305 309 JSValueRef jsUndefined = JSValueMakeUndefined(); 306 310 JSValueRef jsNull = JSValueMakeNull(); … … 364 368 #endif // __APPLE__ 365 369 370 JSObjectRef myObject = JSObjectMake(context, MyObject_class(context), NULL); 371 assert(didInitialize); 372 JSStringRef myObjectIString = JSStringCreateWithUTF8CString("MyObject"); 373 JSObjectSetProperty(context, globalObject, myObjectIString, myObject, kJSPropertyAttributeNone); 374 JSStringRelease(myObjectIString); 375 376 JSValueRef exception; 377 366 378 // Conversions that throw exceptions 367 assert(NULL == JSValueToObject(context, jsNull)); 368 assert(isnan(JSValueToNumber(context, jsObjectNoProto))); 369 assertEqualsAsCharactersPtr(jsObjectNoProto, ""); 379 exception = NULL; 380 assert(NULL == JSValueToObject(context, jsNull, &exception)); 381 assert(exception); 382 383 exception = NULL; 384 assert(isnan(JSValueToNumber(context, jsObjectNoProto, &exception))); 385 assert(exception); 386 387 exception = NULL; 388 assert(!JSValueToStringCopy(context, jsObjectNoProto, &exception)); 389 assert(exception); 390 391 exception = NULL; 392 assert(!JSValueToBoolean(context, myObject, &exception)); 393 assert(exception); 394 395 exception = NULL; 396 assert(!JSValueIsEqual(context, jsObjectNoProto, JSValueMakeNumber(1), &exception)); 397 assert(exception); 370 398 371 399 assertEqualsAsBoolean(jsUndefined, false); … … 437 465 assert(!JSValueIsStrictEqual(context, jsOne, jsOneString)); 438 466 439 assert(JSValueIsEqual(context, jsOne, jsOneString ));440 assert(!JSValueIsEqual(context, jsTrue, jsFalse ));467 assert(JSValueIsEqual(context, jsOne, jsOneString, NULL)); 468 assert(!JSValueIsEqual(context, jsTrue, jsFalse, NULL)); 441 469 442 470 #if defined(__APPLE__) … … 458 486 JSValueUnprotect(jsGlobalValue); 459 487 460 /* JSInterpreter.h */461 462 JSObjectRef globalObject = JSContextGetGlobalObject(context);463 assert(JSValueIsObject(globalObject));464 465 488 JSStringRef goodSyntax = JSStringCreateWithUTF8CString("x = 1;"); 466 489 JSStringRef badSyntax = JSStringCreateWithUTF8CString("x := 1;"); 467 assert(JSCheckS yntax(context, goodSyntax, NULL, 0, NULL));468 assert(!JSCheckS yntax(context, badSyntax, NULL, 0, NULL));490 assert(JSCheckScriptSyntax(context, goodSyntax, NULL, 0, NULL)); 491 assert(!JSCheckScriptSyntax(context, badSyntax, NULL, 0, NULL)); 469 492 470 493 JSValueRef result; 471 JSValueRef exception;472 494 JSValueRef v; 473 495 JSObjectRef o; 474 496 475 result = JSEvaluate (context, goodSyntax, NULL, NULL, 1, NULL);497 result = JSEvaluateScript(context, goodSyntax, NULL, NULL, 1, NULL); 476 498 assert(result); 477 assert(JSValueIsEqual(context, result, jsOne ));499 assert(JSValueIsEqual(context, result, jsOne, NULL)); 478 500 479 501 exception = NULL; 480 result = JSEvaluate (context, badSyntax, NULL, NULL, 1, &exception);502 result = JSEvaluateScript(context, badSyntax, NULL, NULL, 1, &exception); 481 503 assert(!result); 482 504 assert(JSValueIsObject(exception)); … … 485 507 v = JSObjectGetProperty(context, globalObject, array); 486 508 assert(v); 487 JSObjectRef arrayConstructor = JSValueToObject(context, v );509 JSObjectRef arrayConstructor = JSValueToObject(context, v, NULL); 488 510 JSStringRelease(array); 489 511 result = JSObjectCallAsConstructor(context, arrayConstructor, 0, NULL, NULL); … … 499 521 assert(!JSObjectMakeFunctionWithBody(context, functionBody, NULL, 1, &exception)); 500 522 assert(JSValueIsObject(exception)); 501 v = JSObjectGetProperty(context, JSValueToObject(context, exception ), line);523 v = JSObjectGetProperty(context, JSValueToObject(context, exception, NULL), line); 502 524 assert(v); 503 525 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) … … 511 533 assert(JSObjectIsFunction(function)); 512 534 v = JSObjectCallAsFunction(context, function, NULL, 0, NULL, NULL); 513 assert(JSValueIsEqual(context, v, arrayConstructor ));535 assert(JSValueIsEqual(context, v, arrayConstructor, NULL)); 514 536 515 JSObjectRef myObject = JSObjectMake(context, MyObject_class(context), NULL);516 assert(didInitialize);517 JSStringRef myObjectIString = JSStringCreateWithUTF8CString("MyObject");518 JSObjectSetProperty(context, globalObject, myObjectIString, myObject, kJSPropertyAttributeNone);519 JSStringRelease(myObjectIString);520 521 537 JSStringRef print = JSStringCreateWithUTF8CString("print"); 522 538 JSObjectRef printFunction = JSObjectMakeFunction(context, print_callAsFunction); … … 552 568 JSStringRelease(functionBody); 553 569 v = JSObjectCallAsFunction(context, function, NULL, 0, NULL, NULL); 554 assert(JSValueIsEqual(context, v, globalObject ));570 assert(JSValueIsEqual(context, v, globalObject, NULL)); 555 571 v = JSObjectCallAsFunction(context, function, o, 0, NULL, NULL); 556 assert(JSValueIsEqual(context, v, o ));572 assert(JSValueIsEqual(context, v, o, NULL)); 557 573 558 574 char* scriptUTF8 = createStringWithContentsOfFile("testapi.js"); 559 575 JSStringRef script = JSStringCreateWithUTF8CString(scriptUTF8); 560 result = JSEvaluate (context, script, NULL, NULL, 1, &exception);576 result = JSEvaluateScript(context, script, NULL, NULL, 1, &exception); 561 577 if (JSValueIsUndefined(result)) 562 578 printf("PASS: Test script executed successfully.\n"); 563 579 else { 564 580 printf("FAIL: Test script returned unexcpected value:\n"); 565 JSStringRef exceptionIString = JSValueToStringCopy(context, exception );581 JSStringRef exceptionIString = JSValueToStringCopy(context, exception, NULL); 566 582 CFStringRef exceptionCF = JSStringCopyCFString(kCFAllocatorDefault, exceptionIString); 567 583 CFShow(exceptionCF);
Note:
See TracChangeset
for help on using the changeset viewer.