tor-browser

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

star-rhs-iter-rtrn-res-done-err.js (1854B)


      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 accessing `done` property of iteration result
      8 info: |
      9  YieldExpression : yield * AssignmentExpression
     10 
     11  1. Let exprRef be the result of evaluating AssignmentExpression.
     12  2. Let value be ? GetValue(exprRef).
     13  3. Let iterator be ? GetIterator(value).
     14  4. Let received be NormalCompletion(undefined).
     15  5. Repeat
     16     a. If received.[[Type]] is normal, then
     17        [...]
     18     b. Else if received.[[Type]] is throw, then
     19        [...]
     20     c. Else,
     21        i. Assert: received.[[Type]] is return.
     22        ii. Let return be ? GetMethod(iterator, "return").
     23        iii. If return is undefined, return Completion(received).
     24        iv. Let innerReturnResult be ? Call(return, iterator, «
     25            received.[[Value]] »).
     26        v. If Type(innerReturnResult) is not Object, throw a TypeError
     27           exception.
     28        vi. Let done be ? IteratorComplete(innerReturnResult).
     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 thrown = new Test262Error();
     38 var badIter = {};
     39 var poisonedDone = Object.defineProperty({}, 'done', {
     40  get: function() {
     41    throw thrown;
     42  }
     43 });
     44 badIter[Symbol.iterator] = function() {
     45  return {
     46    next: function() {
     47      return { done: false };
     48    },
     49    return: function() {
     50      return poisonedDone;
     51    }
     52  };
     53 };
     54 function* g() {
     55  try {
     56    yield * badIter;
     57  } catch (err) {
     58    caught = err;
     59  }
     60 }
     61 var iter = g();
     62 var caught;
     63 
     64 iter.next();
     65 iter.return();
     66 
     67 assert.sameValue(caught, thrown);
     68 
     69 reportCompare(0, 0);