tor-browser

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

iterator-close-after-set-failure.js (1004B)


      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-weakmap-iterable
      5 description: >
      6  Return IteratorClose(iter, status) if fail on adding value on constructing.
      7 info: |
      8  WeakMap ( [ iterable ] )
      9 
     10  ...
     11  9. Repeat
     12    k. Let status be Call(adder, map, «k.[[value]], v.[[value]]»).
     13    l. 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: [],
     24        done: false
     25      };
     26    },
     27    return: function() {
     28      count += 1;
     29    }
     30  };
     31 };
     32 WeakMap.prototype.set = function() {
     33  throw new Test262Error();
     34 };
     35 
     36 assert.throws(Test262Error, function() {
     37  new WeakMap(iterable);
     38 });
     39 
     40 assert.sameValue(
     41  count, 1,
     42  'The iterator is closed when `WeakMap.prototype.set` throws an error.'
     43 );
     44 
     45 reportCompare(0, 0);