tor-browser

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

yield-star-async-next.js (8369B)


      1 // |reftest| async
      2 // This file was procedurally generated from the following sources:
      3 // - src/async-generators/yield-star-async-next.case
      4 // - src/async-generators/default/async-class-expr-private-method.template
      5 /*---
      6 description: Execution order for yield* with async iterator and next() (Async generator method as a ClassExpression element)
      7 esid: prod-AsyncGeneratorPrivateMethod
      8 features: [Symbol.iterator, async-iteration, Symbol.asyncIterator, 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    
     24 ---*/
     25 var log = [];
     26 var obj = {
     27  get [Symbol.iterator]() {
     28    log.push({ name: "get [Symbol.iterator]" });
     29  },
     30  get [Symbol.asyncIterator]() {
     31    log.push({
     32      name: "get [Symbol.asyncIterator]",
     33      thisValue: this
     34    });
     35    return function() {
     36      log.push({
     37        name: "call [Symbol.asyncIterator]",
     38        thisValue: this,
     39        args: [...arguments]
     40      });
     41      var nextCount = 0;
     42      return {
     43        name: "asyncIterator",
     44        get next() {
     45          log.push({
     46            name: "get next",
     47            thisValue: this
     48          });
     49          return function() {
     50            log.push({
     51              name: "call next",
     52              thisValue: this,
     53              args: [...arguments]
     54            });
     55 
     56            nextCount++;
     57            if (nextCount == 1) {
     58              return {
     59                name: "next-promise-1",
     60                get then() {
     61                  log.push({
     62                    name: "get next then (1)",
     63                    thisValue: this
     64                  });
     65                  return function(resolve) {
     66                    log.push({
     67                      name: "call next then (1)",
     68                      thisValue: this,
     69                      args: [...arguments]
     70                    });
     71 
     72                    resolve({
     73                      name: "next-result-1",
     74                      get value() {
     75                        log.push({
     76                          name: "get next value (1)",
     77                          thisValue: this
     78                        });
     79                        return "next-value-1";
     80                      },
     81                      get done() {
     82                        log.push({
     83                          name: "get next done (1)",
     84                          thisValue: this
     85                        });
     86                        return false;
     87                      }
     88                    });
     89                  };
     90                }
     91              };
     92            }
     93 
     94            return {
     95              name: "next-promise-2",
     96              get then() {
     97                log.push({
     98                  name: "get next then (2)",
     99                  thisValue: this
    100                });
    101                return function(resolve) {
    102                  log.push({
    103                    name: "call next then (2)",
    104                    thisValue: this,
    105                    args: [...arguments]
    106                  });
    107 
    108                  resolve({
    109                    name: "next-result-2",
    110                    get value() {
    111                      log.push({
    112                        name: "get next value (2)",
    113                        thisValue: this
    114                      });
    115                      return "next-value-2";
    116                    },
    117                    get done() {
    118                      log.push({
    119                        name: "get next done (2)",
    120                        thisValue: this
    121                      });
    122                      return true;
    123                    }
    124                  });
    125                };
    126              }
    127            };
    128          };
    129        }
    130      };
    131    };
    132  }
    133 };
    134 
    135 
    136 
    137 var callCount = 0;
    138 
    139 var C = class {
    140    async *#gen() {
    141        callCount += 1;
    142        log.push({ name: "before yield*" });
    143          var v = yield* obj;
    144          log.push({
    145            name: "after yield*",
    146            value: v
    147          });
    148          return "return-value";
    149 
    150    }
    151    get gen() { return this.#gen; }
    152 }
    153 
    154 const c = new C();
    155 
    156 // Test the private fields do not appear as properties before set to value
    157 assert(
    158  !Object.prototype.hasOwnProperty.call(C.prototype, "#gen"),
    159  "#gen does not appear as an own property on C prototype"
    160 );
    161 assert(
    162  !Object.prototype.hasOwnProperty.call(C, "#gen"),
    163  "#gen does not appear as an own property on C constructor"
    164 );
    165 assert(
    166  !Object.prototype.hasOwnProperty.call(c, "#gen"),
    167  "#gen does not appear as an own property on C instance"
    168 );
    169 
    170 var iter = c.gen();
    171 
    172 assert.sameValue(log.length, 0, "log.length");
    173 
    174 iter.next("next-arg-1").then(v => {
    175  assert.sameValue(log[0].name, "before yield*");
    176 
    177  assert.sameValue(log[1].name, "get [Symbol.asyncIterator]");
    178  assert.sameValue(log[1].thisValue, obj, "get [Symbol.asyncIterator] thisValue");
    179 
    180  assert.sameValue(log[2].name, "call [Symbol.asyncIterator]");
    181  assert.sameValue(log[2].thisValue, obj, "[Symbol.asyncIterator] thisValue");
    182  assert.sameValue(log[2].args.length, 0, "[Symbol.asyncIterator] args.length");
    183 
    184  assert.sameValue(log[3].name, "get next");
    185  assert.sameValue(log[3].thisValue.name, "asyncIterator", "get next thisValue");
    186 
    187  assert.sameValue(log[4].name, "call next");
    188  assert.sameValue(log[4].thisValue.name, "asyncIterator", "next thisValue");
    189  assert.sameValue(log[4].args.length, 1, "next args.length");
    190  assert.sameValue(log[4].args[0], undefined, "next args[0]");
    191 
    192  assert.sameValue(log[5].name, "get next then (1)");
    193  assert.sameValue(log[5].thisValue.name, "next-promise-1", "get next then thisValue");
    194 
    195  assert.sameValue(log[6].name, "call next then (1)");
    196  assert.sameValue(log[6].thisValue.name, "next-promise-1", "next then thisValue");
    197  assert.sameValue(log[6].args.length, 2, "next then args.length");
    198  assert.sameValue(typeof log[6].args[0], "function", "next then args[0]");
    199  assert.sameValue(typeof log[6].args[1], "function", "next then args[1]");
    200 
    201  assert.sameValue(log[7].name, "get next done (1)");
    202  assert.sameValue(log[7].thisValue.name, "next-result-1", "get next done thisValue");
    203 
    204  assert.sameValue(log[8].name, "get next value (1)");
    205  assert.sameValue(log[8].thisValue.name, "next-result-1", "get next value thisValue");
    206 
    207  assert.sameValue(v.value, "next-value-1");
    208  assert.sameValue(v.done, false);
    209 
    210  assert.sameValue(log.length, 9, "log.length");
    211 
    212  iter.next("next-arg-2").then(v => {
    213    assert.sameValue(log[9].name, "call next");
    214    assert.sameValue(log[9].thisValue.name, "asyncIterator", "next thisValue");
    215    assert.sameValue(log[9].args.length, 1, "next args.length");
    216    assert.sameValue(log[9].args[0], "next-arg-2", "next args[0]");
    217 
    218    assert.sameValue(log[10].name, "get next then (2)");
    219    assert.sameValue(log[10].thisValue.name, "next-promise-2", "get next then thisValue");
    220 
    221    assert.sameValue(log[11].name, "call next then (2)");
    222    assert.sameValue(log[11].thisValue.name, "next-promise-2", "next then thisValue");
    223    assert.sameValue(log[11].args.length, 2, "next then args.length");
    224    assert.sameValue(typeof log[11].args[0], "function", "next then args[0]");
    225    assert.sameValue(typeof log[11].args[1], "function", "next then args[1]");
    226 
    227    assert.sameValue(log[12].name, "get next done (2)");
    228    assert.sameValue(log[12].thisValue.name, "next-result-2", "get next done thisValue");
    229 
    230    assert.sameValue(log[13].name, "get next value (2)");
    231    assert.sameValue(log[13].thisValue.name, "next-result-2", "get next value thisValue");
    232 
    233    assert.sameValue(log[14].name, "after yield*");
    234    assert.sameValue(log[14].value, "next-value-2");
    235 
    236    assert.sameValue(v.value, "return-value");
    237    assert.sameValue(v.done, true);
    238 
    239    assert.sameValue(log.length, 15, "log.length");
    240  }).then($DONE, $DONE);
    241 }).catch($DONE);
    242 
    243 assert.sameValue(callCount, 1);
    244 
    245 // Test the private fields do not appear as properties after set to value
    246 assert(
    247  !Object.prototype.hasOwnProperty.call(C.prototype, "#gen"),
    248  "#gen does not appear as an own property on C prototype"
    249 );
    250 assert(
    251  !Object.prototype.hasOwnProperty.call(C, "#gen"),
    252  "#gen does not appear as an own property on C constructor"
    253 );
    254 assert(
    255  !Object.prototype.hasOwnProperty.call(c, "#gen"),
    256  "#gen does not appear as an own property on C instance"
    257 );