|
Lines 137-142
public:
a/Source/JavaScriptCore/API/tests/testapi.cpp_sec1
|
| 137 |
void symbolsDeletePropertyForKey(); |
137 |
void symbolsDeletePropertyForKey(); |
| 138 |
void promiseResolveTrue(); |
138 |
void promiseResolveTrue(); |
| 139 |
void promiseRejectTrue(); |
139 |
void promiseRejectTrue(); |
|
|
140 |
void promiseRejectionCallbacks(); |
| 140 |
|
141 |
|
| 141 |
int failed() const { return m_failed; } |
142 |
int failed() const { return m_failed; } |
| 142 |
|
143 |
|
|
Lines 454-460
void TestAPI::promiseResolveTrue()
a/Source/JavaScriptCore/API/tests/testapi.cpp_sec2
|
| 454 |
|
455 |
|
| 455 |
auto trueValue = JSValueMakeBoolean(context, true); |
456 |
auto trueValue = JSValueMakeBoolean(context, true); |
| 456 |
JSObjectCallAsFunction(context, resolve, resolve, 1, &trueValue, &exception); |
457 |
JSObjectCallAsFunction(context, resolve, resolve, 1, &trueValue, &exception); |
| 457 |
check(!exception, "No exception should be thrown resolve promise"); |
458 |
check(!exception, "No exception should be thrown resolving promise"); |
| 458 |
check(passedTrueCalled, "then response function should have been called."); |
459 |
check(passedTrueCalled, "then response function should have been called."); |
| 459 |
} |
460 |
} |
| 460 |
|
461 |
|
|
Lines 479-485
void TestAPI::promiseRejectTrue()
a/Source/JavaScriptCore/API/tests/testapi.cpp_sec3
|
| 479 |
|
480 |
|
| 480 |
APIString catchString("catch"); |
481 |
APIString catchString("catch"); |
| 481 |
JSValueRef catchFunction = JSObjectGetProperty(context, promise, catchString, &exception); |
482 |
JSValueRef catchFunction = JSObjectGetProperty(context, promise, catchString, &exception); |
| 482 |
check(!exception && catchFunction && JSValueIsObject(context, catchFunction), "Promise should have a then object property"); |
483 |
check(!exception && catchFunction && JSValueIsObject(context, catchFunction), "Promise should have a catch object property"); |
| 483 |
|
484 |
|
| 484 |
JSValueRef passedTrueFunction = JSObjectMakeFunctionWithCallback(context, trueString, passedTrue); |
485 |
JSValueRef passedTrueFunction = JSObjectMakeFunctionWithCallback(context, trueString, passedTrue); |
| 485 |
JSObjectCallAsFunction(context, const_cast<JSObjectRef>(catchFunction), promise, 1, &passedTrueFunction, &exception); |
486 |
JSObjectCallAsFunction(context, const_cast<JSObjectRef>(catchFunction), promise, 1, &passedTrueFunction, &exception); |
|
Lines 487-494
void TestAPI::promiseRejectTrue()
a/Source/JavaScriptCore/API/tests/testapi.cpp_sec4
|
| 487 |
|
488 |
|
| 488 |
auto trueValue = JSValueMakeBoolean(context, true); |
489 |
auto trueValue = JSValueMakeBoolean(context, true); |
| 489 |
JSObjectCallAsFunction(context, reject, reject, 1, &trueValue, &exception); |
490 |
JSObjectCallAsFunction(context, reject, reject, 1, &trueValue, &exception); |
| 490 |
check(!exception, "No exception should be thrown resolve promise"); |
491 |
check(!exception, "No exception should be thrown rejecting promise"); |
| 491 |
check(passedTrueCalled, "then response function should have been called."); |
492 |
check(passedTrueCalled, "catch response function should have been called."); |
|
|
493 |
} |
| 494 |
|
| 495 |
void TestAPI::promiseRejectionCallbacks() |
| 496 |
{ |
| 497 |
JSObjectRef reject; |
| 498 |
JSValueRef exception = nullptr; |
| 499 |
static auto promise = JSObjectMakeDeferredPromise(context, nullptr, &reject, &exception); |
| 500 |
check(!exception, "creating a (reject-only) deferred promise should not throw"); |
| 501 |
static auto reason = JSValueMakeString(context, APIString("reason")); |
| 502 |
|
| 503 |
static TestAPI* tester = this; |
| 504 |
static auto callbackCallCount = 0; |
| 505 |
|
| 506 |
auto callback = [](JSContextRef ctx, JSObjectRef, JSObjectRef, size_t argumentCount, const JSValueRef arguments[], JSValueRef*) -> JSValueRef { |
| 507 |
tester->check(argumentCount && JSValueIsStrictEqual(ctx, arguments[0], promise), "callback should receive rejected promise as first argument"); |
| 508 |
tester->check(argumentCount > 1 && JSValueIsStrictEqual(ctx, arguments[1], reason), "callback should receive rejection reason as second argument"); |
| 509 |
tester->check(argumentCount == 2, "callback should not receive a third argument"); |
| 510 |
callbackCallCount++; |
| 511 |
return JSValueMakeUndefined(ctx); |
| 512 |
}; |
| 513 |
auto callbackFunction = JSObjectMakeFunctionWithCallback(context, APIString("callback"), callback); |
| 514 |
|
| 515 |
JSGlobalContextSetUnhandledRejectionCallback(context, callbackFunction, &exception); |
| 516 |
check(!exception, "setting unhandled rejection callback should not throw"); |
| 517 |
|
| 518 |
JSObjectCallAsFunction(context, reject, reject, 1, &reason, &exception); |
| 519 |
check(!exception && callbackCallCount == 1, "unhandled rejection callback should be called upon unhandled rejection"); |
| 520 |
|
| 521 |
auto noopFunction = JSObjectMakeFunction(context, APIString("noop"), 0, nullptr, APIString(""), nullptr, 1, &exception); |
| 522 |
check(!exception, "creating a no-op function should not throw"); |
| 523 |
|
| 524 |
JSGlobalContextSetUnhandledRejectionCallback(context, noopFunction, &exception); |
| 525 |
check(!exception, "resetting unhandled rejection callback should not throw"); |
| 526 |
JSGlobalContextSetRejectionHandledCallback(context, callbackFunction, &exception); |
| 527 |
check(!exception, "setting rejection handled callback should not throw"); |
| 528 |
|
| 529 |
auto catchFunction = JSObjectGetProperty(context, promise, APIString("catch"), &exception); |
| 530 |
JSObjectCallAsFunction(context, const_cast<JSObjectRef>(catchFunction), promise, 1, &noopFunction, &exception); |
| 531 |
check(!exception && callbackCallCount == 2, "rejection handled callback should be called upon late-handled rejection"); |
| 492 |
} |
532 |
} |
| 493 |
|
533 |
|
| 494 |
#define RUN(test) do { \ |
534 |
#define RUN(test) do { \ |
|
Lines 521-526
int testCAPIViaCpp(const char* filter)
a/Source/JavaScriptCore/API/tests/testapi.cpp_sec5
|
| 521 |
RUN(symbolsDeletePropertyForKey()); |
561 |
RUN(symbolsDeletePropertyForKey()); |
| 522 |
RUN(promiseResolveTrue()); |
562 |
RUN(promiseResolveTrue()); |
| 523 |
RUN(promiseRejectTrue()); |
563 |
RUN(promiseRejectTrue()); |
|
|
564 |
RUN(promiseRejectionCallbacks()); |
| 524 |
|
565 |
|
| 525 |
if (tasks.isEmpty()) { |
566 |
if (tasks.isEmpty()) { |
| 526 |
dataLogLn("Filtered all tests: ERROR"); |
567 |
dataLogLn("Filtered all tests: ERROR"); |