tor-browser

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

iterator-close-throw-get-method-non-callable.js (1547B)


      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  3. If func is either undefined or null, return undefined.
     24  4. If IsCallable(func) is false, throw a TypeError exception.
     25 features: [async-iteration]
     26 flags: [async]
     27 ---*/
     28 
     29 const asyncIterable = {};
     30 asyncIterable[Symbol.asyncIterator] = function() {
     31  return {
     32    next: function() {
     33      return { done: false, value: null };
     34    },
     35    return: true,
     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);