| 1 |
// Copyright (C) 2016 the V8 project authors. All rights reserved. |
| 2 |
// This code is governed by the BSD license found in the LICENSE file. |
| 3 |
/*--- |
| 4 |
description: Resolving with a resolved Promise instance whose `then` method has been overridden |
| 5 |
es6id: 25.4.4.3 |
| 6 |
info: | |
| 7 |
[...] |
| 8 |
6. Let promiseCapability be NewPromiseCapability(C). |
| 9 |
[...] |
| 10 |
11. Let result be PerformPromiseRace(iteratorRecord, promiseCapability, C). |
| 11 |
[...] |
| 12 |
|
| 13 |
25.4.4.3.1 Runtime Semantics: PerformPromiseRace |
| 14 |
1. Repeat |
| 15 |
[...] |
| 16 |
j. Let result be Invoke(nextPromise, "then", |
| 17 |
«promiseCapability.[[Resolve]], promiseCapability.[[Reject]]»). |
| 18 |
|
| 19 |
25.4.1.3.2 Promise Resolve Functions |
| 20 |
[...] |
| 21 |
8. Let then be Get(resolution, "then"). |
| 22 |
9. If then is an abrupt completion, then |
| 23 |
[...] |
| 24 |
10. Let thenAction be then.[[value]]. |
| 25 |
11. If IsCallable(thenAction) is false, then |
| 26 |
[...] |
| 27 |
12. Perform EnqueueJob ("PromiseJobs", PromiseResolveThenableJob, |
| 28 |
«promise, resolution, thenAction») |
| 29 |
flags: [async] |
| 30 |
---*/ |
| 31 |
|
| 32 |
var value = {}; |
| 33 |
var thenableValue = { |
| 34 |
then: function(resolve) { |
| 35 |
resolve(value); |
| 36 |
} |
| 37 |
}; |
| 38 |
var thenable = new Promise(function(resolve) { |
| 39 |
resolve(); |
| 40 |
}); |
| 41 |
|
| 42 |
thenable.then = function(resolve) { |
| 43 |
resolve(thenableValue); |
| 44 |
}; |
| 45 |
|
| 46 |
Promise.race([thenable]) |
| 47 |
.then(function(val) { |
| 48 |
if (val !== value) { |
| 49 |
$DONE('The promise should be resolved with the correct value.'); |
| 50 |
return; |
| 51 |
} |
| 52 |
$DONE(); |
| 53 |
}, function() { |
| 54 |
$DONE('The promise should not be rejected.'); |
| 55 |
}); |