mirror of
https://github.com/tc39/test262.git
synced 2025-04-08 19:35:28 +02:00
* [javascriptcore-test262-automation] changes from git@github.com:WebKit/webkit.git at sha 949e26452cfa153a7f4afe593da97e2fe9e1b706 on Tue Jul 03 2018 14:35:15 GMT-0400 (Eastern Daylight Time)
37 lines
820 B
JavaScript
37 lines
820 B
JavaScript
function test() {
|
|
var passed = false;
|
|
function asyncTestPassed() {
|
|
passed = true;
|
|
}
|
|
|
|
var p1 = new Promise(function(resolve, reject) { resolve("foo"); });
|
|
var p2 = new Promise(function(resolve, reject) { reject("quux"); });
|
|
var score = 0;
|
|
|
|
function thenFn(result) { score += (result === "foo"); check(); }
|
|
function catchFn(result) { score += (result === "quux"); check(); }
|
|
function shouldNotRun(result) { score = -Infinity; }
|
|
|
|
p1.then(thenFn, shouldNotRun);
|
|
p2.then(shouldNotRun, catchFn);
|
|
p1.catch(shouldNotRun);
|
|
p2.catch(catchFn);
|
|
|
|
p1.then(function() {
|
|
// Promise.prototype.then() should return a new Promise
|
|
score += p1.then() !== p1;
|
|
check();
|
|
});
|
|
|
|
function check() {
|
|
if (score === 4) asyncTestPassed();
|
|
}
|
|
|
|
drainMicrotasks();
|
|
return passed;
|
|
}
|
|
|
|
if (!test())
|
|
throw new Error("Test failed");
|
|
|