tor-browser

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

yield-star-async-throw.js (9110B)


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