tor-browser

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

resolve-poisoned-then.js (1240B)


      1 // |reftest| async
      2 // Copyright (C) 2019 Leo Balter. 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 esid: sec-promise.allsettled
      7 info: |
      8  Runtime Semantics: PerformPromiseAllSettled ( iteratorRecord, constructor, resultCapability )
      9 
     10  4. Let remainingElementsCount be a new Record { [[Value]]: 1 }.
     11  ...
     12  6.d ...
     13    ii. Set remainingElementsCount.[[value]] to remainingElementsCount.[[value]] − 1.
     14    iii. If remainingElementsCount.[[value]] is 0, then
     15      1. Let valuesArray be CreateArrayFromList(values).
     16      2. Perform ? Call(resultCapability.[[Resolve]], undefined, « valuesArray »).
     17  ...
     18 flags: [async]
     19 features: [Promise.allSettled]
     20 ---*/
     21 
     22 var value = {};
     23 var promise;
     24 
     25 try {
     26  Object.defineProperty(Array.prototype, 'then', {
     27    get() {
     28      throw value;
     29    },
     30    configurable: true
     31  });
     32 
     33  promise = Promise.allSettled([]);
     34 } finally {
     35  delete Array.prototype.then;
     36 }
     37 
     38 promise.then(function() {
     39  $DONE('The promise should not be fulfilled.');
     40 }, function(val) {
     41  if (val !== value) {
     42    $DONE('The promise should be rejected with the expected value.');
     43    return;
     44  }
     45 
     46  $DONE();
     47 });