tor-browser

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

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


      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-decl-method.template
      5 /*---
      6 description: Execution order for yield* with async iterator and next() (Async Generator method as a ClassDeclaration element)
      7 esid: prod-AsyncGeneratorMethod
      8 features: [Symbol.iterator, async-iteration, Symbol.asyncIterator]
      9 flags: [generated, async]
     10 info: |
     11    ClassElement :
     12      MethodDefinition
     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 class C { async *gen() {
    140    callCount += 1;
    141    log.push({ name: "before yield*" });
    142      var v = yield* obj;
    143      log.push({
    144        name: "after yield*",
    145        value: v
    146      });
    147      return "return-value";
    148 
    149 }}
    150 
    151 var gen = C.prototype.gen;
    152 
    153 var iter = gen();
    154 
    155 assert.sameValue(log.length, 0, "log.length");
    156 
    157 iter.next("next-arg-1").then(v => {
    158  assert.sameValue(log[0].name, "before yield*");
    159 
    160  assert.sameValue(log[1].name, "get [Symbol.asyncIterator]");
    161  assert.sameValue(log[1].thisValue, obj, "get [Symbol.asyncIterator] thisValue");
    162 
    163  assert.sameValue(log[2].name, "call [Symbol.asyncIterator]");
    164  assert.sameValue(log[2].thisValue, obj, "[Symbol.asyncIterator] thisValue");
    165  assert.sameValue(log[2].args.length, 0, "[Symbol.asyncIterator] args.length");
    166 
    167  assert.sameValue(log[3].name, "get next");
    168  assert.sameValue(log[3].thisValue.name, "asyncIterator", "get next thisValue");
    169 
    170  assert.sameValue(log[4].name, "call next");
    171  assert.sameValue(log[4].thisValue.name, "asyncIterator", "next thisValue");
    172  assert.sameValue(log[4].args.length, 1, "next args.length");
    173  assert.sameValue(log[4].args[0], undefined, "next args[0]");
    174 
    175  assert.sameValue(log[5].name, "get next then (1)");
    176  assert.sameValue(log[5].thisValue.name, "next-promise-1", "get next then thisValue");
    177 
    178  assert.sameValue(log[6].name, "call next then (1)");
    179  assert.sameValue(log[6].thisValue.name, "next-promise-1", "next then thisValue");
    180  assert.sameValue(log[6].args.length, 2, "next then args.length");
    181  assert.sameValue(typeof log[6].args[0], "function", "next then args[0]");
    182  assert.sameValue(typeof log[6].args[1], "function", "next then args[1]");
    183 
    184  assert.sameValue(log[7].name, "get next done (1)");
    185  assert.sameValue(log[7].thisValue.name, "next-result-1", "get next done thisValue");
    186 
    187  assert.sameValue(log[8].name, "get next value (1)");
    188  assert.sameValue(log[8].thisValue.name, "next-result-1", "get next value thisValue");
    189 
    190  assert.sameValue(v.value, "next-value-1");
    191  assert.sameValue(v.done, false);
    192 
    193  assert.sameValue(log.length, 9, "log.length");
    194 
    195  iter.next("next-arg-2").then(v => {
    196    assert.sameValue(log[9].name, "call next");
    197    assert.sameValue(log[9].thisValue.name, "asyncIterator", "next thisValue");
    198    assert.sameValue(log[9].args.length, 1, "next args.length");
    199    assert.sameValue(log[9].args[0], "next-arg-2", "next args[0]");
    200 
    201    assert.sameValue(log[10].name, "get next then (2)");
    202    assert.sameValue(log[10].thisValue.name, "next-promise-2", "get next then thisValue");
    203 
    204    assert.sameValue(log[11].name, "call next then (2)");
    205    assert.sameValue(log[11].thisValue.name, "next-promise-2", "next then thisValue");
    206    assert.sameValue(log[11].args.length, 2, "next then args.length");
    207    assert.sameValue(typeof log[11].args[0], "function", "next then args[0]");
    208    assert.sameValue(typeof log[11].args[1], "function", "next then args[1]");
    209 
    210    assert.sameValue(log[12].name, "get next done (2)");
    211    assert.sameValue(log[12].thisValue.name, "next-result-2", "get next done thisValue");
    212 
    213    assert.sameValue(log[13].name, "get next value (2)");
    214    assert.sameValue(log[13].thisValue.name, "next-result-2", "get next value thisValue");
    215 
    216    assert.sameValue(log[14].name, "after yield*");
    217    assert.sameValue(log[14].value, "next-value-2");
    218 
    219    assert.sameValue(v.value, "return-value");
    220    assert.sameValue(v.done, true);
    221 
    222    assert.sameValue(log.length, 15, "log.length");
    223  }).then($DONE, $DONE);
    224 }).catch($DONE);
    225 
    226 assert.sameValue(callCount, 1);