feat: add helper functions to natives store + refac

This commit is contained in:
Percs 2024-12-10 20:45:51 +00:00 committed by GitHub
parent 70f0315791
commit ef8735f95a
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
6 changed files with 164 additions and 121 deletions

View file

@ -5,7 +5,7 @@ import { ScramjetClient } from "../../client";
export default function (client: ScramjetClient, self: Self) {
let worker;
if (self.Worker && flagEnabled("syncxhr", client.url)) {
worker = new client.natives["Worker"](config.files.sync);
worker = client.natives.construct("Worker", config.files.sync);
}
const ARGS = Symbol("xhr original args");
const HEADERS = Symbol("xhr headers");
@ -44,7 +44,7 @@ export default function (client: ScramjetClient, self: Self) {
const sab = new SharedArrayBuffer(1024, { maxByteLength: 2147483647 });
const view = new DataView(sab);
client.natives["Worker.prototype.postMessage"].call(worker, {
client.natives.call("Worker.prototype.postMessage", worker, {
sab,
args,
headers: ctx.this[HEADERS],