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 (2259B)


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