mirror of
https://github.com/MercuryWorkshop/scramjet.git
synced 2025-05-14 15:00:01 -04:00
worker rewriting
This commit is contained in:
parent
2598bee87b
commit
f6c3c13d1e
22 changed files with 543 additions and 392 deletions
|
@ -1,27 +1,39 @@
|
|||
import { locationProxy } from "./location";
|
||||
import { documentProxy, windowProxy } from "./window";
|
||||
|
||||
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;
|
||||
|
||||
function scope(identifier: any) {
|
||||
// this will break iframe postmessage!
|
||||
if (
|
||||
identifier instanceof Window ||
|
||||
identifier instanceof top.window.Window ||
|
||||
identifier instanceof parent.window.Window
|
||||
iswindow &&
|
||||
(identifier instanceof Window ||
|
||||
identifier instanceof top.window.Window ||
|
||||
identifier instanceof parent.window.Window)
|
||||
) {
|
||||
return windowProxy;
|
||||
} else if (identifier instanceof Location) {
|
||||
} else if (
|
||||
(iswindow && identifier instanceof Location) ||
|
||||
(isworker && identifier instanceof WorkerLocation)
|
||||
) {
|
||||
return locationProxy;
|
||||
} else if (identifier instanceof Document) {
|
||||
} else if (iswindow && identifier instanceof Document) {
|
||||
return documentProxy;
|
||||
} else if (isworker && identifier instanceof WorkerGlobalScope) {
|
||||
return windowProxy;
|
||||
}
|
||||
|
||||
return identifier;
|
||||
}
|
||||
|
||||
// shorthand because this can get out of hand reall quickly
|
||||
window.$s = scope;
|
||||
self.$s = scope;
|
||||
|
||||
window.$tryset = function (lhs: any, op: string, rhs: any) {
|
||||
self.$tryset = function (lhs: any, op: string, rhs: any) {
|
||||
if (lhs instanceof Location) {
|
||||
// @ts-ignore
|
||||
locationProxy.href = rhs;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue