test262/implementation-contributed/javascriptcore/es6/Promise_basic_functionality.js
test262-automation e9a5a7f918 [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) (#1620)
* [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)
2018-07-03 15:59:58 -04:00

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");