tor-browser

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

resolve-thenable.js (2048B)


      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: Resolving with a thenable object value
      6 es6id: 25.4.4.1
      7 info: |
      8    [...]
      9    6. Let promiseCapability be NewPromiseCapability(C).
     10    [...]
     11    11. Let result be PerformPromiseAll(iteratorRecord, C, promiseCapability).
     12    [...]
     13 
     14    25.4.4.1.1 Runtime Semantics: PerformPromiseAll
     15    [...]
     16    6. Repeat
     17       [...]
     18       d. If next is false,
     19          [...]
     20          iii. If remainingElementsCount.[[value]] is 0,
     21             1. Let valuesArray be CreateArrayFromList(values).
     22             2. Let resolveResult be Call(resultCapability.[[Resolve]],
     23                undefined, «valuesArray»).
     24             3. ReturnIfAbrupt(resolveResult)
     25          iv. Return resultCapability.[[Promise]].
     26 
     27    7.3.16 CreateArrayFromList (elements)
     28    [...]
     29    2. Let array be ArrayCreate(0) (see 9.4.2.2).
     30 
     31    9.4.2.2 ArrayCreate(length, proto)
     32    [...]
     33    4. If the proto argument was not passed, let proto be the intrinsic object
     34       %ArrayPrototype%.
     35    5. Let A be a newly created Array exotic object.
     36    [...]
     37    8. Set the [[Prototype]] internal slot of A to proto.
     38 
     39    25.4.1.3.2 Promise Resolve Functions
     40    [...]
     41    8. Let then be Get(resolution, "then").
     42    9. If then is an abrupt completion, then
     43       [...]
     44    10. Let thenAction be then.[[value]].
     45    11. If IsCallable(thenAction) is false, then
     46        [...]
     47    12. Perform EnqueueJob ("PromiseJobs", PromiseResolveThenableJob,
     48        «promise, resolution, thenAction»)
     49 flags: [async]
     50 ---*/
     51 
     52 var value = {};
     53 var promise;
     54 
     55 try {
     56  Array.prototype.then = function(resolve) {
     57    resolve(value);
     58  };
     59 
     60  promise = Promise.all([]);
     61 } finally {
     62  delete Array.prototype.then;
     63 }
     64 
     65 promise.then(function(val) {
     66  if (val !== value) {
     67    $DONE('The promise should be resolved with the expected value.');
     68    return;
     69  }
     70 
     71  $DONE();
     72 }, function() {
     73  $DONE('The promise should not be rejected.');
     74 });