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