refactor window and document proxies

This commit is contained in:
velzie 2024-08-25 15:48:12 -04:00
parent f3f1a2ed41
commit 6f51642afb
No known key found for this signature in database
GPG key ID: 048413F95F0DDE1F
9 changed files with 99 additions and 99 deletions

View file

@ -22,7 +22,7 @@ export default function (client: ScramjetClient, self: Self) {
source() {
let scram: ScramjetClient = this.source[ScramjetClient.SCRAMJET];
if (scram) return scram.windowProxy;
if (scram) return scram.globalProxy;
return this.source;
},

View file

@ -45,11 +45,11 @@ export default function (client: ScramjetClient, self: typeof window) {
export function unproxy(ctx: ProxyCtx, client: ScramjetClient) {
const self = client.global;
if (ctx.this === client.windowProxy) ctx.this = self;
if (ctx.this === client.globalProxy) ctx.this = self;
if (ctx.this === client.documentProxy) ctx.this = self.document;
for (const i in ctx.args) {
if (ctx.args[i] === client.documentProxy) ctx.args[i] = self.document;
if (ctx.args[i] === client.windowProxy) ctx.args[i] = self;
if (ctx.args[i] === client.globalProxy) ctx.args[i] = self;
}
}

View file

@ -13,14 +13,14 @@ export default function (client: ScramjetClient, self: typeof globalThis) {
argdbg(arg);
}
if (iswindow && identifier instanceof self.Window) {
return client.windowProxy;
return client.globalProxy;
} else if (iswindow && identifier instanceof self.parent.self.Window) {
if (ScramjetClient.SCRAMJET in self.parent.self) {
// ... then we're in a subframe, and the parent frame is also in a proxy context, so we should return its proxy
return self.parent.self[ScramjetClient.SCRAMJET].windowProxy;
} else {
// ... then we should pretend we aren't nested and return the current window
return client.windowProxy;
return client.globalProxy;
}
} else if (iswindow && identifier instanceof self.top.self.Window) {
// instead of returning top, we need to return the uppermost parent that's inside a scramjet context
@ -46,7 +46,7 @@ export default function (client: ScramjetClient, self: typeof globalThis) {
} else if (iswindow && identifier instanceof self.Document) {
return client.documentProxy;
} else if (isworker && identifier instanceof self.WorkerGlobalScope) {
return client.windowProxy;
return client.globalProxy;
}
return identifier;