tor-browser

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

yield-spread-obj.js (2352B)


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