Skip to content

Commit e547249

Browse files
committed
remove cross realm .apply and .call
1 parent 368d180 commit e547249

File tree

1 file changed

+26
-33
lines changed

1 file changed

+26
-33
lines changed

src/client/shared/unproxy.ts

Lines changed: 26 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -89,39 +89,32 @@ export default function (client: ScramjetClient, self: typeof window) {
8989
ctx.return(desc);
9090
},
9191
});
92-
client.Proxy(
93-
[
94-
"Function.prototype.bind",
95-
"Function.prototype.call",
96-
"Function.prototype.apply",
97-
],
98-
{
99-
apply(ctx) {
100-
if (
101-
(ctx.args[0] instanceof Window &&
102-
ctx.args[0] !== client.globalProxy) ||
103-
(ctx.args[0] instanceof Document &&
104-
ctx.args[0] !== client.documentProxy)
105-
) {
106-
const client = ctx.args[0][SCRAMJETCLIENT];
107-
ctx.this = new Proxy(ctx.this, {
108-
apply(target, that, args) {
109-
if (that === client.globalProxy) that = client.global;
110-
if (that === client.documentProxy) that = client.global.document;
111-
112-
for (const i in args) {
113-
if (args[i] === client.globalProxy) args[i] = client.global;
114-
if (args[i] === client.documentProxy)
115-
args[i] = client.global.document;
116-
}
117-
118-
return Reflect.apply(target, that, args);
119-
},
120-
});
121-
}
122-
},
123-
}
124-
);
92+
client.Proxy("Function.prototype.bind", {
93+
apply(ctx) {
94+
if (
95+
(ctx.args[0] instanceof Window && ctx.args[0] !== client.globalProxy) ||
96+
(ctx.args[0] instanceof Document &&
97+
ctx.args[0] !== client.documentProxy)
98+
) {
99+
const client = ctx.args[0][SCRAMJETCLIENT];
100+
console.log(ctx.this);
101+
ctx.this = new Proxy(ctx.this, {
102+
apply(target, that, args) {
103+
if (that === client.globalProxy) that = client.global;
104+
if (that === client.documentProxy) that = client.global.document;
105+
106+
for (const i in args) {
107+
if (args[i] === client.globalProxy) args[i] = client.global;
108+
if (args[i] === client.documentProxy)
109+
args[i] = client.global.document;
110+
}
111+
112+
return Reflect.apply(target, that, args);
113+
},
114+
});
115+
}
116+
},
117+
});
125118
}
126119

127120
export function unproxy(ctx: ProxyCtx, client: ScramjetClient) {

0 commit comments

Comments
 (0)