mirror of
https://github.com/MercuryWorkshop/scramjet.git
synced 2025-05-13 14:30:02 -04:00
fix meriyah crash
This commit is contained in:
parent
37b268bfeb
commit
c703ed39ca
4 changed files with 31 additions and 17 deletions
|
@ -1,6 +1,8 @@
|
||||||
import { encodeUrl } from "../shared/rewriters/url";
|
import { encodeUrl } from "../shared/rewriters/url";
|
||||||
|
export const URL = globalThis.URL;
|
||||||
|
|
||||||
URL = new Proxy(URL, {
|
if (globalThis.window) {
|
||||||
|
window.URL = new Proxy(URL, {
|
||||||
construct(target, argArray, newTarget) {
|
construct(target, argArray, newTarget) {
|
||||||
if (typeof argArray[0] === "string") argArray[0] = encodeUrl(argArray[0]);
|
if (typeof argArray[0] === "string") argArray[0] = encodeUrl(argArray[0]);
|
||||||
if (typeof argArray[1] === "string") argArray[1] = encodeUrl(argArray[1]);
|
if (typeof argArray[1] === "string") argArray[1] = encodeUrl(argArray[1]);
|
||||||
|
@ -8,3 +10,4 @@ URL = new Proxy(URL, {
|
||||||
return Reflect.construct(target, argArray, newTarget);
|
return Reflect.construct(target, argArray, newTarget);
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
}
|
||||||
|
|
|
@ -18,6 +18,8 @@ import * as ESTree from "estree";
|
||||||
|
|
||||||
|
|
||||||
export function rewriteJs(js: string, origin?: URL) {
|
export function rewriteJs(js: string, origin?: URL) {
|
||||||
|
const htmlcomment = /<!--[\s\S]*?-->/g;
|
||||||
|
js = js.replace(htmlcomment, "");
|
||||||
try {
|
try {
|
||||||
const ast = parseModule(js, {
|
const ast = parseModule(js, {
|
||||||
module: true,
|
module: true,
|
||||||
|
@ -76,7 +78,7 @@ export function rewriteJs(js: string, origin?: URL) {
|
||||||
},
|
},
|
||||||
|
|
||||||
VariableDeclarator: (node: ESTree.VariableDeclarator) => {
|
VariableDeclarator: (node: ESTree.VariableDeclarator) => {
|
||||||
if (node.init.type === "Identifier" && identifierList.includes(node.init.name)) {
|
if (node.init && node.init.type === "Identifier" && identifierList.includes(node.init.name)) {
|
||||||
node.init.name = `$s(${node.init.name})`;
|
node.init.name = `$s(${node.init.name})`;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -85,7 +87,8 @@ export function rewriteJs(js: string, origin?: URL) {
|
||||||
customTraveler.go(ast);
|
customTraveler.go(ast);
|
||||||
|
|
||||||
return generate(ast);
|
return generate(ast);
|
||||||
} catch {
|
} catch (e) {
|
||||||
|
console.error(e);
|
||||||
console.log(js);
|
console.log(js);
|
||||||
|
|
||||||
return js;
|
return js;
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
import { URL } from "../../client/url";
|
||||||
import { rewriteJs } from "./js";
|
import { rewriteJs } from "./js";
|
||||||
|
|
||||||
function canParseUrl(url: string, origin?: URL) {
|
function canParseUrl(url: string, origin?: URL) {
|
||||||
|
|
7
tests/location.html
Normal file
7
tests/location.html
Normal file
|
@ -0,0 +1,7 @@
|
||||||
|
<head></head>
|
||||||
|
<script>
|
||||||
|
function f() {
|
||||||
|
location = "http://www.google.com";
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
<button onclick='f()'>Google</button>
|
Loading…
Add table
Add a link
Reference in a new issue