tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

resolve-prms-cstm-then-deferred.js (1505B)


      1 // |reftest| async
      2 // Copyright (C) 2016 the V8 project authors. All rights reserved.
      3 // This code is governed by the BSD license found in the LICENSE file.
      4 /*---
      5 description: >
      6    Resolving with a resolved Promise instance whose `then` method has been
      7    overridden after execution of the executor function
      8 es6id: 25.4.3.1
      9 info: |
     10    [...]
     11    8. Let resolvingFunctions be CreateResolvingFunctions(promise).
     12    9. Let completion be Call(executor, undefined,
     13       «resolvingFunctions.[[Resolve]], resolvingFunctions.[[Reject]]»).
     14 
     15    25.4.1.3.2 Promise Resolve Functions
     16    [...]
     17    8. Let then be Get(resolution, "then").
     18    9. If then is an abrupt completion, then
     19       [...]
     20    10. Let thenAction be then.[[value]].
     21    11. If IsCallable(thenAction) is false, then
     22        [...]
     23    12. Perform EnqueueJob ("PromiseJobs", PromiseResolveThenableJob,
     24        «promise, resolution, thenAction»)
     25 flags: [async]
     26 ---*/
     27 
     28 var returnValue = null;
     29 var value = {};
     30 var resolve;
     31 var thenable = new Promise(function(resolve) {
     32  resolve();
     33 });
     34 var promise = new Promise(function(_resolve) {
     35  resolve = _resolve;
     36 });
     37 
     38 thenable.then = function(resolve) {
     39  resolve(value);
     40 };
     41 
     42 promise.then(function(val) {
     43  if (val !== value) {
     44    $DONE('The promise should be fulfilled with the provided value.');
     45    return;
     46  }
     47 
     48  $DONE();
     49 }, function() {
     50  $DONE('The promise should not be rejected.');
     51 });
     52 
     53 returnValue = resolve(thenable);
     54 
     55 assert.sameValue(returnValue, undefined, '"resolve" return value');