mirror of
https://github.com/MercuryWorkshop/scramjet.git
synced 2025-05-14 06:50:01 -04:00
fix postmessage proxy
This commit is contained in:
parent
a29e8c42a3
commit
b8334993ae
5 changed files with 34 additions and 8 deletions
|
@ -63,17 +63,30 @@ export class ScramjetClient {
|
|||
recursive: true,
|
||||
});
|
||||
|
||||
let modules = [];
|
||||
|
||||
for (const key of context.keys()) {
|
||||
const module = context(key);
|
||||
if (!key.endsWith(".ts")) continue;
|
||||
if (
|
||||
(key.startsWith("./dom/") && "window" in self) ||
|
||||
(key.startsWith("./worker/") && "WorkerGlobalScope" in self) ||
|
||||
key.startsWith("./shared/")
|
||||
) {
|
||||
const module = context(key);
|
||||
module.default(this, this.global);
|
||||
modules.push(module);
|
||||
}
|
||||
}
|
||||
|
||||
modules.sort((a, b) => {
|
||||
const aorder = a.order || 0;
|
||||
const border = b.order || 0;
|
||||
|
||||
return aorder - border;
|
||||
});
|
||||
|
||||
for (const module of modules) {
|
||||
module.default(this, this.global);
|
||||
}
|
||||
}
|
||||
|
||||
Proxy(name: string | string[], handler: Proxy) {
|
||||
|
|
|
@ -1,6 +1,9 @@
|
|||
import { encodeUrl } from "../../shared/rewriters/url";
|
||||
import { ScramjetClient } from "../client";
|
||||
|
||||
// we need a late order because we're mangling with addEventListener at a higher level
|
||||
export const order = 2;
|
||||
|
||||
export default function (client: ScramjetClient, self: Self) {
|
||||
let fakeregistrations = new WeakSet();
|
||||
|
||||
|
|
|
@ -8,10 +8,17 @@ export default function (client: ScramjetClient, self: Self) {
|
|||
const handlers = {
|
||||
message: {
|
||||
origin() {
|
||||
return this.data.$scramjet$origin;
|
||||
if (typeof this.data === "object" && "$scramjet$origin" in this.data)
|
||||
return this.data.$scramjet$origin;
|
||||
|
||||
// then it must be from a worker, which we aren't currently rewriting
|
||||
return client.url.origin;
|
||||
},
|
||||
data() {
|
||||
return this.data.$scramjet$data;
|
||||
if (typeof this.data === "object" && "$scramjet$data" in this.data)
|
||||
return this.data.$scramjet$data;
|
||||
|
||||
return this.data;
|
||||
},
|
||||
},
|
||||
};
|
||||
|
@ -46,8 +53,8 @@ export default function (client: ScramjetClient, self: Self) {
|
|||
|
||||
client.Proxy("EventTarget.prototype.addEventListener", {
|
||||
apply(ctx) {
|
||||
unproxy(ctx, client);
|
||||
if (typeof ctx.args[1] === "object")
|
||||
// if (ctx.args[0] === "message" && iswindow) debugger;
|
||||
if (typeof ctx.args[1] === "function")
|
||||
ctx.args[1] = wraplistener(ctx.args[1]);
|
||||
},
|
||||
});
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
import { isworker } from "../..";
|
||||
import { iswindow, isworker } from "../..";
|
||||
import { ScramjetClient } from "../../client";
|
||||
import { BareClient } from "../../shared";
|
||||
|
||||
const bare = new BareClient();
|
||||
const bare = iswindow && new BareClient();
|
||||
|
||||
export default function (client: ScramjetClient, self: typeof globalThis) {
|
||||
// r58 please fix
|
||||
|
|
|
@ -1,6 +1,9 @@
|
|||
import { iswindow } from "..";
|
||||
import { ProxyCtx, ScramjetClient } from "../client";
|
||||
|
||||
// we don't want to end up overriding a property on window that's derived from a prototype until we've proxied the prototype
|
||||
export const order = 3;
|
||||
|
||||
export default function (client: ScramjetClient, self: typeof window) {
|
||||
// an automated approach to cleaning the documentProxy from dom functions
|
||||
// it will trigger an illegal invocation if you pass the proxy to c++ code, we gotta hotswap it out with the real one
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue