tor-browser

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

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


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