tor-browser

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

yield-star-getiter-async-get-abrupt.js (3023B)


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