js/src/tests/test262/language/expressions/object/dstr/async-gen-meth-dflt-ary-init-iter-no-close.js
raw symbols SCIP| 1 | // |reftest| async |
| 2 | // This file was procedurally generated from the following sources: |
| 3 | // - src/dstr-binding/ary-init-iter-no-close.case |
| 4 | // - src/dstr-binding/default/async-gen-method-dflt.template |
| 5 | /*--- |
| 6 | description: Iterator is not closed when exhausted by pattern evaluation (async generator method (default parameter)) |
| 7 | esid: sec-asyncgenerator-definitions-propertydefinitionevaluation |
| 8 | features: [Symbol.iterator, async-iteration] |
| 9 | flags: [generated, async] |
| 10 | info: | |
| 11 | AsyncGeneratorMethod : |
| 12 | async [no LineTerminator here] * PropertyName ( UniqueFormalParameters ) |
| 13 | { AsyncGeneratorBody } |
| 14 | |
| 15 | 1. Let propKey be the result of evaluating PropertyName. |
| 16 | 2. ReturnIfAbrupt(propKey). |
| 17 | 3. If the function code for this AsyncGeneratorMethod is strict mode code, let strict be true. |
| 18 | Otherwise let strict be false. |
| 19 | 4. Let scope be the running execution context's LexicalEnvironment. |
| 20 | 5. Let closure be ! AsyncGeneratorFunctionCreate(Method, UniqueFormalParameters, |
| 21 | AsyncGeneratorBody, scope, strict). |
| 22 | [...] |
| 23 | |
| 24 | |
| 25 | 13.3.3.5 Runtime Semantics: BindingInitialization |
| 26 | |
| 27 | BindingPattern : ArrayBindingPattern |
| 28 | |
| 29 | [...] |
| 30 | 4. If iteratorRecord.[[done]] is false, return ? IteratorClose(iterator, |
| 31 | result). |
| 32 | [...] |
| 33 | |
| 34 | ---*/ |
| 35 | var doneCallCount = 0; |
| 36 | var iter = {}; |
| 37 | iter[Symbol.iterator] = function() { |
| 38 | return { |
| 39 | next: function() { |
| 40 | return { value: null, done: true }; |
| 41 | }, |
| 42 | return: function() { |
| 43 | doneCallCount += 1; |
| 44 | return {}; |
| 45 | } |
| 46 | }; |
| 47 | }; |
| 48 | |
| 49 | |
| 50 | var callCount = 0; |
| 51 | var obj = { |
| 52 | async *method([x] = iter) { |
| 53 | assert.sameValue(doneCallCount, 0); |
| 54 | callCount = callCount + 1; |
| 55 | } |
| 56 | }; |
| 57 | |
| 58 | obj.method().next().then(() => { |
| 59 | assert.sameValue(callCount, 1, 'invoked exactly once'); |
| 60 | }).then($DONE, $DONE); |