tor-browser

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

yield-spread-obj.js (2132B)


      1 // |reftest| async
      2 // This file was procedurally generated from the following sources:
      3 // - src/async-generators/yield-spread-obj.case
      4 // - src/async-generators/default/async-class-decl-static-private-method.template
      5 /*---
      6 description: Use yield value in a object spread position (Static async generator method as a ClassDeclaration element)
      7 esid: prod-AsyncGeneratorPrivateMethod
      8 features: [object-spread, 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    Spread Properties
     24 
     25    PropertyDefinition[Yield]:
     26      (...)
     27      ...AssignmentExpression[In, ?Yield]
     28 
     29 ---*/
     30 
     31 
     32 var callCount = 0;
     33 
     34 class C {
     35    static async *#gen() {
     36        callCount += 1;
     37        yield {
     38            ...yield,
     39            y: 1,
     40            ...yield yield,
     41          };
     42    }
     43    static get gen() { return this.#gen; }
     44 }
     45 
     46 // Test the private fields do not appear as properties before set to value
     47 assert(
     48  !Object.prototype.hasOwnProperty.call(C.prototype, "#gen"),
     49  "#gen does not appear as an own property on C prototype"
     50 );
     51 assert(
     52  !Object.prototype.hasOwnProperty.call(C, "#gen"),
     53  "#gen does not appear as an own property on C constructor"
     54 );
     55 
     56 var iter = C.gen();
     57 
     58 iter.next();
     59 iter.next({ x: 42 });
     60 iter.next({ x: 'lol' });
     61 var item = iter.next({ y: 39 });
     62 
     63 item.then(({ done, value }) => {
     64  assert.sameValue(value.x, 42);
     65  assert.sameValue(value.y, 39);
     66  assert.sameValue(Object.keys(value).length, 2);
     67  assert.sameValue(done, false);
     68 }).then($DONE, $DONE);
     69 
     70 assert.sameValue(callCount, 1);
     71 
     72 // Test the private fields do not appear as properties after set to value
     73 assert(
     74  !Object.prototype.hasOwnProperty.call(C.prototype, "#gen"),
     75  "#gen does not appear as an own property on C prototype"
     76 );
     77 assert(
     78  !Object.prototype.hasOwnProperty.call(C, "#gen"),
     79  "#gen does not appear as an own property on C constructor"
     80 );