tor-browser

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

star-rhs-iter-thrw-res-done-no-value.js (2437B)


      1 // Copyright (C) 2016 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-generator-function-definitions-runtime-semantics-evaluation
      5 description: >
      6  `value` property is not accessed when iteration is complete
      7 info: |
      8  YieldExpression : yield * AssignmentExpression
      9 
     10  1. Let exprRef be the result of evaluating AssignmentExpression.
     11  2. Let value be ? GetValue(exprRef).
     12  3. Let iterator be ? GetIterator(value).
     13  4. Let received be NormalCompletion(undefined).
     14  5. Repeat
     15     a. If received.[[Type]] is normal, then
     16        [...]
     17     b. Else if received.[[Type]] is throw, then
     18        i. Let throw be ? GetMethod(iterator, "throw").
     19        ii. If throw is not undefined, then
     20            1. Let innerResult be ? Call(throw, iterator, « received.[[Value]]
     21               »).
     22            2. NOTE: Exceptions from the inner iterator throw method are
     23               propagated. Normal completions from an inner throw method are
     24               processed similarly to an inner next.
     25            3. If Type(innerResult) is not Object, throw a TypeError exception.
     26            4. Let done be ? IteratorComplete(innerResult).
     27            5. If done is true, then
     28               a. Return ? IteratorValue(innerResult).
     29 
     30  7.4.3 IteratorComplete
     31 
     32  1. Assert: Type(iterResult) is Object.
     33  2. Return ToBoolean(? Get(iterResult, "done")).
     34 features: [generators, Symbol.iterator]
     35 ---*/
     36 
     37 var badIter = {};
     38 var callCount = 0;
     39 var spyValue = Object.defineProperty({ done: false }, 'value', {
     40  get: function() {
     41    callCount += 1;
     42  }
     43 });
     44 badIter[Symbol.iterator] = function() {
     45  return {
     46    next: function() {
     47      return { done: false };
     48    },
     49    throw: function() {
     50      return spyValue;
     51    }
     52  };
     53 };
     54 var delegationComplete = false;
     55 function* g() {
     56  yield * badIter;
     57  delegationComplete = true;
     58 }
     59 var iter = g();
     60 
     61 iter.next();
     62 assert.sameValue(callCount, 0, 'access count (first iteration)');
     63 assert.sameValue(
     64  delegationComplete, false, 'delegation ongoing (first iteration)'
     65 );
     66 
     67 iter.throw();
     68 assert.sameValue(callCount, 0, 'access count (second iteration)');
     69 assert.sameValue(
     70  delegationComplete, false, 'delegation ongoing (second iteration)'
     71 );
     72 
     73 spyValue.done = true;
     74 iter.throw();
     75 assert.sameValue(callCount, 1, 'access count (final iteration)');
     76 assert.sameValue(delegationComplete, true, 'delegation complete');
     77 
     78 reportCompare(0, 0);