(func, name, properties)
| 574 | } |
| 575 | |
| 576 | function promise_test(func, name, properties) { |
| 577 | if (typeof func !== "function") { |
| 578 | properties = name; |
| 579 | name = func; |
| 580 | func = null; |
| 581 | } |
| 582 | var test_name = name ? name : test_environment.next_default_test_name(); |
| 583 | var test = new Test(test_name, properties); |
| 584 | test._is_promise_test = true; |
| 585 | |
| 586 | // If there is no promise tests queue make one. |
| 587 | if (!tests.promise_tests) { |
| 588 | tests.promise_tests = Promise.resolve(); |
| 589 | } |
| 590 | tests.promise_tests = tests.promise_tests.then(function() { |
| 591 | return new Promise(function(resolve) { |
| 592 | var promise = test.step(func, test, test); |
| 593 | |
| 594 | test.step(function() { |
| 595 | assert(!!promise, "promise_test", null, |
| 596 | "test body must return a 'thenable' object (received ${value})", |
| 597 | {value:promise}); |
| 598 | assert(typeof promise.then === "function", "promise_test", null, |
| 599 | "test body must return a 'thenable' object (received an object with no `then` method)", |
| 600 | null); |
| 601 | }); |
| 602 | |
| 603 | // Test authors may use the `step` method within a |
| 604 | // `promise_test` even though this reflects a mixture of |
| 605 | // asynchronous control flow paradigms. The "done" callback |
| 606 | // should be registered prior to the resolution of the |
| 607 | // user-provided Promise to avoid timeouts in cases where the |
| 608 | // Promise does not settle but a `step` function has thrown an |
| 609 | // error. |
| 610 | add_test_done_callback(test, resolve); |
| 611 | |
| 612 | Promise.resolve(promise) |
| 613 | .catch(test.step_func( |
| 614 | function(value) { |
| 615 | if (value instanceof AssertionError) { |
| 616 | throw value; |
| 617 | } |
| 618 | assert(false, "promise_test", null, |
| 619 | "Unhandled rejection with value: ${value}", {value:value}); |
| 620 | })) |
| 621 | .then(function() { |
| 622 | test.done(); |
| 623 | }); |
| 624 | }); |
| 625 | }); |
| 626 | } |
| 627 | |
| 628 | /** |
| 629 | * Make a copy of a Promise in the current realm. |
nothing calls this directly
no test coverage detected