tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

yield-star-next-then-get-abrupt.js (2382B)


      1 // |reftest| async
      2 // This file was procedurally generated from the following sources:
      3 // - src/async-generators/yield-star-next-then-get-abrupt.case
      4 // - src/async-generators/default/async-class-decl-method.template
      5 /*---
      6 description: Return abrupt after getting next().then (Async Generator method as a ClassDeclaration element)
      7 esid: prod-AsyncGeneratorMethod
      8 features: [Symbol.iterator, Symbol.asyncIterator, async-iteration]
      9 flags: [generated, async]
     10 info: |
     11    ClassElement :
     12      MethodDefinition
     13 
     14    MethodDefinition :
     15      AsyncGeneratorMethod
     16 
     17    Async Generator Function Definitions
     18 
     19    AsyncGeneratorMethod :
     20      async [no LineTerminator here] * PropertyName ( UniqueFormalParameters ) { AsyncGeneratorBody }
     21 
     22 
     23    YieldExpression: yield * AssignmentExpression
     24    ...
     25    6. Repeat
     26      a. If received.[[Type]] is normal, then
     27        ii. Let innerResult be ? Invoke(iterator, "next",
     28            « received.[[Value]] »).
     29        iii. If generatorKind is async, then set innerResult to
     30             ? Await(innerResult).
     31    ...
     32 
     33    Await
     34 
     35    ...
     36    2. Let promiseCapability be ! NewPromiseCapability(%Promise%).
     37    3. Perform ! Call(promiseCapability.[[Resolve]], undefined, « promise »).
     38    ...
     39 
     40    Promise Resolve Functions
     41 
     42    ...
     43    8. Let then be Get(resolution, "then").
     44    ...
     45    10. Get thenAction be then.[[Value]].
     46    ...
     47    12. Perform EnqueueJob("PromiseJobs", PromiseResolveThenableJob, « promise,
     48        resolution, thenAction »).
     49    ...
     50 
     51 ---*/
     52 var reason = {};
     53 var obj = {
     54  get [Symbol.iterator]() {
     55    throw new Test262Error('it should not get Symbol.iterator');
     56  },
     57  [Symbol.asyncIterator]() {
     58    return {
     59      next() {
     60        return {
     61          get then() {
     62            throw reason;
     63          }
     64        };
     65      }
     66    };
     67  }
     68 };
     69 
     70 
     71 
     72 var callCount = 0;
     73 
     74 class C { async *gen() {
     75    callCount += 1;
     76    yield* obj;
     77      throw new Test262Error('abrupt completion closes iter');
     78 
     79 }}
     80 
     81 var gen = C.prototype.gen;
     82 
     83 var iter = gen();
     84 
     85 iter.next().then(() => {
     86  throw new Test262Error('Promise incorrectly fulfilled.');
     87 }, v => {
     88  assert.sameValue(v, reason, 'reject reason');
     89 
     90  iter.next().then(({ done, value }) => {
     91    assert.sameValue(done, true, 'the iterator is completed');
     92    assert.sameValue(value, undefined, 'value is undefined');
     93  }).then($DONE, $DONE);
     94 }).catch($DONE);
     95 
     96 assert.sameValue(callCount, 1);