Debian Codegraph @

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

raw
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: >
5 Resolving with an object with a "poisoned" `then` property after invocation
6 of the executor function
7 es6id: 25.4.3.1
8 info: |
9 [...]
10 8. Let resolvingFunctions be CreateResolvingFunctions(promise).
11 9. Let completion be Call(executor, undefined,
12 «resolvingFunctions.[[Resolve]], resolvingFunctions.[[Reject]]»).
13
14 25.4.1.3.2 Promise Resolve Functions
15 7. If Type(resolution) is not Object, then
16 a. Return FulfillPromise(promise, resolution).
17 flags: [async]
18 ---*/
19
20 var returnValue = null;
21 var value = {};
22 var resolve;
23 var poisonedThen = Object.defineProperty({}, 'then', {
24 get: function() {
25 throw value;
26 }
27 });
28 var promise = new Promise(function(_resolve) {
29 resolve = _resolve;
30 });
31
32 promise.then(function() {
33 $DONE('The promise should not be fulfilled.');
34 }, function(val) {
35 if (val !== value) {
36 $DONE('The promise should be fulfilled with the provided value.');
37 return;
38 }
39
40 $DONE();
41 });
42
43 returnValue = resolve(poisonedThen);
44
45 assert.sameValue(returnValue, undefined, '"resolve" return value');