mirror of
https://github.com/MercuryWorkshop/scramjet.git
synced 2025-05-12 14:00:01 -04:00
add lint command, lint and lint:fix project
This commit is contained in:
parent
430c7ad6ec
commit
93b609932d
23 changed files with 36916 additions and 25 deletions
|
@ -10,7 +10,7 @@
|
|||
"max-lines-per-function": [
|
||||
"error",
|
||||
{
|
||||
"max": 200,
|
||||
"max": 250,
|
||||
"skipComments": true
|
||||
}
|
||||
],
|
||||
|
|
|
@ -14,7 +14,9 @@
|
|||
"dev": "node server.js",
|
||||
"prepublish": "pnpm build",
|
||||
"pub": "pnpm publish --no-git-checks --access public",
|
||||
"format": "prettier --config prettier.json --write ."
|
||||
"format": "prettier --config prettier.json --write .",
|
||||
"lint": "eslint ./src/ --ext .ts",
|
||||
"lint:fix": "eslint ./src/ --ext .ts --fix"
|
||||
},
|
||||
"files": [
|
||||
"dist",
|
||||
|
|
|
@ -248,6 +248,7 @@ export class ScramjetClient {
|
|||
call: () => {
|
||||
earlyreturn = true;
|
||||
returnValue = Reflect.construct(ctx.fn, ctx.args, ctx.newTarget);
|
||||
|
||||
return returnValue;
|
||||
},
|
||||
};
|
||||
|
@ -279,6 +280,7 @@ export class ScramjetClient {
|
|||
call: () => {
|
||||
earlyreturn = true;
|
||||
returnValue = Reflect.apply(ctx.fn, ctx.this, ctx.args);
|
||||
|
||||
return returnValue;
|
||||
},
|
||||
};
|
||||
|
|
|
@ -17,11 +17,13 @@ export function createDocumentProxy(
|
|||
}
|
||||
|
||||
const value = Reflect.get(target, prop);
|
||||
|
||||
return value;
|
||||
},
|
||||
set(target, prop, newValue) {
|
||||
if (prop === "location") {
|
||||
location.href = encodeUrl(newValue, client.meta);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
|
@ -6,7 +6,6 @@ export default function (client: ScramjetClient, self: typeof window) {
|
|||
|
||||
if (data.scramjet$type === "cookie") {
|
||||
client.cookieStore.setCookies([data.cookie], new URL(data.url));
|
||||
return;
|
||||
}
|
||||
});
|
||||
|
||||
|
|
|
@ -93,7 +93,7 @@ export default function (client: ScramjetClient, self: typeof window) {
|
|||
const desc = originalhrefs[i];
|
||||
client.RawTrap(target, prop, {
|
||||
get(ctx) {
|
||||
let href = desc.get.call(ctx.this);
|
||||
const href = desc.get.call(ctx.this);
|
||||
if (!href) return href;
|
||||
|
||||
const url = new URL(decodeUrl(href));
|
||||
|
@ -124,7 +124,7 @@ export default function (client: ScramjetClient, self: typeof window) {
|
|||
const [name, value] = ctx.args;
|
||||
|
||||
const rule = htmlRules.find((rule) => {
|
||||
let r = rule[name];
|
||||
const r = rule[name];
|
||||
if (!r) return false;
|
||||
if (r === "*") return true;
|
||||
if (typeof r === "function") return false; // this can't happen but ts
|
||||
|
@ -225,10 +225,10 @@ export default function (client: ScramjetClient, self: typeof window) {
|
|||
client.Trap("Node.prototype.ownerDocument", {
|
||||
get(ctx) {
|
||||
return client.documentProxy;
|
||||
let doc = ctx.get() as Document | null;
|
||||
const doc = ctx.get() as Document | null;
|
||||
if (!doc) return null;
|
||||
|
||||
let scram: ScramjetClient = doc[SCRAMJETCLIENT];
|
||||
const scram: ScramjetClient = doc[SCRAMJETCLIENT];
|
||||
if (!scram) return doc; // ??
|
||||
|
||||
return scram.documentProxy;
|
||||
|
|
|
@ -53,6 +53,7 @@ export default function (client: ScramjetClient, self: Self) {
|
|||
client.Trap("navigator.serviceWorker.ready", {
|
||||
get(ctx) {
|
||||
console.log(registration);
|
||||
|
||||
return new Promise((resolve) => resolve(registration));
|
||||
},
|
||||
});
|
||||
|
|
|
@ -32,6 +32,7 @@ export function createGlobalProxy(
|
|||
set(target, prop, value) {
|
||||
if (prop === "location") {
|
||||
client.url = value;
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -39,6 +40,7 @@ export function createGlobalProxy(
|
|||
},
|
||||
has(target, prop) {
|
||||
if (prop === "$scramjet") return false;
|
||||
|
||||
return Reflect.has(target, prop);
|
||||
},
|
||||
ownKeys(target) {
|
||||
|
|
|
@ -1,8 +1,9 @@
|
|||
export function getOwnPropertyDescriptorHandler(target, prop) {
|
||||
let realDescriptor = Reflect.getOwnPropertyDescriptor(target, prop);
|
||||
const realDescriptor = Reflect.getOwnPropertyDescriptor(target, prop);
|
||||
|
||||
return realDescriptor;
|
||||
|
||||
let d: PropertyDescriptor = {};
|
||||
const d: PropertyDescriptor = {};
|
||||
|
||||
if (realDescriptor.enumerable !== undefined)
|
||||
d.enumerable = realDescriptor.enumerable;
|
||||
|
@ -22,5 +23,6 @@ export function getOwnPropertyDescriptorHandler(target, prop) {
|
|||
if (realDescriptor.value) {
|
||||
d.value = this.get(target, prop);
|
||||
}
|
||||
|
||||
return d;
|
||||
}
|
||||
|
|
|
@ -48,10 +48,11 @@ export function createLocationProxy(
|
|||
if (prop === "href") {
|
||||
// special case
|
||||
client.url = args[0];
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
let url = new URL(client.url.href);
|
||||
const url = new URL(client.url.href);
|
||||
url[prop] = args[0];
|
||||
client.url = url;
|
||||
},
|
||||
|
|
|
@ -15,9 +15,9 @@ export function argdbg(arg, recurse = []) {
|
|||
arg[Symbol.iterator] &&
|
||||
typeof arg[Symbol.iterator] === "function"
|
||||
)
|
||||
for (let prop in arg) {
|
||||
for (const prop in arg) {
|
||||
// make sure it's not a getter
|
||||
let desc = Object.getOwnPropertyDescriptor(arg, prop);
|
||||
const desc = Object.getOwnPropertyDescriptor(arg, prop);
|
||||
if (desc && desc.get) continue;
|
||||
|
||||
const ar = arg[prop];
|
||||
|
@ -37,6 +37,7 @@ export default function (client: ScramjetClient, self: typeof globalThis) {
|
|||
self.$scramdbg = function scramdbg(args, t) {
|
||||
if (args && typeof args === "object" && args.length > 0) argdbg(args);
|
||||
argdbg(t);
|
||||
|
||||
return t;
|
||||
};
|
||||
|
||||
|
|
|
@ -23,7 +23,7 @@ export default function (client: ScramjetClient, self: Self) {
|
|||
return this.ports;
|
||||
},
|
||||
source() {
|
||||
let scram: ScramjetClient = this.source[SCRAMJETCLIENT];
|
||||
const scram: ScramjetClient = this.source[SCRAMJETCLIENT];
|
||||
|
||||
if (scram) return scram.globalProxy;
|
||||
|
||||
|
|
|
@ -4,7 +4,7 @@ import { rewriteJs } from "../../shared";
|
|||
function rewriteFunction(ctx: ProxyCtx, client: ScramjetClient) {
|
||||
const stringifiedFunction = ctx.call().toString();
|
||||
|
||||
let content = rewriteJs(`return ${stringifiedFunction}`, client.meta);
|
||||
const content = rewriteJs(`return ${stringifiedFunction}`, client.meta);
|
||||
ctx.return(ctx.fn(content)());
|
||||
}
|
||||
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
import { ScramjetClient } from "../client";
|
||||
|
||||
let sourcemaps: {
|
||||
const sourcemaps: {
|
||||
source: string;
|
||||
map: [string, number, number][];
|
||||
}[] = [];
|
||||
|
@ -61,6 +61,7 @@ export default function (client: ScramjetClient, self: Self) {
|
|||
offset += end - start - str.length;
|
||||
i = start - starting + offset + str.length;
|
||||
}
|
||||
|
||||
return ctx.return(newString + stringified.slice(i));
|
||||
},
|
||||
});
|
||||
|
|
|
@ -8,8 +8,8 @@ export default function (client: ScramjetClient, self: typeof globalThis) {
|
|||
construct({ args, call }) {
|
||||
if (args[0] instanceof URL) args[0] = args[0].href;
|
||||
if (args[0].startsWith("blob:") || args[0].startsWith("data:")) {
|
||||
let data = syncfetch(client, args[0]);
|
||||
let id = Math.random().toString(8).slice(5);
|
||||
const data = syncfetch(client, args[0]);
|
||||
const id = Math.random().toString(8).slice(5);
|
||||
|
||||
args[0] = "/scramjet/worker?id=" + id;
|
||||
if (args[1] && args[1].type === "module") {
|
||||
|
|
|
@ -28,6 +28,7 @@ export function rewriteHtml(
|
|||
if (head) return head;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
|
@ -55,7 +56,12 @@ export function rewriteHtml(
|
|||
script(self.$scramjet.config["codecs"]),
|
||||
script("data:application/javascript;base64," + btoa(injected)),
|
||||
script(self.$scramjet.config["shared"]),
|
||||
script(self.$scramjet.config["client"])
|
||||
script(self.$scramjet.config["client"]),
|
||||
script("/vc/browser.js"),
|
||||
new Element("link", {
|
||||
rel: "stylesheet",
|
||||
href: "/vc/browser.css",
|
||||
})
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -186,7 +192,7 @@ function traverseParsedHtml(
|
|||
if (sel === "*" || sel.includes(node.name)) {
|
||||
if (node.attribs[attr] !== undefined) {
|
||||
const value = node.attribs[attr];
|
||||
let v = rule.fn(value, meta, cookieStore);
|
||||
const v = rule.fn(value, meta, cookieStore);
|
||||
|
||||
if (v === null) delete node.attribs[attr];
|
||||
else {
|
||||
|
|
|
@ -21,6 +21,7 @@ Error.stackTraceLimit = 50;
|
|||
export function rewriteJs(js: string | ArrayBuffer, meta: URLMeta) {
|
||||
if (self.$scramjet.config.flags.naiiveRewriter) {
|
||||
const text = typeof js === "string" ? js : new TextDecoder().decode(js);
|
||||
|
||||
return rewriteJsNaiive(text);
|
||||
}
|
||||
|
||||
|
|
|
@ -11,10 +11,10 @@ onconnect = (e) => {
|
|||
port.onmessage = ({ data }) => {
|
||||
console.log("thread: received message", data);
|
||||
const [task, ...args] = data;
|
||||
let token = syncToken++;
|
||||
const token = syncToken++;
|
||||
|
||||
try {
|
||||
let res = tasks[task](...args);
|
||||
const res = tasks[task](...args);
|
||||
console.log("thread: task", task, "completed with token", token);
|
||||
port.postMessage({
|
||||
token,
|
||||
|
|
|
@ -79,7 +79,7 @@ export async function swfetch(
|
|||
new URL(client.url).pathname.startsWith(self.$scramjet.config.prefix)
|
||||
) {
|
||||
// TODO: i was against cors emulation but we might actually break stuff if we send full origin/referrer always
|
||||
let url = new URL(decodeUrl(client.url));
|
||||
const url = new URL(decodeUrl(client.url));
|
||||
headers.set("Referer", url.toString());
|
||||
headers.set("Origin", url.origin);
|
||||
}
|
||||
|
@ -135,7 +135,7 @@ async function handleResponse(
|
|||
let responseBody: string | ArrayBuffer | ReadableStream;
|
||||
const responseHeaders = rewriteHeaders(response.rawHeaders, newmeta(url));
|
||||
|
||||
let maybeHeaders = responseHeaders["set-cookie"] || [];
|
||||
const maybeHeaders = responseHeaders["set-cookie"] || [];
|
||||
for (const cookie in maybeHeaders) {
|
||||
if (client)
|
||||
client.postMessage({
|
||||
|
|
|
@ -32,11 +32,13 @@ export class ScramjetServiceWorker {
|
|||
|
||||
if (data.scramjet$type === "registerServiceWorker") {
|
||||
this.serviceWorkers.push(new FakeServiceWorker(data.port, data.origin));
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if (data.scramjet$type === "cookie") {
|
||||
this.cookieStore.setCookies([data.cookie], new URL(data.url));
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -49,7 +51,6 @@ export class ScramjetServiceWorker {
|
|||
this.dataworkerpromises[data.id] = { promise, resolve };
|
||||
resolve(data.data);
|
||||
}
|
||||
return;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
|
|
@ -30,10 +30,12 @@ export class ScramjetThreadpool {
|
|||
thread.handle.onmessage = (e) => {
|
||||
if (e.data === "ready") {
|
||||
thread.ready = true;
|
||||
|
||||
return;
|
||||
}
|
||||
if (e.data === "idle") {
|
||||
thread.busy = false;
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -70,7 +72,7 @@ export class ScramjetThreadpool {
|
|||
if (!thread) throw new Error("No threads available");
|
||||
thread.busy = true;
|
||||
|
||||
let token = thread.syncToken++;
|
||||
const token = thread.syncToken++;
|
||||
|
||||
// console.log("runthread: dispatching task", task, "to thread", thread, "of token", token)
|
||||
return new Promise((resolve, reject) => {
|
||||
|
|
1549
static/vc/browser.css
Normal file
1549
static/vc/browser.css
Normal file
File diff suppressed because it is too large
Load diff
35319
static/vc/browser.js
Normal file
35319
static/vc/browser.js
Normal file
File diff suppressed because it is too large
Load diff
Loading…
Add table
Add a link
Reference in a new issue