tor-browser

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

yield-star-sync-throw.js (6022B)


      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-expression.template
      5 /*---
      6 description: execution order for yield* with sync iterator and throw() (Unnamed async generator expression)
      7 esid: prod-AsyncGeneratorExpression
      8 features: [Symbol.iterator, async-iteration]
      9 flags: [generated, async]
     10 info: |
     11    Async Generator Function Definitions
     12 
     13    AsyncGeneratorExpression :
     14      async [no LineTerminator here] function * BindingIdentifier ( FormalParameters ) {
     15        AsyncGeneratorBody }
     16 
     17 
     18    YieldExpression: yield * AssignmentExpression
     19 
     20    ...
     21    6. Repeat
     22      ...
     23      b. Else if received.[[Type]] is throw, then
     24        i. Let throw be ? GetMethod(iterator, "throw").
     25        ii. If throw is not undefined, then
     26          1. Let innerResult be ? Call(throw, iterator, « received.[[Value]] »).
     27          2. If generatorKind is async, then set innerResult to
     28             ? Await(innerResult).
     29          ...
     30          5. Let done be ? IteratorComplete(innerResult).
     31          6. If done is true, then
     32            a. Return ? IteratorValue(innerResult).
     33          7. Let received be GeneratorYield(innerResult).
     34      ...
     35 
     36    %AsyncFromSyncIteratorPrototype%.throw ( value )
     37 
     38    ...
     39    5. Let throw be GetMethod(syncIterator, "throw").
     40    ...
     41    8. Let throwResult be Call(throw, syncIterator, « value »).
     42    ...
     43    11. Let throwValue be IteratorValue(throwResult).
     44    ...
     45    13. Let throwDone be IteratorComplete(throwResult).
     46    ...
     47    16. Perform ! Call(valueWrapperCapability.[[Resolve]], undefined,
     48        « throwValue »).
     49    ...
     50    18. Set onFulfilled.[[Done]] to throwDone.
     51    19. Perform ! PerformPromiseThen(valueWrapperCapability.[[Promise]],
     52        onFulfilled, undefined, promiseCapability).
     53    ...
     54 
     55 ---*/
     56 var log = [];
     57 var obj = {
     58  [Symbol.iterator]() {
     59    var throwCount = 0;
     60    return {
     61      name: "syncIterator",
     62      get next() {
     63        log.push({ name: "get next" });
     64        return function() {
     65          return {
     66            value: "next-value-1",
     67            done: false
     68          };
     69        };
     70      },
     71      get throw() {
     72        log.push({
     73          name: "get throw",
     74          thisValue: this
     75        });
     76        return function() {
     77          log.push({
     78            name: "call throw",
     79            thisValue: this,
     80            args: [...arguments]
     81          });
     82 
     83          throwCount++;
     84          if (throwCount == 1) {
     85            return {
     86              name: "throw-result-1",
     87              get value() {
     88                log.push({
     89                  name: "get throw value (1)",
     90                  thisValue: this
     91                });
     92                return "throw-value-1";
     93              },
     94              get done() {
     95                log.push({
     96                  name: "get throw done (1)",
     97                  thisValue: this
     98                });
     99                return false;
    100              }
    101            };
    102          }
    103 
    104          return {
    105            name: "throw-result-2",
    106            get value() {
    107              log.push({
    108                name: "get throw value (2)",
    109                thisValue: this
    110              });
    111              return "throw-value-2";
    112            },
    113            get done() {
    114              log.push({
    115                name: "get throw done (2)",
    116                thisValue: this
    117              });
    118              return true;
    119            }
    120          };
    121        };
    122      }
    123    };
    124  }
    125 };
    126 
    127 
    128 
    129 var callCount = 0;
    130 
    131 var gen = async function *() {
    132  callCount += 1;
    133  log.push({ name: "before yield*" });
    134    var v = yield* obj;
    135    log.push({
    136      name: "after yield*",
    137      value: v
    138    });
    139    return "return-value";
    140 
    141 };
    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);