tor-browser

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

async-gen-yield-star-sync-throw.js (6013B)


      1 // |reftest| async
      2 // This file was procedurally generated from the following sources:
      3 // - src/async-generators/yield-star-sync-throw.case
      4 // - src/async-generators/default/async-obj-method.template
      5 /*---
      6 description: execution order for yield* with sync iterator and throw() (Async generator method)
      7 esid: prod-AsyncGeneratorMethod
      8 features: [Symbol.iterator, async-iteration]
      9 flags: [generated, async]
     10 info: |
     11    Async Generator Function Definitions
     12 
     13    AsyncGeneratorMethod :
     14      async [no LineTerminator here] * PropertyName ( UniqueFormalParameters ) { AsyncGeneratorBody }
     15 
     16 
     17    YieldExpression: yield * AssignmentExpression
     18 
     19    ...
     20    6. Repeat
     21      ...
     22      b. Else if received.[[Type]] is throw, then
     23        i. Let throw be ? GetMethod(iterator, "throw").
     24        ii. If throw is not undefined, then
     25          1. Let innerResult be ? Call(throw, iterator, « received.[[Value]] »).
     26          2. If generatorKind is async, then set innerResult to
     27             ? Await(innerResult).
     28          ...
     29          5. Let done be ? IteratorComplete(innerResult).
     30          6. If done is true, then
     31            a. Return ? IteratorValue(innerResult).
     32          7. Let received be GeneratorYield(innerResult).
     33      ...
     34 
     35    %AsyncFromSyncIteratorPrototype%.throw ( value )
     36 
     37    ...
     38    5. Let throw be GetMethod(syncIterator, "throw").
     39    ...
     40    8. Let throwResult be Call(throw, syncIterator, « value »).
     41    ...
     42    11. Let throwValue be IteratorValue(throwResult).
     43    ...
     44    13. Let throwDone be IteratorComplete(throwResult).
     45    ...
     46    16. Perform ! Call(valueWrapperCapability.[[Resolve]], undefined,
     47        « throwValue »).
     48    ...
     49    18. Set onFulfilled.[[Done]] to throwDone.
     50    19. Perform ! PerformPromiseThen(valueWrapperCapability.[[Promise]],
     51        onFulfilled, undefined, promiseCapability).
     52    ...
     53 
     54 ---*/
     55 var log = [];
     56 var obj = {
     57  [Symbol.iterator]() {
     58    var throwCount = 0;
     59    return {
     60      name: "syncIterator",
     61      get next() {
     62        log.push({ name: "get next" });
     63        return function() {
     64          return {
     65            value: "next-value-1",
     66            done: false
     67          };
     68        };
     69      },
     70      get throw() {
     71        log.push({
     72          name: "get throw",
     73          thisValue: this
     74        });
     75        return function() {
     76          log.push({
     77            name: "call throw",
     78            thisValue: this,
     79            args: [...arguments]
     80          });
     81 
     82          throwCount++;
     83          if (throwCount == 1) {
     84            return {
     85              name: "throw-result-1",
     86              get value() {
     87                log.push({
     88                  name: "get throw value (1)",
     89                  thisValue: this
     90                });
     91                return "throw-value-1";
     92              },
     93              get done() {
     94                log.push({
     95                  name: "get throw done (1)",
     96                  thisValue: this
     97                });
     98                return false;
     99              }
    100            };
    101          }
    102 
    103          return {
    104            name: "throw-result-2",
    105            get value() {
    106              log.push({
    107                name: "get throw value (2)",
    108                thisValue: this
    109              });
    110              return "throw-value-2";
    111            },
    112            get done() {
    113              log.push({
    114                name: "get throw done (2)",
    115                thisValue: this
    116              });
    117              return true;
    118            }
    119          };
    120        };
    121      }
    122    };
    123  }
    124 };
    125 
    126 
    127 var callCount = 0;
    128 
    129 var gen = {
    130  async *method() {
    131    callCount += 1;
    132    log.push({ name: "before yield*" });
    133      var v = yield* obj;
    134      log.push({
    135        name: "after yield*",
    136        value: v
    137      });
    138      return "return-value";
    139 
    140  }
    141 }.method;
    142 
    143 var iter = gen();
    144 
    145 assert.sameValue(log.length, 0, "log.length");
    146 
    147 iter.next().then(v => {
    148  assert.sameValue(log[0].name, "before yield*");
    149 
    150  assert.sameValue(log[1].name, "get next");
    151 
    152  assert.sameValue(v.value, "next-value-1");
    153  assert.sameValue(v.done, false);
    154 
    155  assert.sameValue(log.length, 2, "log.length");
    156 
    157  iter.throw("throw-arg-1").then(v => {
    158    assert.sameValue(log[2].name, "get throw");
    159    assert.sameValue(log[2].thisValue.name, "syncIterator", "get throw thisValue");
    160 
    161    assert.sameValue(log[3].name, "call throw");
    162    assert.sameValue(log[3].thisValue.name, "syncIterator", "throw thisValue");
    163    assert.sameValue(log[3].args.length, 1, "throw args.length");
    164    assert.sameValue(log[3].args[0], "throw-arg-1", "throw args[0]");
    165 
    166    assert.sameValue(log[4].name, "get throw done (1)");
    167    assert.sameValue(log[4].thisValue.name, "throw-result-1", "get throw done thisValue");
    168 
    169    assert.sameValue(log[5].name, "get throw value (1)");
    170    assert.sameValue(log[5].thisValue.name, "throw-result-1", "get throw value thisValue");
    171 
    172    assert.sameValue(v.value, "throw-value-1");
    173    assert.sameValue(v.done, false);
    174 
    175    assert.sameValue(log.length, 6, "log.length");
    176 
    177    iter.throw().then(v => {
    178      assert.sameValue(log[6].name, "get throw");
    179      assert.sameValue(log[6].thisValue.name, "syncIterator", "get throw thisValue");
    180 
    181      assert.sameValue(log[7].name, "call throw");
    182      assert.sameValue(log[7].thisValue.name, "syncIterator", "throw thisValue");
    183      assert.sameValue(log[7].args.length, 1, "throw args.length");
    184      assert.sameValue(log[7].args[0], undefined, "throw args[0]");
    185 
    186      assert.sameValue(log[8].name, "get throw done (2)");
    187      assert.sameValue(log[8].thisValue.name, "throw-result-2", "get throw done thisValue");
    188 
    189      assert.sameValue(log[9].name, "get throw value (2)");
    190      assert.sameValue(log[9].thisValue.name, "throw-result-2", "get throw value thisValue");
    191 
    192      assert.sameValue(log[10].name, "after yield*");
    193      assert.sameValue(log[10].value, "throw-value-2");
    194 
    195      assert.sameValue(v.value, "return-value");
    196      assert.sameValue(v.done, true);
    197 
    198      assert.sameValue(log.length, 11, "log.length");
    199    }).then($DONE, $DONE);
    200  }).catch($DONE);
    201 }).catch($DONE);
    202 
    203 assert.sameValue(callCount, 1);