tor-browser

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

yield-star-next-non-object-ignores-then.js (3228B)


      1 // |reftest| async
      2 // This file was procedurally generated from the following sources:
      3 // - src/async-generators/yield-star-next-non-object-ignores-then.case
      4 // - src/async-generators/default/async-class-decl-static-private-method.template
      5 /*---
      6 description: If next() value is not-object, do not access respective then property (Static async generator method as a ClassDeclaration 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        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 
     49 ---*/
     50 Number.prototype.then = function() {
     51  throw new Test262Error('Number#then should not be used');
     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 42;
     61      }
     62    };
     63  }
     64 };
     65 
     66 
     67 
     68 var callCount = 0;
     69 
     70 class C {
     71    static async *#gen() {
     72        callCount += 1;
     73        yield* obj;
     74          throw new Test262Error('abrupt completion closes iter');
     75 
     76    }
     77    static get gen() { return this.#gen; }
     78 }
     79 
     80 // Test the private fields do not appear as properties before set to value
     81 assert(
     82  !Object.prototype.hasOwnProperty.call(C.prototype, "#gen"),
     83  "#gen does not appear as an own property on C prototype"
     84 );
     85 assert(
     86  !Object.prototype.hasOwnProperty.call(C, "#gen"),
     87  "#gen does not appear as an own property on C constructor"
     88 );
     89 
     90 var iter = C.gen();
     91 
     92 iter.next().then(() => {
     93  throw new Test262Error('Promise incorrectly fulfilled.');
     94 }, v => {
     95  assert.sameValue(v.constructor, TypeError, 'TypeError');
     96 
     97  iter.next().then(({ done, value }) => {
     98    assert.sameValue(done, true, 'the iterator is completed');
     99    assert.sameValue(value, undefined, 'value is undefined');
    100  }).then($DONE, $DONE);
    101 }).catch($DONE);
    102 
    103 assert.sameValue(callCount, 1);
    104 
    105 // Test the private fields do not appear as properties after set to value
    106 assert(
    107  !Object.prototype.hasOwnProperty.call(C.prototype, "#gen"),
    108  "#gen does not appear as an own property on C prototype"
    109 );
    110 assert(
    111  !Object.prototype.hasOwnProperty.call(C, "#gen"),
    112  "#gen does not appear as an own property on C constructor"
    113 );