mirror of
https://github.com/MercuryWorkshop/scramjet.git
synced 2025-05-15 23:30:00 -04:00
add more flags
This commit is contained in:
parent
7adf76d37f
commit
4d1b7ef1b8
10 changed files with 85 additions and 57 deletions
|
@ -133,7 +133,7 @@ export class ScramjetClient {
|
|||
for (const module of modules) {
|
||||
if (!module.enabled || module.enabled())
|
||||
module.default(this, this.global);
|
||||
else module.disabled(this, this.global);
|
||||
else if (module.disabled) module.disabled(this, this.global);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
44
src/client/shared/err.ts
Normal file
44
src/client/shared/err.ts
Normal file
|
@ -0,0 +1,44 @@
|
|||
import { config } from "../../shared";
|
||||
import { ScramjetClient } from "../client";
|
||||
|
||||
export const enabled = () => config.flags.captureErrors;
|
||||
|
||||
export default function (client: ScramjetClient, self: typeof globalThis) {
|
||||
function argdbg(arg) {
|
||||
switch (typeof arg) {
|
||||
case "string":
|
||||
if (arg.includes("scramjet") && !arg.includes("\n")) debugger;
|
||||
break;
|
||||
case "object":
|
||||
if (arg instanceof Location) debugger;
|
||||
if (
|
||||
arg &&
|
||||
arg[Symbol.iterator] &&
|
||||
typeof arg[Symbol.iterator] === "function"
|
||||
)
|
||||
for (let ar of arg) argdbg(ar);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
self.$scramerr = function scramerr(e) {
|
||||
console.warn("CAUGHT ERROR", e);
|
||||
};
|
||||
|
||||
self.$scramdbg = function scramdbg(args, t) {
|
||||
if (args && typeof args === "object" && args.length > 0) argdbg(args);
|
||||
argdbg(t);
|
||||
return t;
|
||||
};
|
||||
|
||||
client.Proxy("Promise.prototype.catch", {
|
||||
apply(ctx) {
|
||||
ctx.args[0] = new Proxy(ctx.args[0], {
|
||||
apply(target, thisArg, argArray) {
|
||||
// console.warn("CAUGHT PROMISE REJECTION", argArray);
|
||||
Reflect.apply(target, thisArg, argArray);
|
||||
},
|
||||
});
|
||||
},
|
||||
});
|
||||
}
|
|
@ -76,41 +76,4 @@ export default function (client: ScramjetClient, self: typeof globalThis) {
|
|||
writable: false,
|
||||
configurable: false,
|
||||
});
|
||||
|
||||
function argdbg(arg) {
|
||||
switch (typeof arg) {
|
||||
case "string":
|
||||
if (arg.includes("scramjet") && !arg.includes("\n")) debugger;
|
||||
break;
|
||||
case "object":
|
||||
if (arg instanceof Location) debugger;
|
||||
if (
|
||||
arg &&
|
||||
arg[Symbol.iterator] &&
|
||||
typeof arg[Symbol.iterator] === "function"
|
||||
)
|
||||
for (let ar of arg) argdbg(ar);
|
||||
break;
|
||||
}
|
||||
}
|
||||
self.$scramerr = function scramerr(e) {
|
||||
console.warn("CAUGHT ERROR", e);
|
||||
};
|
||||
|
||||
self.$scramdbg = function scramdbg(args, t) {
|
||||
if (args && typeof args === "object" && args.length > 0) argdbg(args);
|
||||
argdbg(t);
|
||||
return t;
|
||||
};
|
||||
|
||||
// client.Proxy("Promise.prototype.catch", {
|
||||
// apply(ctx) {
|
||||
// ctx.args[0] = new Proxy(ctx.args[0], {
|
||||
// apply(target, thisArg, argArray) {
|
||||
// // console.warn("CAUGHT PROMISE REJECTION", argArray);
|
||||
// Reflect.apply(target, thisArg, argArray);
|
||||
// },
|
||||
// });
|
||||
// },
|
||||
// });
|
||||
}
|
||||
|
|
|
@ -10,7 +10,7 @@ export class ScramjetController {
|
|||
codec: Codec;
|
||||
|
||||
constructor(config: ScramjetConfig) {
|
||||
const defaultConfig = {
|
||||
const defaultConfig: Partial<ScramjetConfig> = {
|
||||
prefix: "/scramjet/",
|
||||
codec: "plain",
|
||||
wrapfn: "$scramjet$wrap",
|
||||
|
@ -27,6 +27,8 @@ export class ScramjetController {
|
|||
codecs: "/scramjet.codecs.js",
|
||||
flags: {
|
||||
serviceworkers: true,
|
||||
naiiveRewriter: false,
|
||||
captureErrors: false,
|
||||
},
|
||||
};
|
||||
|
||||
|
|
|
@ -23,6 +23,11 @@ export function rewriteJs(js: string | ArrayBuffer, origin?: URL) {
|
|||
if ("window" in globalThis)
|
||||
origin = origin ?? new URL(decodeUrl(location.href));
|
||||
|
||||
if (self.$scramjet.config.flags.naiiveRewriter) {
|
||||
const text = typeof js === "string" ? js : new TextDecoder().decode(js);
|
||||
return rewriteJsNaiive(text, origin);
|
||||
}
|
||||
|
||||
const before = performance.now();
|
||||
if (typeof js === "string") {
|
||||
js = new TextDecoder().decode(
|
||||
|
|
3
src/types.d.ts
vendored
3
src/types.d.ts
vendored
|
@ -21,7 +21,8 @@ import { ScramjetFrame } from "./controller/frame";
|
|||
|
||||
type ScramjetFlags = {
|
||||
serviceworkers: boolean;
|
||||
naiiverewriter: boolean;
|
||||
naiiveRewriter: boolean;
|
||||
captureErrors: boolean;
|
||||
};
|
||||
|
||||
interface ScramjetConfig {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue