tor-browser

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

invoke-then-get-error-close.js (1333B)


      1 // Copyright (C) 2016 the V8 project authors. All rights reserved.
      2 // This code is governed by the BSD license found in the LICENSE file.
      3 /*---
      4 description: >
      5  Error thrown when accessing the instance's `then` method (closing iterator)
      6 esid: sec-promise.race
      7 info: |
      8    11. Let result be PerformPromiseRace(iteratorRecord, C, promiseCapability).
      9    12. If result is an abrupt completion,
     10        a. If iteratorRecord.[[done]] is false, let result be
     11           IteratorClose(iterator, result).
     12        b. IfAbruptRejectPromise(result, promiseCapability).
     13 
     14    [...]
     15 
     16    25.4.4.3.1 Runtime Semantics: PerformPromiseRace
     17 
     18    1. Repeat
     19        [...]
     20        j. Let result be Invoke(nextPromise, "then",
     21           «promiseCapability.[[Resolve]], promiseCapability.[[Reject]]»).
     22        k. ReturnIfAbrupt(result).
     23 features: [Symbol.iterator]
     24 ---*/
     25 
     26 var promise = new Promise(function() {});
     27 var iter = {};
     28 var returnCount = 0;
     29 iter[Symbol.iterator] = function() {
     30  return {
     31    next: function() {
     32      return {
     33        done: false,
     34        value: promise
     35      };
     36    },
     37    return: function() {
     38      returnCount += 1;
     39      return {};
     40    }
     41  };
     42 };
     43 Object.defineProperty(promise, 'then', {
     44  get: function() {
     45    throw new Test262Error();
     46  }
     47 });
     48 
     49 Promise.race(iter);
     50 
     51 assert.sameValue(returnCount, 1);
     52 
     53 reportCompare(0, 0);