mirror of
https://github.com/MercuryWorkshop/scramjet.git
synced 2025-05-15 07:20:02 -04:00
feat: add back self.top to wrapfn
This commit is contained in:
parent
e7bef2b1c0
commit
b98d57a5bf
1 changed files with 16 additions and 2 deletions
|
@ -22,9 +22,23 @@ export function createWrapFn(client: ScramjetClient, self: typeof globalThis) {
|
|||
}
|
||||
} else if (identifier === self.document) {
|
||||
return client.documentProxy;
|
||||
}
|
||||
} else if (identifier === self.top) {
|
||||
// instead of returning top, we need to return the uppermost parent that's inside a scramjet context
|
||||
let current = self.self;
|
||||
|
||||
// TODO .top
|
||||
for (;;) {
|
||||
const test = current.parent.self;
|
||||
if (test === current) break; // there is no parent, actual or emulated.
|
||||
|
||||
// ... then `test` represents a window outside of the proxy context, and therefore `current` is the topmost window in the proxy context
|
||||
if (!(SCRAMJETCLIENT in test)) break;
|
||||
|
||||
// test is also insde a proxy, so we should continue up the chain
|
||||
current = test;
|
||||
}
|
||||
|
||||
return current[SCRAMJETCLIENT].globalProxy.window;
|
||||
}
|
||||
}
|
||||
|
||||
return identifier;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue