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