This commit is contained in:
Avad3 2024-07-14 15:38:21 -04:00
parent 212a9510d5
commit ba42d3083e
2 changed files with 22 additions and 8 deletions

View file

@ -10,7 +10,7 @@ const FunctionProxy = new Proxy(Function, {
},
apply(target, thisArg, argArray) {
if (argArray.length === 1) {
return Reflect.apply(target, undefined, rewriteJs(argArray[0]));
return Reflect.apply(target, undefined, [rewriteJs(argArray[0])]);
} else {
return Reflect.apply(target, undefined, [...argArray.map((x, index) => index === argArray.length - 1), rewriteJs(argArray[argArray.length - 1])])
}
@ -21,8 +21,8 @@ delete window.Function;
window.Function = FunctionProxy;
delete window.eval;
// since the function proxy is already rewriting the js we can just reuse it for the eval proxy
window.eval = (str: string) => window.Function(str);
window.eval = new Proxy(window.eval, {
apply(target, thisArg, argArray) {
return Reflect.apply(target, thisArg, [rewriteJs(argArray[0])]);
},
})

View file

@ -31,7 +31,6 @@ export function rewriteJs(js: string, origin?: URL) {
"this",
"parent",
"top",
"this",
"location"
]
@ -60,11 +59,26 @@ export function rewriteJs(js: string, origin?: URL) {
if (node.source) node.source.value = encodeUrl(node.source.value as string, origin);
},
// js rweriting notrdone
MemberExpression: (node: ESTree.MemberExpression) => {
if (node.object.type === "Identifier" && identifierList.includes(node.object.name)) {
node.object.name = `$s(${node.object.name})`;
}
},
AssignmentExpression: (node: ESTree.AssignmentExpression) => {
if (node.left.type === "Identifier" && identifierList.includes(node.left.name)) {
node.left.name = `$s(${node.left.name})`;
}
if (node.right.type === "Identifier" && identifierList.includes(node.right.name)) {
node.right.name = `$s(${node.right.name})`;
}
},
VariableDeclarator: (node: ESTree.VariableDeclarator) => {
if (node.init.type === "Identifier" && identifierList.includes(node.init.name)) {
node.init.name = `$s(${node.init.name})`;
}
}
});