tor-browser

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

yield-promise-reject-next-yield-star-async-iterator.js (2485B)


      1 // |reftest| async
      2 // This file was procedurally generated from the following sources:
      3 // - src/async-generators/yield-promise-reject-next-yield-star-async-iterator.case
      4 // - src/async-generators/default/async-class-expr-private-method.template
      5 /*---
      6 description: yield * (async iterator) is treated as throw value (Async generator method as a ClassExpression element)
      7 esid: prod-AsyncGeneratorPrivateMethod
      8 features: [async-iteration, 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 let error = new Error();
     24 async function * readFile() {
     25  yield Promise.reject(error);
     26  yield "unreachable";
     27 }
     28 
     29 
     30 var callCount = 0;
     31 
     32 var C = class {
     33    async *#gen() {
     34        callCount += 1;
     35        yield * readFile();
     36 
     37    }
     38    get gen() { return this.#gen; }
     39 }
     40 
     41 const c = new C();
     42 
     43 // Test the private fields do not appear as properties before set to value
     44 assert(
     45  !Object.prototype.hasOwnProperty.call(C.prototype, "#gen"),
     46  "#gen does not appear as an own property on C prototype"
     47 );
     48 assert(
     49  !Object.prototype.hasOwnProperty.call(C, "#gen"),
     50  "#gen does not appear as an own property on C constructor"
     51 );
     52 assert(
     53  !Object.prototype.hasOwnProperty.call(c, "#gen"),
     54  "#gen does not appear as an own property on C instance"
     55 );
     56 
     57 var iter = c.gen();
     58 
     59 iter.next().then(() => {
     60  throw new Test262Error("Promise incorrectly resolved.");
     61 }, rejectValue => {
     62  // yield Promise.reject(error);
     63  assert.sameValue(rejectValue, error);
     64 
     65  iter.next().then(({done, value}) => {
     66    // iter is closed now.
     67    assert.sameValue(done, true, "The value of IteratorResult.done is `true`");
     68    assert.sameValue(value, undefined, "The value of IteratorResult.value is `undefined`");
     69  }).then($DONE, $DONE);
     70 }, $DONE).catch($DONE);
     71 
     72 assert.sameValue(callCount, 1);
     73 
     74 // Test the private fields do not appear as properties after set to value
     75 assert(
     76  !Object.prototype.hasOwnProperty.call(C.prototype, "#gen"),
     77  "#gen does not appear as an own property on C prototype"
     78 );
     79 assert(
     80  !Object.prototype.hasOwnProperty.call(C, "#gen"),
     81  "#gen does not appear as an own property on C constructor"
     82 );
     83 assert(
     84  !Object.prototype.hasOwnProperty.call(c, "#gen"),
     85  "#gen does not appear as an own property on C instance"
     86 );