Debian Codegraph @

tests/auto/qml/ecmascripttests/test262/test/built-ins/Promise/race/resolve-poisoned-then.js

raw
1 // Copyright (C) 2015 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 an object with a "poisoned" `then` property
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 a. Return RejectPromise(promise, then.[[value]]).
24 flags: [async]
25 ---*/
26
27 var value = {};
28 var poisonedThen = Object.defineProperty({}, 'then', {
29 get: function() {
30 throw value;
31 }
32 });
33 var thenable = {
34 then: function(resolve) {
35 resolve(poisonedThen);
36 }
37 };
38
39 Promise.race([thenable])
40 .then(function() {
41 $DONE('The promise should not be fulfilled.');
42 }, function(val) {
43 if (val !== value) {
44 $DONE('The promise should be rejected with the correct value.');
45 return;
46 }
47 $DONE();
48 });