tor-browser

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

test_ReadableStream_from.js (832B)


      1 /* This Source Code Form is subject to the terms of the Mozilla Public
      2 * License, v. 2.0. If a copy of the MPL was not distributed with this
      3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
      4 
      5 add_task(async function run_test() {
      6  let sb = new Cu.Sandbox('http://www.example.com');
      7 
      8  let done = false;
      9  let iterator = {
     10    [Symbol.asyncIterator]() {
     11      return this;
     12    },
     13 
     14    next() {
     15      let promise = Cu.evalInSandbox(`Promise.resolve({done: ${done}, value: {hello: "world"}})`, sb);
     16      done = true;
     17      return promise;
     18    }
     19  }
     20 
     21  let stream = ReadableStream.from(iterator);
     22  let reader = stream.getReader();
     23  let result = await reader.read();
     24  Assert.equal(result.done, false);
     25  Assert.equal(result.value?.hello, "world");
     26  result = await reader.read();
     27  Assert.equal(result.done, true);
     28 });