tor-browser

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

star-rhs-iter-rtrn-rtrn-invoke.js (1605B)


      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 es6id: 14.4.14
      6 description: Invocation of iterator `return` method
      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        [...]
     19     c. Else,
     20        i. Assert: received.[[Type]] is return.
     21        ii. Let return be ? GetMethod(iterator, "return").
     22        iii. If return is undefined, return Completion(received).
     23        iv. Let innerReturnResult be ? Call(return, iterator, «
     24            received.[[Value]] »).
     25        [...]
     26 features: [generators, Symbol.iterator]
     27 ---*/
     28 
     29 var args, thisValue;
     30 var callCount = 0;
     31 var spyIterator = {
     32  next: function() {
     33    return { done: false };
     34  },
     35  return: function() {
     36    callCount += 1;
     37    args = arguments;
     38    thisValue = this;
     39    return { done: true };
     40  }
     41 };
     42 var spyIterable = {};
     43 spyIterable[Symbol.iterator] = function() {
     44  return spyIterator;
     45 };
     46 function* g() {
     47  yield * spyIterable;
     48 }
     49 var iter = g();
     50 
     51 iter.next(8888);
     52 iter.return(7777);
     53 
     54 assert.sameValue(callCount, 1);
     55 assert.sameValue(args.length, 1);
     56 assert.sameValue(args[0], 7777);
     57 assert.sameValue(thisValue, spyIterator);
     58 
     59 reportCompare(0, 0);