tor-browser

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

iterator-close-after-add-failure.js (991B)


      1 // Copyright (C) 2015 the V8 project authors. All rights reserved.
      2 // This code is governed by the BSD license found in the LICENSE file.
      3 /*---
      4 esid: sec-weakset-iterable
      5 description: >
      6  Return IteratorClose(iter, status) if fail on adding value on constructing.
      7 info: |
      8  WeakSet ( [ iterable ] )
      9 
     10  ...
     11  9. Repeat
     12    f. Let status be Call(adder, set, «nextValue»).
     13    g. If status is an abrupt completion, return IteratorClose(iter, status).
     14 features: [Symbol.iterator]
     15 ---*/
     16 
     17 var count = 0;
     18 var iterable = {};
     19 iterable[Symbol.iterator] = function() {
     20  return {
     21    next: function() {
     22      return {
     23        value: null,
     24        done: false
     25      };
     26    },
     27    return: function() {
     28      count += 1;
     29    }
     30  };
     31 };
     32 WeakSet.prototype.add = function() {
     33  throw new Test262Error();
     34 };
     35 
     36 assert.throws(Test262Error, function() {
     37  new WeakSet(iterable);
     38 });
     39 
     40 assert.sameValue(
     41  count, 1,
     42  'The iterator is closed when `WeakSet.prototype.add` throws an error.'
     43 );
     44 
     45 reportCompare(0, 0);