mirror of
https://github.com/MercuryWorkshop/scramjet.git
synced 2025-05-13 22:40: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,
|
recursive: true,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
let modules = [];
|
||||||
|
|
||||||
for (const key of context.keys()) {
|
for (const key of context.keys()) {
|
||||||
|
const module = context(key);
|
||||||
if (!key.endsWith(".ts")) continue;
|
if (!key.endsWith(".ts")) continue;
|
||||||
if (
|
if (
|
||||||
(key.startsWith("./dom/") && "window" in self) ||
|
(key.startsWith("./dom/") && "window" in self) ||
|
||||||
(key.startsWith("./worker/") && "WorkerGlobalScope" in self) ||
|
(key.startsWith("./worker/") && "WorkerGlobalScope" in self) ||
|
||||||
key.startsWith("./shared/")
|
key.startsWith("./shared/")
|
||||||
) {
|
) {
|
||||||
const module = context(key);
|
modules.push(module);
|
||||||
module.default(this, this.global);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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) {
|
Proxy(name: string | string[], handler: Proxy) {
|
||||||
|
|
|
@ -1,6 +1,9 @@
|
||||||
import { encodeUrl } from "../../shared/rewriters/url";
|
import { encodeUrl } from "../../shared/rewriters/url";
|
||||||
import { ScramjetClient } from "../client";
|
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) {
|
export default function (client: ScramjetClient, self: Self) {
|
||||||
let fakeregistrations = new WeakSet();
|
let fakeregistrations = new WeakSet();
|
||||||
|
|
||||||
|
|
|
@ -8,10 +8,17 @@ export default function (client: ScramjetClient, self: Self) {
|
||||||
const handlers = {
|
const handlers = {
|
||||||
message: {
|
message: {
|
||||||
origin() {
|
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() {
|
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", {
|
client.Proxy("EventTarget.prototype.addEventListener", {
|
||||||
apply(ctx) {
|
apply(ctx) {
|
||||||
unproxy(ctx, client);
|
// if (ctx.args[0] === "message" && iswindow) debugger;
|
||||||
if (typeof ctx.args[1] === "object")
|
if (typeof ctx.args[1] === "function")
|
||||||
ctx.args[1] = wraplistener(ctx.args[1]);
|
ctx.args[1] = wraplistener(ctx.args[1]);
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
|
@ -1,8 +1,8 @@
|
||||||
import { isworker } from "../..";
|
import { iswindow, isworker } from "../..";
|
||||||
import { ScramjetClient } from "../../client";
|
import { ScramjetClient } from "../../client";
|
||||||
import { BareClient } from "../../shared";
|
import { BareClient } from "../../shared";
|
||||||
|
|
||||||
const bare = new BareClient();
|
const bare = iswindow && new BareClient();
|
||||||
|
|
||||||
export default function (client: ScramjetClient, self: typeof globalThis) {
|
export default function (client: ScramjetClient, self: typeof globalThis) {
|
||||||
// r58 please fix
|
// r58 please fix
|
||||||
|
|
|
@ -1,6 +1,9 @@
|
||||||
import { iswindow } from "..";
|
import { iswindow } from "..";
|
||||||
import { ProxyCtx, ScramjetClient } from "../client";
|
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) {
|
export default function (client: ScramjetClient, self: typeof window) {
|
||||||
// an automated approach to cleaning the documentProxy from dom functions
|
// 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
|
// 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