tor-browser

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

iterator-closed-for-throwing-entry-key-accessor.js (1554B)


      1 // Copyright (C) 2018 Kevin Gibbons. All rights reserved.
      2 // This code is governed by the BSD license found in the LICENSE file.
      3 
      4 /*---
      5 esid: sec-object.fromentries
      6 description: Closes iterators when accessing an entry's key throws.
      7 info: |
      8  Object.fromEntries ( iterable )
      9 
     10  ...
     11  4. Let stepsDefine be the algorithm steps defined in CreateDataPropertyOnObject Functions.
     12  5. Let adder be CreateBuiltinFunction(stepsDefine, « »).
     13  6. Return ? AddEntriesFromIterable(obj, iterable, adder).
     14 
     15  AddEntriesFromIterable ( target, iterable, adder )
     16 
     17  ...
     18  4. Repeat,
     19    ...
     20    e. Let k be Get(nextItem, "0").
     21    f. If k is an abrupt completion, return ? IteratorClose(iteratorRecord, k).
     22 
     23 features: [Symbol.iterator, Object.fromEntries]
     24 ---*/
     25 
     26 function DummyError() {}
     27 
     28 var returned = false;
     29 var iterable = {
     30  [Symbol.iterator]: function() {
     31    var advanced = false;
     32    return {
     33      next: function() {
     34        if (advanced) {
     35          throw new Test262Error('should only advance once');
     36        }
     37        advanced = true;
     38        return {
     39          done: false,
     40          value: {
     41            get '0'() {
     42              throw new DummyError();
     43            },
     44          },
     45        };
     46      },
     47      return: function() {
     48        if (returned) {
     49          throw new Test262Error('should only return once');
     50        }
     51        returned = true;
     52      },
     53    };
     54  },
     55 };
     56 
     57 assert.throws(DummyError, function() {
     58  Object.fromEntries(iterable);
     59 });
     60 
     61 assert(returned, 'iterator should be closed when entry property access throws');
     62 
     63 reportCompare(0, 0);