feat: add back self.top to wrapfn

This commit is contained in:
Percs 2024-10-23 09:59:35 -05:00
parent e7bef2b1c0
commit b98d57a5bf

View file

@ -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;