tor-browser

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

async-from-sync-iterator-continuation-close-with-interrupt.js (1385B)


      1 // |jit-test| exitstatus: 6;
      2 
      3 // https://tc39.es/ecma262/#sec-asyncfromsynciteratorcontinuation
      4 //
      5 // 27.1.6.4 AsyncFromSyncIteratorContinuation ( result, promiseCapability, syncIteratorRecord, closeOnRejection )
      6 //
      7 // ...
      8 // 6 Let valueWrapper be Completion(PromiseResolve(%Promise%, value)).
      9 // 7. If valueWrapper is an abrupt completion, done is false, and closeOnRejection is true, then
     10 //   a. Set valueWrapper to Completion(IteratorClose(syncIteratorRecord, valueWrapper)).
     11 // 8. IfAbruptRejectPromise(valueWrapper, promiseCapability).
     12 // ...
     13 //
     14 // https://tc39.es/ecma262/#sec-promise-resolve
     15 //
     16 // 27.2.4.7.1 PromiseResolve ( C, x )
     17 //
     18 // 1. If IsPromise(x) is true, then
     19 //   a. Let xConstructor be ? Get(x, "constructor").
     20 //   b. If SameValue(xConstructor, C) is true, return x.
     21 // ...
     22 
     23 let p = Promise.resolve(0);
     24 
     25 // Add a getter to execute user-defined operations when PromiseResolve is called.
     26 Object.defineProperty(p, "constructor", {
     27  get() {
     28    // Request an interrupt.
     29    interruptIf(true);
     30    return Promise;
     31  }
     32 });
     33 
     34 setInterruptCallback(function() {
     35  // Return false from the interrupt handler to stop execution.
     36  return false;
     37 });
     38 
     39 var iterator = {
     40  [Symbol.iterator]() {
     41    return this;
     42  },
     43  next() {
     44    return {value: p, done: false};
     45  },
     46  return() {
     47    throw "bad error";
     48  },
     49 };
     50 
     51 async function f() {
     52  for await (let v of iterator) {}
     53 }
     54 
     55 f();