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-tostring.js (1587B)


      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 toString on a 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            0: {
     42              toString: function() {
     43                throw new DummyError();
     44              },
     45            },
     46          },
     47        };
     48      },
     49      return: function() {
     50        if (returned) {
     51          throw new Test262Error('should only return once');
     52        }
     53        returned = true;
     54      },
     55    };
     56  },
     57 };
     58 
     59 assert.throws(DummyError, function() {
     60  Object.fromEntries(iterable);
     61 });
     62 
     63 assert(returned, 'iterator should be closed when key toString throws');
     64 
     65 reportCompare(0, 0);