Debian Codegraph @

tests/auto/qml/ecmascripttests/test262/test/language/expressions/yield/star-rhs-iter-thrw-thrw-call-non-obj.js

raw
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 `throw` 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 [...]
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 features: [generators, Symbol.iterator]
28 ---*/
29
30 var badIter = {};
31 badIter[Symbol.iterator] = function() {
32 return {
33 next: function() {
34 return { done: false };
35 },
36 throw: function() {
37 return 23;
38 }
39 };
40 };
41 function* g() {
42 try {
43 yield * badIter;
44 } catch (err) {
45 caught = err;
46 }
47 }
48 var iter = g();
49 var result, caught;
50
51 iter.next();
52 result = iter.throw();
53
54 assert.sameValue(result.value, undefined);
55 assert.sameValue(result.done, true);
56 assert.sameValue(typeof caught, 'object');
57 assert.sameValue(caught.constructor, TypeError);