tor-browser

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

star-rhs-iter-thrw-res-value-err.js (2034B)


      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 `value` property of iteration
      8  result
      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            1. Let innerResult be ? Call(throw, iterator, « received.[[Value]]
     23               »).
     24            2. NOTE: Exceptions from the inner iterator throw method are
     25               propagated. Normal completions from an inner throw method are
     26               processed similarly to an inner next.
     27            3. If Type(innerResult) is not Object, throw a TypeError exception.
     28            4. Let done be ? IteratorComplete(innerResult).
     29            5. If done is true, then
     30               a. Return ? IteratorValue(innerResult).
     31 
     32  7.4.4 IteratorValue
     33 
     34  1. Assert: Type(iterResult) is Object.
     35  2. Return ? Get(iterResult, "value").
     36 features: [generators, Symbol.iterator]
     37 ---*/
     38 
     39 var thrown = new Test262Error();
     40 var badIter = {};
     41 var poisonedValue = Object.defineProperty({ done: true }, 'value', {
     42  get: function() {
     43    throw thrown;
     44  }
     45 });
     46 badIter[Symbol.iterator] = function() {
     47  return {
     48    next: function() {
     49      return { done: false };
     50    },
     51    throw: function() {
     52      return poisonedValue;
     53    }
     54  };
     55 };
     56 function* g() {
     57  try {
     58    yield * badIter;
     59  } catch (err) {
     60    caught = err;
     61  }
     62 }
     63 var iter = g();
     64 var caught;
     65 
     66 iter.next();
     67 iter.throw();
     68 
     69 assert.sameValue(caught, thrown);
     70 
     71 reportCompare(0, 0);