mirror of
https://github.com/MercuryWorkshop/scramjet.git
synced 2025-05-12 22:10:01 -04:00
lint fixes
This commit is contained in:
parent
8ff087efb2
commit
c3ccd8f238
12 changed files with 41 additions and 44 deletions
|
@ -7,11 +7,11 @@ import { getOwnPropertyDescriptorHandler } from "../helpers";
|
|||
export const order = 2;
|
||||
|
||||
export const enabled = () => config.flags.serviceworkers;
|
||||
export function disabled(client: ScramjetClient, self: Self) {
|
||||
export function disabled(_client: ScramjetClient, _self: Self) {
|
||||
Reflect.deleteProperty(Navigator.prototype, "serviceWorker");
|
||||
}
|
||||
|
||||
export default function (client: ScramjetClient, self: Self) {
|
||||
export default function (client: ScramjetClient, _self: Self) {
|
||||
let registration;
|
||||
|
||||
client.Proxy("EventTarget.prototype.addEventListener", {
|
||||
|
@ -45,7 +45,7 @@ export default function (client: ScramjetClient, self: Self) {
|
|||
});
|
||||
|
||||
client.Trap("navigator.serviceWorker.ready", {
|
||||
get(ctx) {
|
||||
get(_ctx) {
|
||||
console.log(registration);
|
||||
|
||||
return new Promise((resolve) => resolve(registration));
|
||||
|
@ -53,7 +53,7 @@ export default function (client: ScramjetClient, self: Self) {
|
|||
});
|
||||
|
||||
client.Trap("navigator.serviceWorker.controller", {
|
||||
get(ctx) {
|
||||
get(_ctx) {
|
||||
return registration?.active;
|
||||
},
|
||||
});
|
||||
|
|
|
@ -63,7 +63,7 @@ export default function (client: ScramjetClient, self: typeof window) {
|
|||
ownKeys(target) {
|
||||
return Reflect.ownKeys(target)
|
||||
.filter((f) => typeof f === "string" && f.startsWith(client.url.host))
|
||||
.map((f) => f.substring(client.url.host.length + 1));
|
||||
.map((f) => typeof f === "string" ? f.substring(client.url.host.length + 1) : f);
|
||||
},
|
||||
|
||||
getOwnPropertyDescriptor(target, property) {
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
// import { encodeUrl } from "../shared";
|
||||
import { ScramjetClient } from "./client";
|
||||
import { indirectEval } from "./shared/eval";
|
||||
// import { config } from "../shared";
|
||||
import { getOwnPropertyDescriptorHandler } from "./helpers";
|
||||
|
||||
|
|
|
@ -2,27 +2,26 @@ export function getOwnPropertyDescriptorHandler(target, prop) {
|
|||
const realDescriptor = Reflect.getOwnPropertyDescriptor(target, prop);
|
||||
|
||||
return realDescriptor;
|
||||
// const d: PropertyDescriptor = {};
|
||||
|
||||
const d: PropertyDescriptor = {};
|
||||
// if (realDescriptor.enumerable !== undefined)
|
||||
// d.enumerable = realDescriptor.enumerable;
|
||||
// if (realDescriptor.configurable !== undefined)
|
||||
// d.configurable = realDescriptor.configurable;
|
||||
// if (realDescriptor.writable !== undefined)
|
||||
// d.writable = realDescriptor.writable;
|
||||
|
||||
if (realDescriptor.enumerable !== undefined)
|
||||
d.enumerable = realDescriptor.enumerable;
|
||||
if (realDescriptor.configurable !== undefined)
|
||||
d.configurable = realDescriptor.configurable;
|
||||
if (realDescriptor.writable !== undefined)
|
||||
d.writable = realDescriptor.writable;
|
||||
// if (realDescriptor.get) {
|
||||
// d.get = () => this.get(target, prop);
|
||||
// }
|
||||
|
||||
if (realDescriptor.get) {
|
||||
d.get = () => this.get(target, prop);
|
||||
}
|
||||
|
||||
if (realDescriptor.set) {
|
||||
d.set = (value) => this.set(target, prop, value);
|
||||
}
|
||||
|
||||
if (realDescriptor.value) {
|
||||
d.value = this.get(target, prop);
|
||||
}
|
||||
|
||||
return d;
|
||||
// if (realDescriptor.set) {
|
||||
// d.set = (value) => this.set(target, prop, value);
|
||||
// }
|
||||
|
||||
// if (realDescriptor.value) {
|
||||
// d.value = this.get(target, prop);
|
||||
// }
|
||||
|
||||
// return d;
|
||||
}
|
||||
|
|
|
@ -3,9 +3,9 @@
|
|||
import { isemulatedsw } from "../..";
|
||||
import { unrewriteUrl } from "../../../shared";
|
||||
import { ScramjetClient } from "../../client";
|
||||
import { rewriteUrl, rewriteHeaders } from "../../../shared";
|
||||
import { rewriteUrl } from "../../../shared";
|
||||
|
||||
export default function (client: ScramjetClient, self: typeof globalThis) {
|
||||
export default function (client: ScramjetClient, _self: typeof globalThis) {
|
||||
client.Proxy("fetch", {
|
||||
apply(ctx) {
|
||||
if (typeof ctx.args[0] === "string" || ctx.args[0] instanceof URL) {
|
||||
|
|
|
@ -59,7 +59,7 @@ export default function (client: ScramjetClient, self: typeof globalThis) {
|
|||
fakeWebSocket.dispatchEvent(fakeev);
|
||||
}
|
||||
|
||||
barews.addEventListener("open", (ev) => {
|
||||
barews.addEventListener("open", () => {
|
||||
fakeEventSend(new Event("open"));
|
||||
});
|
||||
barews.addEventListener("close", (ev) => {
|
||||
|
@ -76,7 +76,7 @@ export default function (client: ScramjetClient, self: typeof globalThis) {
|
|||
|
||||
fakeEventSend(fakeev);
|
||||
});
|
||||
barews.addEventListener("error", (ev) => {
|
||||
barews.addEventListener("error", () => {
|
||||
fakeEventSend(new Event("error"));
|
||||
});
|
||||
|
||||
|
|
|
@ -51,17 +51,17 @@ export default function (client: ScramjetClient, self: typeof window) {
|
|||
|
||||
if (desc.get) {
|
||||
client.RawProxy(desc, "get", {
|
||||
apply(ctx) {
|
||||
apply(getCtx) {
|
||||
// value of this in the getter needs to be corrected
|
||||
unproxy(ctx, client);
|
||||
unproxy(getCtx, client);
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
if (desc.set) {
|
||||
client.RawProxy(desc, "set", {
|
||||
apply(ctx) {
|
||||
unproxy(ctx, client);
|
||||
apply(setCtx) {
|
||||
unproxy(setCtx, client);
|
||||
},
|
||||
});
|
||||
}
|
||||
|
|
|
@ -138,6 +138,7 @@ export const htmlRules: {
|
|||
// because they can't be fetch'd
|
||||
return unrewriteBlob(value);
|
||||
}
|
||||
|
||||
return rewriteUrl(value, meta);
|
||||
},
|
||||
src: ["video", "audio"],
|
||||
|
|
|
@ -25,7 +25,7 @@ export function rewriteJs(js: string | ArrayBuffer, meta: URLMeta) {
|
|||
return rewriteJsNaiive(text);
|
||||
}
|
||||
|
||||
const before = performance.now();
|
||||
// const before = performance.now();
|
||||
if (typeof js === "string") {
|
||||
js = new TextDecoder().decode(
|
||||
rewrite_js(js, meta.base.href, self.$scramjet)
|
||||
|
@ -37,7 +37,7 @@ export function rewriteJs(js: string | ArrayBuffer, meta: URLMeta) {
|
|||
self.$scramjet
|
||||
);
|
||||
}
|
||||
const after = performance.now();
|
||||
// const after = performance.now();
|
||||
|
||||
// dbg.debug("Rewrite took", Math.floor((after - before) * 10) / 10, "ms");
|
||||
|
||||
|
|
|
@ -14,12 +14,14 @@ function tryCanParseURL(url: string, origin?: string | URL): URL | null {
|
|||
}
|
||||
|
||||
export function rewriteBlob(url: string, meta: URLMeta) {
|
||||
let blob = new URL(url.substring("blob:".length));
|
||||
const blob = new URL(url.substring("blob:".length));
|
||||
|
||||
return "blob:" + meta.origin.origin + blob.pathname;
|
||||
}
|
||||
|
||||
export function unrewriteBlob(url: string) {
|
||||
let blob = new URL(url.substring("blob:".length));
|
||||
const blob = new URL(url.substring("blob:".length));
|
||||
|
||||
return "blob:" + location.origin + blob.pathname;
|
||||
}
|
||||
|
||||
|
|
|
@ -57,7 +57,7 @@ export async function swfetch(
|
|||
dataurl = unrewriteBlob(dataurl);
|
||||
}
|
||||
|
||||
let response: Response = await fetch(dataurl, {});
|
||||
const response: Response = await fetch(dataurl, {});
|
||||
|
||||
let body: BodyType;
|
||||
|
||||
|
@ -285,15 +285,12 @@ async function rewriteBody(
|
|||
} else {
|
||||
return response.body;
|
||||
}
|
||||
break;
|
||||
case "script":
|
||||
return rewriteJs(await response.arrayBuffer(), meta);
|
||||
// Disable threading for now, it's causing issues.
|
||||
// responseBody = await this.threadpool.rewriteJs(await responseBody.arrayBuffer(), url.toString());
|
||||
break;
|
||||
case "style":
|
||||
return rewriteCss(await response.text(), meta);
|
||||
break;
|
||||
case "sharedworker":
|
||||
case "worker":
|
||||
return rewriteWorkers(await response.arrayBuffer(), workertype, meta);
|
||||
|
|
|
@ -2,7 +2,6 @@ import { FakeServiceWorker } from "./fakesw";
|
|||
import { swfetch } from "./fetch";
|
||||
import { ScramjetThreadpool } from "./threadpool";
|
||||
import type BareClient from "@mercuryworkshop/bare-mux";
|
||||
import { ScramjetConfig } from "../types";
|
||||
|
||||
export class ScramjetServiceWorker extends EventTarget {
|
||||
client: BareClient;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue