tor-browser

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

yield-star-next-call-done-get-abrupt.js (2797B)


      1 // |reftest| async
      2 // This file was procedurally generated from the following sources:
      3 // - src/async-generators/yield-star-next-call-done-get-abrupt.case
      4 // - src/async-generators/default/async-class-expr-static-private-method.template
      5 /*---
      6 description: Abrupt completion while getting done (Static async generator method as a ClassExpression element)
      7 esid: prod-AsyncGeneratorPrivateMethod
      8 features: [Symbol.iterator, Symbol.asyncIterator, async-iteration, class-static-methods-private]
      9 flags: [generated, async]
     10 info: |
     11    ClassElement :
     12      static PrivateMethodDefinition
     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        v. Let done be ? IteratorComplete(innerResult).
     33    ...
     34 
     35 ---*/
     36 var reason = {};
     37 var obj = {
     38  get [Symbol.iterator]() {
     39    throw new Test262Error('it should not get Symbol.iterator');
     40  },
     41  [Symbol.asyncIterator]() {
     42    return {
     43      next() {
     44        return {
     45          get done() {
     46            throw reason;
     47          }
     48        };
     49      }
     50    };
     51  }
     52 };
     53 
     54 
     55 
     56 var callCount = 0;
     57 
     58 var C = class {
     59    static async *#gen() {
     60        callCount += 1;
     61        yield* obj;
     62          throw new Test262Error('abrupt completion closes iter');
     63 
     64    }
     65    static get gen() { return this.#gen; }
     66 }
     67 
     68 // Test the private fields do not appear as properties before set to value
     69 assert(
     70  !Object.prototype.hasOwnProperty.call(C.prototype, "#gen"),
     71  "#gen does not appear as an own property on C prototype"
     72 );
     73 assert(
     74  !Object.prototype.hasOwnProperty.call(C, "#gen"),
     75  "#gen does not appear as an own property on C constructor"
     76 );
     77 
     78 var iter = C.gen();
     79 
     80 iter.next().then(() => {
     81  throw new Test262Error('Promise incorrectly fulfilled.');
     82 }, v => {
     83  assert.sameValue(v, reason, "reject reason");
     84 
     85  iter.next().then(({ done, value }) => {
     86    assert.sameValue(done, true, 'the iterator is completed');
     87    assert.sameValue(value, undefined, 'value is undefined');
     88  }).then($DONE, $DONE);
     89 }).catch($DONE);
     90 
     91 assert.sameValue(callCount, 1);
     92 
     93 // Test the private fields do not appear as properties after set to value
     94 assert(
     95  !Object.prototype.hasOwnProperty.call(C.prototype, "#gen"),
     96  "#gen does not appear as an own property on C prototype"
     97 );
     98 assert(
     99  !Object.prototype.hasOwnProperty.call(C, "#gen"),
    100  "#gen does not appear as an own property on C constructor"
    101 );