tor-browser

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

star-rhs-iter-thrw-thrw-get-err.js (1454B)


      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: Abrupt completion returned when accessing iterator `throw` 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        i. Let throw be ? GetMethod(iterator, "throw").
     19 features: [generators, Symbol.iterator]
     20 ---*/
     21 
     22 var thrown = new Test262Error();
     23 var badIter = {};
     24 var poisonedThrow = {
     25  next: function() {
     26    return { done: false };
     27  }
     28 };
     29 Object.defineProperty(poisonedThrow, 'throw', {
     30  get: function() {
     31    throw thrown;
     32  }
     33 });
     34 badIter[Symbol.iterator] = function() {
     35  return poisonedThrow;
     36 };
     37 function* g() {
     38  try {
     39    yield * badIter;
     40  } catch (err) {
     41    caught = err;
     42  }
     43 }
     44 var iter = g();
     45 var result, caught;
     46 
     47 iter.next();
     48 
     49 assert.sameValue(caught, undefined, '`throw` property not accesed eagerly');
     50 
     51 result = iter.throw();
     52 
     53 assert.sameValue(result.value, undefined);
     54 assert.sameValue(result.done, true);
     55 assert.sameValue(caught, thrown);
     56 
     57 reportCompare(0, 0);