tor-browser

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

iterator-close-throw-get-method-abrupt.js (1468B)


      1 // |reftest| async
      2 // Copyright (C) 2020 Alexey Shvayka. All rights reserved.
      3 // This code is governed by the BSD license found in the LICENSE file.
      4 /*---
      5 esid: sec-asynciteratorclose
      6 description: >
      7  If retrieving an iterator's `return` method generates an error while
      8  closing the iterator with throw completion, this error should be suppressed.
      9 info: |
     10  AsyncIteratorClose ( iteratorRecord, completion )
     11 
     12  [...]
     13  4. Let innerResult be GetMethod(iterator, "return").
     14  5. If innerResult.[[Type]] is normal,
     15    [...]
     16  6. If completion.[[Type]] is throw, return Completion(completion).
     17  7. If innerResult.[[Type]] is throw, return Completion(innerResult).
     18 
     19  GetMethod ( V, P )
     20 
     21  [...]
     22  2. Let func be ? GetV(V, P).
     23 features: [async-iteration]
     24 flags: [async]
     25 ---*/
     26 
     27 const asyncIterable = {};
     28 asyncIterable[Symbol.asyncIterator] = function() {
     29  return {
     30    next: function() {
     31      return { done: false, value: null };
     32    },
     33    get return() {
     34      throw { name: "inner error" };
     35    },
     36  };
     37 };
     38 
     39 let iterationCount = 0;
     40 const promise = (async function() {
     41  for await (const x of asyncIterable) {
     42    iterationCount += 1;
     43    throw new Test262Error("should not be overriden");
     44  }
     45 })();
     46 
     47 promise.then(function(value) {
     48  throw new Test262Error("Promise should be rejected, got: " + value);
     49 }, function(error) {
     50  assert.sameValue(error.constructor, Test262Error);
     51  assert.sameValue(iterationCount, 1, "The loop body is evaluated");
     52 }).then($DONE, $DONE);