tor-browser

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

body-dstr-assign-error.js (1438B)


      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-runtime-semantics-forin-div-ofheadevaluation-tdznames-expr-iterationkind
      5 description: >
      6    If the left-hand side requires a DestructuringAssignment operation and that
      7    operation produces an error, the iterator should be closed and the error
      8    forwarded to the runtime.
      9 info: |
     10  ...
     11  Else,
     12    If lhsKind is assignment, then
     13      Let status be the result of performing DestructuringAssignmentEvaluation of
     14      assignmentPattern using nextValue as the argument.
     15  ...
     16  If status is an abrupt completion, then
     17    Set the running execution context's LexicalEnvironment to oldEnv.
     18    If iterationKind is enumerate, then
     19      Return status.
     20 
     21 features: [destructuring-assignment, for-of, Symbol.iterator]
     22 ---*/
     23 
     24 var callCount = 0;
     25 var iterationCount = 0;
     26 var iterable = {};
     27 var x = {
     28  set attr(_) {
     29    throw new Test262Error();
     30  }
     31 };
     32 
     33 iterable[Symbol.iterator] = function() {
     34  return {
     35    next: function() {
     36      return { done: false, value: [0] };
     37    },
     38    return: function() {
     39      callCount += 1;
     40    }
     41  }
     42 };
     43 
     44 assert.throws(Test262Error, function() {
     45  for ([x.attr] of iterable) {
     46    iterationCount += 1;
     47  }
     48 });
     49 
     50 assert.sameValue(iterationCount, 0, 'The loop body is not evaluated');
     51 assert.sameValue(callCount, 1, 'Iterator is closed');
     52 
     53 reportCompare(0, 0);