star-rhs-iter-thrw-violation-rtrn-call-non-obj.js (2170B)
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 Non-object value returned by iterator `return` method following protocol 8 violation 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 [...] 23 iii. Else, 24 1. NOTE: If iterator does not have a throw method, this throw is 25 going to terminate the yield* loop. But first we need to give 26 iterator a chance to clean up. 27 2. Perform ? IteratorClose(iterator, Completion{[[Type]]: normal, 28 [[Value]]: empty, [[Target]]: empty}). 29 30 7.4.6 IteratorClose 31 32 1. Assert: Type(iterator) is Object. 33 2. Assert: completion is a Completion Record. 34 3. Let return be ? GetMethod(iterator, "return"). 35 4. If return is undefined, return Completion(completion). 36 5. Let innerResult be Call(return, iterator, « »). 37 6. If completion.[[Type]] is throw, return Completion(completion). 38 7. If innerResult.[[Type]] is throw, return Completion(innerResult). 39 8. If Type(innerResult.[[Value]]) is not Object, throw a TypeError exception. 40 features: [generators, Symbol.iterator] 41 ---*/ 42 43 var badIter = {}; 44 badIter[Symbol.iterator] = function() { 45 return { 46 next: function() { 47 return { done: false }; 48 }, 49 return: function() { 50 return 87; 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.throw(); 66 67 assert.sameValue(typeof caught, 'object'); 68 assert.sameValue(caught.constructor, TypeError); 69 70 reportCompare(0, 0);