| 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 reference to the promise itself |
| 5 |
es6id: 25.4.4.5 |
| 6 |
info: | |
| 7 |
1. Let C be the this value. |
| 8 |
[...] |
| 9 |
4. Let promiseCapability be NewPromiseCapability(C). |
| 10 |
[...] |
| 11 |
6. Let resolveResult be Call(promiseCapability.[[Resolve]], undefined, |
| 12 |
«x»). |
| 13 |
[...] |
| 14 |
|
| 15 |
25.4.1.3.2 Promise Resolve Functions |
| 16 |
[...] |
| 17 |
6. If SameValue(resolution, promise) is true, then |
| 18 |
a. Let selfResolutionError be a newly created TypeError object. |
| 19 |
b. Return RejectPromise(promise, selfResolutionError). |
| 20 |
flags: [async] |
| 21 |
---*/ |
| 22 |
|
| 23 |
var resolve, reject; |
| 24 |
var promise = new Promise(function(_resolve, _reject) { |
| 25 |
resolve = _resolve; |
| 26 |
reject = _reject; |
| 27 |
}); |
| 28 |
var P = function(executor) { |
| 29 |
executor(resolve, reject); |
| 30 |
return promise; |
| 31 |
}; |
| 32 |
|
| 33 |
Promise.resolve.call(P, promise) |
| 34 |
.then(function() { |
| 35 |
$DONE('The promise should not be fulfilled.'); |
| 36 |
}, function(value) { |
| 37 |
if (!value) { |
| 38 |
$DONE('The promise should be rejected with a value.'); |
| 39 |
return; |
| 40 |
} |
| 41 |
if (value.constructor !== TypeError) { |
| 42 |
$DONE('The promise should be rejected with a TypeError instance.'); |
| 43 |
return; |
| 44 |
} |
| 45 |
|
| 46 |
$DONE(); |
| 47 |
}); |