tor-browser

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

yield-star-next-then-non-callable-number-fulfillpromise.js (3291B)


      1 // |reftest| async
      2 // This file was procedurally generated from the following sources:
      3 // - src/async-generators/yield-star-next-then-non-callable-number-fulfillpromise.case
      4 // - src/async-generators/default/async-class-expr-private-method.template
      5 /*---
      6 description: FulfillPromise if next().then is not-callable (number) (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    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        iv. If Type(innerResult) is not Object, throw a TypeError exception.
     32    ...
     33 
     34    Await
     35 
     36    ...
     37    2. Let promiseCapability be ! NewPromiseCapability(%Promise%).
     38    3. Perform ! Call(promiseCapability.[[Resolve]], undefined, « promise »).
     39    ...
     40 
     41    Promise Resolve Functions
     42 
     43    ...
     44    7. If Type(resolution) is not Object, then
     45      a. Return FulfillPromise(promise, resolution).
     46    8. Let then be Get(resolution, "then").
     47    ...
     48    11. If IsCallable(thenAction) is false, then
     49      a. Return FulfillPromise(promise, resolution).
     50    ...
     51 
     52 ---*/
     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          then: 39,
     62          value: 42,
     63          done: false
     64        }
     65      }
     66    };
     67  }
     68 };
     69 
     70 
     71 
     72 var callCount = 0;
     73 
     74 var C = class {
     75    async *#gen() {
     76        callCount += 1;
     77        yield* obj;
     78          throw new Test262Error('completion closes iter');
     79 
     80    }
     81    get gen() { return this.#gen; }
     82 }
     83 
     84 const c = new C();
     85 
     86 // Test the private fields do not appear as properties before set to value
     87 assert(
     88  !Object.prototype.hasOwnProperty.call(C.prototype, "#gen"),
     89  "#gen does not appear as an own property on C prototype"
     90 );
     91 assert(
     92  !Object.prototype.hasOwnProperty.call(C, "#gen"),
     93  "#gen does not appear as an own property on C constructor"
     94 );
     95 assert(
     96  !Object.prototype.hasOwnProperty.call(c, "#gen"),
     97  "#gen does not appear as an own property on C instance"
     98 );
     99 
    100 var iter = c.gen();
    101 
    102 iter.next().then(({ value, done }) => {
    103  assert.sameValue(value, 42);
    104  assert.sameValue(done, false);
    105 }).then($DONE, $DONE);
    106 
    107 assert.sameValue(callCount, 1);
    108 
    109 // Test the private fields do not appear as properties after set to value
    110 assert(
    111  !Object.prototype.hasOwnProperty.call(C.prototype, "#gen"),
    112  "#gen does not appear as an own property on C prototype"
    113 );
    114 assert(
    115  !Object.prototype.hasOwnProperty.call(C, "#gen"),
    116  "#gen does not appear as an own property on C constructor"
    117 );
    118 assert(
    119  !Object.prototype.hasOwnProperty.call(c, "#gen"),
    120  "#gen does not appear as an own property on C instance"
    121 );