star-rhs-iter-nrml-next-call-non-obj.js (1361B)
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 TypeError thrown when iterator `next` method returns a non-object value 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 i. Let innerResult be ? IteratorNext(iterator, received.[[Value]]). 18 19 7.4.2 IteratorNext 20 21 1. If value was not passed, then 22 [...] 23 2. Else, 24 a. Let result be ? Invoke(iterator, "next", « value »). 25 features: [generators, Symbol.iterator] 26 ---*/ 27 28 var badIter = {}; 29 badIter[Symbol.iterator] = function() { 30 return { 31 next: function() { 32 return 8; 33 } 34 }; 35 }; 36 function* g() { 37 try { 38 yield * badIter; 39 } catch (err) { 40 caught = err; 41 } 42 } 43 var iter = g(); 44 var result, caught; 45 46 result = iter.next(); 47 48 assert.sameValue(result.value, undefined); 49 assert.sameValue(result.done, true); 50 assert.sameValue(typeof caught, 'object'); 51 assert.sameValue(caught.constructor, TypeError); 52 53 reportCompare(0, 0);