Debian Codegraph @

tests/auto/qml/ecmascripttests/test262/test/language/expressions/yield/star-rhs-iter-thrw-thrw-invoke.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: Invocation of iterator `throw` 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 i. Let throw be ? GetMethod(iterator, "throw").
19 ii. If throw is not undefined, then
20 1. Let innerResult be ? Call(throw, iterator, « received.[[Value]]
21 »).
22 [...]
23 features: [generators, Symbol.iterator]
24 ---*/
25
26 var args, thisValue;
27 var callCount = 0;
28 var spyIterator = {
29 next: function() {
30 return { done: false };
31 },
32 throw: function() {
33 callCount += 1;
34 args = arguments;
35 thisValue = this;
36 return { done: true };
37 }
38 };
39 var spyIterable = {};
40 spyIterable[Symbol.iterator] = function() {
41 return spyIterator;
42 };
43 function* g() {
44 yield * spyIterable;
45 }
46 var iter = g();
47
48 iter.next(8888);
49 iter.throw(7777);
50
51 assert.sameValue(callCount, 1);
52 assert.sameValue(args.length, 1);
53 assert.sameValue(args[0], 7777);
54 assert.sameValue(thisValue, spyIterator);