diff options
author | Mike Pennisi <mike@mikepennisi.com> | 2015-12-30 14:15:01 -0500 |
---|---|---|
committer | Gorkem Yakin <goyakin@microsoft.com> | 2016-01-19 16:32:36 -0800 |
commit | b1b4f04494fa15ecca154805c9422a42c447b1c4 (patch) | |
tree | 4247d471b8b47143d90ebf2546c7eb60f6e9a087 /test/built-ins/Promise/race/resolve-self.js | |
parent | a5bf19486a6e5a58193580c088fb715baa57f90e (diff) | |
download | qtdeclarative-testsuites-b1b4f04494fa15ecca154805c9422a42c447b1c4.tar.gz |
Add tests for Promise Resolve Functions
Remove files that tested both PerformPromiseThen and
PromiseResolveFunction in favor of new tests that test
PromiseResolveFunction more directly and completely.
Diffstat (limited to 'test/built-ins/Promise/race/resolve-self.js')
-rw-r--r-- | test/built-ins/Promise/race/resolve-self.js | 54 |
1 files changed, 54 insertions, 0 deletions
diff --git a/test/built-ins/Promise/race/resolve-self.js b/test/built-ins/Promise/race/resolve-self.js new file mode 100644 index 000000000..511a03200 --- /dev/null +++ b/test/built-ins/Promise/race/resolve-self.js @@ -0,0 +1,54 @@ +// This code is governed by the BSD license found in the LICENSE file. +/*--- +description: Resolving with a reference to the promise itself +es6id: 25.4.4.3 +info: > + [...] + 6. Let promiseCapability be NewPromiseCapability(C). + [...] + 11. Let result be PerformPromiseRace(iteratorRecord, promiseCapability, C). + [...] + + 25.4.4.3.1 Runtime Semantics: PerformPromiseRace + 1. Repeat + [...] + j. Let result be Invoke(nextPromise, "then", + «promiseCapability.[[Resolve]], promiseCapability.[[Reject]]»). + + 25.4.1.3.2 Promise Resolve Functions + [...] + 6. If SameValue(resolution, promise) is true, then + a. Let selfResolutionError be a newly created TypeError object. + b. Return RejectPromise(promise, selfResolutionError). +---*/ + +var self, resolve; +var builtinResolve = Promise.resolve; +var thenable = { + then: function(r) { + resolve = r; + } +}; + +try { + Promise.resolve = function(v) { return v; }; + self = Promise.race([thenable]); +} finally { + Promise.resolve = builtinResolve; +} + +resolve(self); + +self.then(function() { + $DONE('The promise should not be fulfilled.'); + }, function(value) { + if (!value) { + $DONE('The promise should be rejected with a value.'); + return; + } + if (value.constructor !== TypeError) { + $DONE('The promise should be rejected with a TypeError instance.'); + return; + } + $DONE(); + }); |