mirror of
https://github.com/MercuryWorkshop/scramjet.git
synced 2025-05-16 07:30:02 -04:00
refactor window and document proxies
This commit is contained in:
parent
f3f1a2ed41
commit
6f51642afb
9 changed files with 99 additions and 99 deletions
|
@ -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;
|
||||
},
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue