Debian Codegraph @

tests/auto/qml/ecmascripttests/test262/test/language/expressions/assignment/dstr-array-elem-trlg-iter-list-rtrn-close.js

raw
1 // This file was procedurally generated from the following sources:
2 // - src/dstr-assignment/array-elem-trlg-iter-list-rtrn-close.case
3 // - src/dstr-assignment/default/assignment-expr.template
4 /*---
5 description: IteratorClose is invoked when evaluation of AssignmentElementList returns a "return" completion and the iterator has not been marked as "done" (AssignmentExpression)
6 esid: sec-variable-statement-runtime-semantics-evaluation
7 es6id: 13.3.2.4
8 features: [Symbol.iterator, generators, destructuring-binding]
9 flags: [generated]
10 info: |
11 VariableDeclaration : BindingPattern Initializer
12
13 1. Let rhs be the result of evaluating Initializer.
14 2. Let rval be GetValue(rhs).
15 3. ReturnIfAbrupt(rval).
16 4. Return the result of performing BindingInitialization for
17 BindingPattern passing rval and undefined as arguments.
18
19 ArrayAssignmentPattern :
20 [ AssignmentElementList , Elisionopt AssignmentRestElementopt ]
21
22 [...]
23 3. Let iteratorRecord be Record {[[iterator]]: iterator, [[done]]: false}.
24 4. Let status be the result of performing
25 IteratorDestructuringAssignmentEvaluation of AssignmentElementList using
26 iteratorRecord as the argument.
27 5. If status is an abrupt completion, then
28 a. If iteratorRecord.[[done]] is false, return IteratorClose(iterator,
29 status).
30 b. Return Completion(status).
31
32 7.4.6 IteratorClose( iterator, completion )
33
34 [...]
35 6. Let innerResult be Call(return, iterator, « »).
36 7. If completion.[[type]] is throw, return Completion(completion).
37 8. If innerResult.[[type]] is throw, return Completion(innerResult).
38
39 ---*/
40 var nextCount = 0;
41 var returnCount = 0;
42 var unreachable = 0;
43 var thisValue = null;
44 var args = null;
45 var iterable = {};
46 var iterator = {
47 next: function() {
48 nextCount += 1;
49 return {done: false, value: undefined};
50 },
51 return: function() {
52 returnCount += 1;
53 thisValue = this;
54 args = arguments;
55 return {};
56 }
57 };
58 var iter, result;
59
60 iterable[Symbol.iterator] = function() {
61 return iterator;
62 };
63
64 function* g() {
65
66 var result;
67 var vals = iterable;
68
69 result = [ {} = yield , ] = vals;
70
71 unreachable += 1;
72
73 assert.sameValue(result, vals);
74
75 };
76
77 iter = g();
78 iter.next();
79
80 assert.sameValue(nextCount, 1);
81 assert.sameValue(returnCount, 0);
82
83 result = iter.return(888);
84
85 assert.sameValue(nextCount, 1);
86 assert.sameValue(returnCount, 1);
87 assert.sameValue(unreachable, 0, 'Unreachable statement was not executed');
88 assert.sameValue(result.value, 888);
89 assert(result.done, 'Iterator correctly closed');
90 assert.sameValue(thisValue, iterator, 'correct `this` value');
91 assert(!!args, 'arguments object provided');
92 assert.sameValue(args.length, 0, 'zero arguments specified');