| 848 | } |
| 849 | |
| 850 | function promise_setup(func, maybe_properties) |
| 851 | { |
| 852 | if (typeof func !== "function") { |
| 853 | tests.set_status(tests.status.ERROR, |
| 854 | "promise_test invoked without a function"); |
| 855 | tests.complete(); |
| 856 | return; |
| 857 | } |
| 858 | tests.promise_setup_called = true; |
| 859 | |
| 860 | if (!tests.promise_tests) { |
| 861 | tests.promise_tests = Promise.resolve(); |
| 862 | } |
| 863 | |
| 864 | tests.promise_tests = tests.promise_tests |
| 865 | .then(function() |
| 866 | { |
| 867 | var properties = maybe_properties || {}; |
| 868 | var result; |
| 869 | |
| 870 | tests.setup(null, properties); |
| 871 | result = func(); |
| 872 | test_environment.on_new_harness_properties(properties); |
| 873 | |
| 874 | if (!result || typeof result.then !== "function") { |
| 875 | throw "Non-thenable returned by function passed to `promise_setup`"; |
| 876 | } |
| 877 | return result; |
| 878 | }) |
| 879 | .catch(function(e) |
| 880 | { |
| 881 | tests.set_status(tests.status.ERROR, |
| 882 | String(e), |
| 883 | e && e.stack); |
| 884 | tests.complete(); |
| 885 | }); |
| 886 | } |
| 887 | |
| 888 | function done() { |
| 889 | if (tests.tests.length === 0) { |