add more flags

This commit is contained in:
velzie 2024-08-31 14:49:08 -04:00
parent 7adf76d37f
commit 4d1b7ef1b8
No known key found for this signature in database
GPG key ID: 048413F95F0DDE1F
10 changed files with 85 additions and 57 deletions

44
src/client/shared/err.ts Normal file
View 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);
},
});
},
});
}