Debian Codegraph @

tests/auto/qml/ecmascripttests/test262/test/built-ins/Promise/race/resolve-self.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 a reference to the promise itself
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 6. If SameValue(resolution, promise) is true, then
22 a. Let selfResolutionError be a newly created TypeError object.
23 b. Return RejectPromise(promise, selfResolutionError).
24 flags: [async]
25 ---*/
26
27 var self, resolve;
28 var builtinResolve = Promise.resolve;
29 var thenable = {
30 then: function(r) {
31 resolve = r;
32 }
33 };
34
35 try {
36 Promise.resolve = function(v) {
37 return v;
38 };
39 self = Promise.race([thenable]);
40 } finally {
41 Promise.resolve = builtinResolve;
42 }
43
44 resolve(self);
45
46 self.then(function() {
47 $DONE('The promise should not be fulfilled.');
48 }, function(value) {
49 if (!value) {
50 $DONE('The promise should be rejected with a value.');
51 return;
52 }
53 if (value.constructor !== TypeError) {
54 $DONE('The promise should be rejected with a TypeError instance.');
55 return;
56 }
57 $DONE();
58 });