tor-browser

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

iterator-close-non-throw-get-method-is-null.js (1115B)


      1 // Copyright (C) 2020 Alexey Shvayka. All rights reserved.
      2 // This code is governed by the BSD license found in the LICENSE file.
      3 /*---
      4 esid: sec-iteratorclose
      5 description: >
      6  If iterator's "return" method is `null`,
      7  received non-throw completion is forwarded to the runtime.
      8 info: |
      9  IteratorClose ( iteratorRecord, completion )
     10 
     11  [...]
     12  4. Let innerResult be GetMethod(iterator, "return").
     13  5. If innerResult.[[Type]] is normal,
     14    a. Let return be innerResult.[[Value]].
     15    b. If return is undefined, return Completion(completion).
     16 
     17  GetMethod ( V, P )
     18 
     19  [...]
     20  2. Let func be ? GetV(V, P).
     21  3. If func is either undefined or null, return undefined.
     22 features: [Symbol.iterator]
     23 ---*/
     24 
     25 var iterationCount = 0;
     26 var returnGets = 0;
     27 
     28 var iterable = {};
     29 iterable[Symbol.iterator] = function() {
     30  return {
     31    next: function() {
     32      return {value: 1, done: false};
     33    },
     34    get return() {
     35      returnGets += 1;
     36      return null;
     37    },
     38  };
     39 };
     40 
     41 for (var _ of iterable) {
     42  iterationCount += 1;
     43  break;
     44 }
     45 
     46 assert.sameValue(iterationCount, 1);
     47 assert.sameValue(returnGets, 1);
     48 
     49 reportCompare(0, 0);