mirror of
https://github.com/MercuryWorkshop/scramjet.git
synced 2025-05-14 06:50:01 -04:00
fix rewriter
This commit is contained in:
parent
0e37a7f267
commit
396170e4ea
7 changed files with 115 additions and 43 deletions
|
@ -1,44 +0,0 @@
|
|||
import { ScramjetClient } from "../client";
|
||||
|
||||
export const iswindow = "window" in self;
|
||||
export const isworker = "WorkerGlobalScope" in self;
|
||||
export const issw = "ServiceWorkerGlobalScope" in self;
|
||||
export const isdedicated = "DedicatedWorkerGlobalScope" in self;
|
||||
export const isshared = "SharedWorkerGlobalScope" in self;
|
||||
|
||||
export default function (client: ScramjetClient, self: typeof globalThis) {
|
||||
function scope(identifier: any) {
|
||||
// this will break iframe postmessage!
|
||||
if (
|
||||
iswindow &&
|
||||
(identifier instanceof self.Window ||
|
||||
identifier instanceof self.top.window.Window ||
|
||||
identifier instanceof self.parent.window.Window)
|
||||
) {
|
||||
return client.windowProxy;
|
||||
} else if (
|
||||
(iswindow && identifier instanceof Location) ||
|
||||
(isworker && identifier instanceof WorkerLocation)
|
||||
) {
|
||||
return client.locationProxy;
|
||||
} else if (iswindow && identifier instanceof Document) {
|
||||
return client.documentProxy;
|
||||
} else if (isworker && identifier instanceof WorkerGlobalScope) {
|
||||
return client.windowProxy;
|
||||
}
|
||||
|
||||
return identifier;
|
||||
}
|
||||
|
||||
// shorthand because this can get out of hand reall quickly
|
||||
self.$s = scope;
|
||||
|
||||
self.$tryset = function (lhs: any, op: string, rhs: any) {
|
||||
if (lhs instanceof Location) {
|
||||
// @ts-ignore
|
||||
locationProxy.href = rhs;
|
||||
|
||||
return true;
|
||||
}
|
||||
};
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue