tor-browser

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

resolve-poisoned-then.js (1304B)


      1 // |reftest| async
      2 // Copyright (C) 2015 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 an object with a "poisoned" `then` property
      6 es6id: 25.4.4.3
      7 info: |
      8    [...]
      9    6. Let promiseCapability be NewPromiseCapability(C).
     10    [...]
     11    11. Let result be PerformPromiseRace(iteratorRecord, promiseCapability, C).
     12    [...]
     13 
     14    25.4.4.3.1 Runtime Semantics: PerformPromiseRace
     15    1. Repeat
     16       [...]
     17       j. Let result be Invoke(nextPromise, "then",
     18          «promiseCapability.[[Resolve]], promiseCapability.[[Reject]]»).
     19 
     20    25.4.1.3.2 Promise Resolve Functions
     21    [...]
     22    8. Let then be Get(resolution, "then").
     23    9. If then is an abrupt completion, then
     24       a. Return RejectPromise(promise, then.[[value]]).
     25 flags: [async]
     26 ---*/
     27 
     28 var value = {};
     29 var poisonedThen = Object.defineProperty({}, 'then', {
     30  get: function() {
     31    throw value;
     32  }
     33 });
     34 var thenable = {
     35  then: function(resolve) {
     36    resolve(poisonedThen);
     37  }
     38 };
     39 
     40 Promise.race([thenable])
     41  .then(function() {
     42    $DONE('The promise should not be fulfilled.');
     43  }, function(val) {
     44    if (val !== value) {
     45      $DONE('The promise should be rejected with the correct value.');
     46      return;
     47    }
     48    $DONE();
     49  });