mirror of
https://github.com/MercuryWorkshop/scramjet.git
synced 2025-05-17 08:00:02 -04:00
fix: function proxy and frame elements
This commit is contained in:
parent
e5dff7f6fc
commit
06583fb0b2
3 changed files with 60 additions and 19 deletions
|
@ -27,7 +27,7 @@
|
||||||
],
|
],
|
||||||
"keywords": [],
|
"keywords": [],
|
||||||
"author": "",
|
"author": "",
|
||||||
"license": "ISC",
|
"license": "MIT",
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@eslint/eslintrc": "^3.2.0",
|
"@eslint/eslintrc": "^3.2.0",
|
||||||
"@eslint/js": "^9.16.0",
|
"@eslint/js": "^9.16.0",
|
||||||
|
|
|
@ -263,6 +263,57 @@ export default function (client: ScramjetClient, self: typeof window) {
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
|
client.Trap("HTMLFrameElement.prototype.contentWindow", {
|
||||||
|
get(ctx) {
|
||||||
|
const realwin = ctx.get() as Window;
|
||||||
|
if (!realwin) return realwin;
|
||||||
|
|
||||||
|
if (SCRAMJETCLIENT in realwin) {
|
||||||
|
return realwin[SCRAMJETCLIENT].globalProxy;
|
||||||
|
} else {
|
||||||
|
// hook the iframe
|
||||||
|
const newclient = new ScramjetClient(realwin);
|
||||||
|
newclient.hook();
|
||||||
|
|
||||||
|
return newclient.globalProxy;
|
||||||
|
}
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
client.Trap("HTMLFrameElement.prototype.contentDocument", {
|
||||||
|
get(ctx) {
|
||||||
|
const contentwindow =
|
||||||
|
client.descriptors["HTMLFrameElement.prototype.contentWindow"].get;
|
||||||
|
const realwin = contentwindow.apply(ctx.this);
|
||||||
|
if (!realwin) return realwin;
|
||||||
|
|
||||||
|
if (SCRAMJETCLIENT in realwin) {
|
||||||
|
return realwin[SCRAMJETCLIENT].documentProxy;
|
||||||
|
} else {
|
||||||
|
const newclient = new ScramjetClient(realwin);
|
||||||
|
newclient.hook();
|
||||||
|
|
||||||
|
return newclient.documentProxy;
|
||||||
|
}
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
client.Proxy(
|
||||||
|
[
|
||||||
|
"HTMLIFrameElement.prototype.getSVGDocument",
|
||||||
|
"HTMLObjectElement.prototype.getSVGDocument",
|
||||||
|
"HTMLEmbedElement.prototype.getSVGDocument",
|
||||||
|
],
|
||||||
|
{
|
||||||
|
apply(ctx) {
|
||||||
|
const doc = ctx.call();
|
||||||
|
if (doc) {
|
||||||
|
ctx.return(ctx.this.contentDocument);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
client.Trap("TreeWalker.prototype.currentNode", {
|
client.Trap("TreeWalker.prototype.currentNode", {
|
||||||
get(ctx) {
|
get(ctx) {
|
||||||
return ctx.get();
|
return ctx.get();
|
||||||
|
@ -312,22 +363,6 @@ export default function (client: ScramjetClient, self: typeof window) {
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
client.Proxy(
|
|
||||||
[
|
|
||||||
"HTMLIFrameElement.prototype.getSVGDocument",
|
|
||||||
"HTMLObjectElement.prototype.getSVGDocument",
|
|
||||||
"HTMLEmbedElement.prototype.getSVGDocument",
|
|
||||||
],
|
|
||||||
{
|
|
||||||
apply(ctx) {
|
|
||||||
const doc = ctx.call();
|
|
||||||
if (doc) {
|
|
||||||
ctx.return(ctx.this.contentDocument);
|
|
||||||
}
|
|
||||||
},
|
|
||||||
}
|
|
||||||
);
|
|
||||||
|
|
||||||
client.Proxy("Node.prototype.getRootNode", {
|
client.Proxy("Node.prototype.getRootNode", {
|
||||||
apply(ctx) {
|
apply(ctx) {
|
||||||
const n = ctx.call() as Node;
|
const n = ctx.call() as Node;
|
||||||
|
|
|
@ -10,7 +10,12 @@ function rewriteFunction(ctx: ProxyCtx, client: ScramjetClient) {
|
||||||
|
|
||||||
export default function (client: ScramjetClient, _self: Self) {
|
export default function (client: ScramjetClient, _self: Self) {
|
||||||
const handler: Proxy = {
|
const handler: Proxy = {
|
||||||
apply(ctx) {
|
apply(ctx: ProxyCtx) {
|
||||||
|
if ((ctx.fn as any).alreadyProxied) {
|
||||||
|
debugger;
|
||||||
|
throw new Error("blah slop");
|
||||||
|
}
|
||||||
|
(ctx.fn as any).alreadyProxied = true;
|
||||||
rewriteFunction(ctx, client);
|
rewriteFunction(ctx, client);
|
||||||
},
|
},
|
||||||
construct(ctx) {
|
construct(ctx) {
|
||||||
|
@ -19,7 +24,7 @@ export default function (client: ScramjetClient, _self: Self) {
|
||||||
};
|
};
|
||||||
|
|
||||||
client.Proxy("Function", handler);
|
client.Proxy("Function", handler);
|
||||||
|
/*
|
||||||
// god i love javascript
|
// god i love javascript
|
||||||
client.RawProxy(function () {}.constructor.prototype, "constructor", handler);
|
client.RawProxy(function () {}.constructor.prototype, "constructor", handler);
|
||||||
client.RawProxy(
|
client.RawProxy(
|
||||||
|
@ -37,4 +42,5 @@ export default function (client: ScramjetClient, _self: Self) {
|
||||||
"constructor",
|
"constructor",
|
||||||
handler
|
handler
|
||||||
);
|
);
|
||||||
|
*/
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue