tor-browser

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

star-rhs-iter-thrw-violation-rtrn-call-err.js (2375B)


      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: >
      7  Abrupt completion returned when invoking iterator `return` method following
      8  protocol violation
      9 info: |
     10  YieldExpression : yield * AssignmentExpression
     11 
     12  1. Let exprRef be the result of evaluating AssignmentExpression.
     13  2. Let value be ? GetValue(exprRef).
     14  3. Let iterator be ? GetIterator(value).
     15  4. Let received be NormalCompletion(undefined).
     16  5. Repeat
     17     a. If received.[[Type]] is normal, then
     18        [...]
     19     b. Else if received.[[Type]] is throw, then
     20        i. Let throw be ? GetMethod(iterator, "throw").
     21        ii. If throw is not undefined, then
     22            [...]
     23        iii. Else,
     24             1. NOTE: If iterator does not have a throw method, this throw is
     25                going to terminate the yield* loop. But first we need to give
     26                iterator a chance to clean up.
     27             2. Perform ? IteratorClose(iterator, Completion{[[Type]]: normal,
     28                [[Value]]: empty, [[Target]]: empty}).
     29 
     30  7.4.6 IteratorClose
     31 
     32  1. Assert: Type(iterator) is Object.
     33  2. Assert: completion is a Completion Record.
     34  3. Let return be ? GetMethod(iterator, "return").
     35  4. If return is undefined, return Completion(completion).
     36  5. Let innerResult be Call(return, iterator, « »).
     37  6. If completion.[[Type]] is throw, return Completion(completion).
     38  7. If innerResult.[[Type]] is throw, return Completion(innerResult).
     39  8. If Type(innerResult.[[Value]]) is not Object, throw a TypeError exception.
     40 features: [generators, Symbol.iterator]
     41 ---*/
     42 
     43 var badIter = {};
     44 badIter[Symbol.iterator] = function() {
     45  return {
     46    next: function() {
     47      return { done: false };
     48    },
     49    return: function() {
     50      // Using a primitive completion value ensures that the check for the type
     51      // of the completion value (and resulting TypeError) occurs *after* the
     52      // check for the type of the completion itself (which is the behavior
     53      // under test).
     54      throw 87;
     55    }
     56  };
     57 };
     58 function* g() {
     59  try {
     60    yield * badIter;
     61  } catch (err) {
     62    caught = err;
     63  }
     64 }
     65 var iter = g();
     66 var caught;
     67 
     68 iter.next();
     69 iter.throw();
     70 
     71 assert.sameValue(caught, 87);
     72 
     73 reportCompare(0, 0);