tor-browser

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

yield-spread-arr-single.js (2371B)


      1 // This file was procedurally generated from the following sources:
      2 // - src/generators/yield-spread-arr-single.case
      3 // - src/generators/default/class-decl-private-method.template
      4 /*---
      5 description: Use yield value in a array spread position (Generator private method as a ClassDeclaration element)
      6 esid: prod-GeneratorPrivateMethod
      7 features: [generators, class-methods-private]
      8 flags: [generated]
      9 info: |
     10    ClassElement :
     11      PrivateMethodDefinition
     12 
     13    MethodDefinition :
     14      GeneratorMethod
     15 
     16    14.4 Generator Function Definitions
     17 
     18    GeneratorMethod :
     19      * PropertyName ( UniqueFormalParameters ) { GeneratorBody }
     20 
     21 
     22    Array Initializer
     23 
     24    SpreadElement[Yield, Await]:
     25      ...AssignmentExpression[+In, ?Yield, ?Await]
     26 ---*/
     27 var arr = ['a', 'b', 'c'];
     28 
     29 var callCount = 0;
     30 
     31 class C {
     32    *#gen() {
     33        callCount += 1;
     34        yield [...yield];
     35    }
     36    get gen() { return this.#gen; }
     37 }
     38 
     39 const c = new C();
     40 
     41 // Test the private fields do not appear as properties before set to value
     42 assert(
     43  !Object.prototype.hasOwnProperty.call(C.prototype, "#gen"),
     44  "Private field '#gen' does not appear as an own property on C prototype"
     45 );
     46 assert(
     47  !Object.prototype.hasOwnProperty.call(C, "#gen"),
     48  "Private field '#gen' does not appear as an own property on C constructor"
     49 );
     50 assert(
     51  !Object.prototype.hasOwnProperty.call(c, "#gen"),
     52  "Private field '#gen' does not appear as an own property on C instance"
     53 );
     54 
     55 var iter = c.gen();
     56 
     57 iter.next(false);
     58 var item = iter.next(arr);
     59 var value = item.value;
     60 
     61 assert.notSameValue(value, arr, 'value is a new array');
     62 assert(Array.isArray(value), 'value is an Array exotic object');
     63 assert.sameValue(value.length, 3)
     64 assert.sameValue(value[0], 'a');
     65 assert.sameValue(value[1], 'b');
     66 assert.sameValue(value[2], 'c');
     67 assert.sameValue(item.done, false);
     68 
     69 assert.sameValue(callCount, 1);
     70 
     71 // Test the private fields do not appear as properties after set to value
     72 assert(
     73  !Object.prototype.hasOwnProperty.call(C.prototype, "#gen"),
     74  "Private field '#gen' does not appear as an own property on C prototype"
     75 );
     76 assert(
     77  !Object.prototype.hasOwnProperty.call(C, "#gen"),
     78  "Private field '#gen' does not appear as an own property on C constructor"
     79 );
     80 assert(
     81  !Object.prototype.hasOwnProperty.call(c, "#gen"),
     82  "Private field '#gen' does not appear as an own property on C instance"
     83 );
     84 
     85 reportCompare(0, 0);