star-rhs-iter-rtrn-rtrn-call-err.js (1553B)
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 invoking iterator `return` 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 [...] 19 c. Else, 20 i. Assert: received.[[Type]] is return. 21 ii. Let return be ? GetMethod(iterator, "return"). 22 iii. If return is undefined, return Completion(received). 23 iv. Let innerReturnResult be ? Call(return, iterator, « 24 received.[[Value]] »). 25 features: [generators, Symbol.iterator] 26 ---*/ 27 28 var thrown = new Test262Error(); 29 var badIter = {}; 30 badIter[Symbol.iterator] = function() { 31 return { 32 next: function() { 33 return { done: false }; 34 }, 35 return: function() { 36 throw thrown; 37 } 38 }; 39 }; 40 function* g() { 41 try { 42 yield * badIter; 43 } catch (err) { 44 caught = err; 45 } 46 } 47 var iter = g(); 48 var result, caught; 49 50 iter.next(); 51 result = iter.return(); 52 53 assert.sameValue(result.value, undefined); 54 assert.sameValue(result.done, true); 55 assert.sameValue(caught, thrown); 56 57 reportCompare(0, 0);