2014-10-23 19:58:31 +02:00
|
|
|
// Copyright 2014 Cubane Canada, Inc. All rights reserved.
|
|
|
|
// See LICENSE for details.
|
|
|
|
|
|
|
|
/*---
|
2015-02-10 22:01:39 +01:00
|
|
|
es6id: S25.4.4.3_A7.2_T1
|
2014-10-23 19:58:31 +02:00
|
|
|
author: Sam Mikes
|
|
|
|
description: Promise.race([p1, p2]) settles when first settles
|
2017-06-23 17:06:32 +02:00
|
|
|
includes: [promiseHelper.js]
|
2016-02-12 18:59:51 +01:00
|
|
|
flags: [async]
|
2014-10-23 19:58:31 +02:00
|
|
|
---*/
|
|
|
|
|
|
|
|
var sequence = [];
|
|
|
|
|
|
|
|
var p1 = Promise.reject(1),
|
2018-02-15 21:11:21 +01:00
|
|
|
p2 = Promise.resolve(2),
|
|
|
|
p = Promise.race([p1, p2]);
|
2014-10-23 19:58:31 +02:00
|
|
|
|
|
|
|
sequence.push(1);
|
|
|
|
|
2018-02-15 21:11:21 +01:00
|
|
|
p.then(function() {
|
2021-07-21 21:48:13 +02:00
|
|
|
throw new Test262Error("Should not be fulfilled - expected rejection.");
|
2018-02-15 21:11:21 +01:00
|
|
|
}, function(arg) {
|
|
|
|
if (arg !== 1) {
|
2021-07-21 21:48:13 +02:00
|
|
|
throw new Test262Error("Expected rejection reason to be 1, got " + arg);
|
2018-02-15 21:11:21 +01:00
|
|
|
}
|
2014-10-23 19:58:31 +02:00
|
|
|
|
2018-02-15 21:11:21 +01:00
|
|
|
sequence.push(4);
|
2020-06-24 21:18:35 +02:00
|
|
|
assert.sameValue(sequence.length, 4);
|
2018-02-15 21:11:21 +01:00
|
|
|
checkSequence(sequence, "This happens second");
|
2014-10-23 19:58:31 +02:00
|
|
|
}).catch($DONE);
|
|
|
|
|
2018-02-15 21:11:21 +01:00
|
|
|
Promise.resolve().then(function() {
|
|
|
|
sequence.push(3);
|
2020-06-24 21:18:35 +02:00
|
|
|
assert.sameValue(sequence.length, 3);
|
2018-02-15 21:11:21 +01:00
|
|
|
checkSequence(sequence, "This happens first");
|
|
|
|
}).then(function() {
|
|
|
|
sequence.push(5);
|
2020-06-24 21:18:35 +02:00
|
|
|
assert.sameValue(sequence.length, 5);
|
2018-02-15 21:11:21 +01:00
|
|
|
checkSequence(sequence, "This happens third");
|
2014-10-23 19:58:31 +02:00
|
|
|
}).then($DONE, $DONE);
|
|
|
|
|
|
|
|
sequence.push(2);
|