Skip to content

Commit 4f64571

Browse files
committed
[scramjet/core] kill config global
1 parent ddef6f0 commit 4f64571

File tree

18 files changed

+65
-86
lines changed

18 files changed

+65
-86
lines changed

packages/scramjet/packages/core/src/client/client.ts

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,7 @@ import { createLocationProxy } from "@client/location";
66
import { createWrapFn } from "@client/shared/wrap";
77
import { NavigateEvent } from "@client/events";
88
import { rewriteUrl, unrewriteUrl, type URLMeta } from "@rewriters/url";
9-
import {
10-
config,
11-
flagEnabled,
12-
ScramjetContext,
13-
ScramjetInterface,
14-
} from "@/shared";
9+
import { flagEnabled, ScramjetContext, ScramjetInterface } from "@/shared";
1510
import { CookieJar } from "@/shared/cookie";
1611
import { iswindow, ScramjetClientInit } from "./entry";
1712
import { SingletonBox } from "./singletonbox";
@@ -696,4 +691,8 @@ export class ScramjetClient {
696691
flagEnabled(flag: keyof ScramjetConfig["flags"]): boolean {
697692
return flagEnabled(flag, this.context, this.url);
698693
}
694+
695+
get config(): ScramjetConfig {
696+
return this.context.config;
697+
}
699698
}

packages/scramjet/packages/core/src/client/dom/element.ts

Lines changed: 35 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -432,39 +432,39 @@ export default function (client: ScramjetClient, self: typeof window) {
432432
});
433433

434434
// TODO: this needs to be done for all insert methods
435-
client.Proxy(["Element.prototype.appendChild", "Element.prototype.append"], {
436-
apply(ctx) {
437-
if (ctx.this instanceof self.HTMLStyleElement) {
438-
for (const node of ctx.args) {
439-
if (node instanceof self.Text) {
440-
node.data = rewriteCss(
441-
ctx.args[0].data,
442-
client.context,
443-
client.meta
444-
);
445-
}
446-
}
447-
} else if (ctx.this instanceof self.HTMLScriptElement) {
448-
for (const node of ctx.args) {
449-
if (node instanceof self.Text) {
450-
const newval: string = rewriteJs(
451-
node.data,
452-
"(anonymous script element)",
453-
client.context,
454-
client.meta
455-
) as string;
456-
client.natives.call(
457-
"Element.prototype.setAttribute",
458-
ctx.this,
459-
"scramjet-attr-script-source-src",
460-
bytesToBase64(encoder.encode(newval))
461-
);
462-
node.data = newval;
463-
}
464-
}
465-
}
466-
},
467-
});
435+
// client.Proxy(["Element.prototype.appendChild", "Element.prototype.append"], {
436+
// apply(ctx) {
437+
// if (ctx.this instanceof self.HTMLStyleElement) {
438+
// for (const node of ctx.args) {
439+
// if (node instanceof self.Text) {
440+
// node.data = rewriteCss(
441+
// ctx.args[0].data,
442+
// client.context,
443+
// client.meta
444+
// );
445+
// }
446+
// }
447+
// } else if (ctx.this instanceof self.HTMLScriptElement) {
448+
// for (const node of ctx.args) {
449+
// if (node instanceof self.Text) {
450+
// const newval: string = rewriteJs(
451+
// node.data,
452+
// "(anonymous script element)",
453+
// client.context,
454+
// client.meta
455+
// ) as string;
456+
// client.natives.call(
457+
// "Element.prototype.setAttribute",
458+
// ctx.this,
459+
// "scramjet-attr-script-source-src",
460+
// bytesToBase64(encoder.encode(newval))
461+
// );
462+
// node.data = newval;
463+
// }
464+
// }
465+
// }
466+
// },
467+
// });
468468

469469
client.Proxy("Audio", {
470470
construct(ctx) {
@@ -527,11 +527,7 @@ export default function (client: ScramjetClient, self: typeof window) {
527527
try {
528528
if (!(SCRAMJETCLIENT in realwin)) {
529529
// hook the iframe before the client can start to steal globals out of it
530-
const newclient = new ScramjetClient(
531-
realwin,
532-
client.context,
533-
client.rpc
534-
);
530+
const newclient = new ScramjetClient(realwin, client.init);
535531
newclient.hook();
536532
}
537533
} catch {
@@ -560,11 +556,7 @@ export default function (client: ScramjetClient, self: typeof window) {
560556
if (!realwin) return realwin;
561557

562558
if (!(SCRAMJETCLIENT in realwin)) {
563-
const newclient = new ScramjetClient(
564-
realwin,
565-
client.context,
566-
client.rpc
567-
);
559+
const newclient = new ScramjetClient(realwin, client.init);
568560
newclient.hook();
569561
}
570562

packages/scramjet/packages/core/src/client/dom/performance.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import { ScramjetClient } from "@client/index";
2-
import { config } from "@/shared";
32

43
export default function (client: ScramjetClient, _self: Self) {
54
client.Trap("PerformanceEntry.prototype.name", {
@@ -17,7 +16,7 @@ export default function (client: ScramjetClient, _self: Self) {
1716

1817
const filterEntries = (entries: PerformanceEntry[]) => {
1918
return entries.filter((entry) => {
20-
for (const file of config.maskedfiles) {
19+
for (const file of client.config.maskedfiles) {
2120
if (entry.name.endsWith(file)) {
2221
return false;
2322
}

packages/scramjet/packages/core/src/client/shared/error.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import { config, flagEnabled } from "@/shared";
21
import { unrewriteUrl } from "@rewriters/url";
32
import { ScramjetClient } from "@client/index";
43

@@ -14,7 +13,7 @@ export default function (client: ScramjetClient, _self: Self) {
1413
const url = stack[i].getFileName();
1514

1615
try {
17-
if (config.maskedfiles.some((f) => url.endsWith(f))) {
16+
if (client.config.maskedfiles.some((f) => url.endsWith(f))) {
1817
// strip stack frames including scramjet handlers from the trace
1918
const lines = newstack.split("\n");
2019
const line = lines.find((l) => l.includes(url));

packages/scramjet/packages/core/src/client/shared/eval.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
1-
import { config } from "@/shared";
21
import { rewriteJs } from "@rewriters/js";
32
import { ScramjetClient } from "@client/index";
43

54
export default function (client: ScramjetClient, self: Self) {
65
// used for proxying *direct eval*
76
// eval("...") -> eval($scramjet$rewrite("..."))
8-
Object.defineProperty(self, config.globals.rewritefn, {
7+
Object.defineProperty(self, client.config.globals.rewritefn, {
98
value: function (js: any) {
109
if (typeof js !== "string") return js;
1110

packages/scramjet/packages/core/src/client/shared/import.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import { ScramjetClient } from "@client/index";
2-
import { config } from "@/shared";
32

43
export default function (client: ScramjetClient, self: Self) {
54
const boundimport = client.natives.call(
@@ -30,7 +29,7 @@ export default function (client: ScramjetClient, self: Self) {
3029
configurable: false,
3130
enumerable: false,
3231
});
33-
Object.defineProperty(self, config.globals.metafn, {
32+
Object.defineProperty(self, client.config.globals.metafn, {
3433
value: function (metaobj: any, base: string) {
3534
metaobj.url = base;
3635
metaobj.resolve = function (url: string) {

packages/scramjet/packages/core/src/client/shared/postmessage.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import { iswindow } from "@client/entry";
22
import { SCRAMJETCLIENT } from "@/symbols";
33
import { ScramjetClient } from "@client/index";
4-
import { config } from "@/shared";
54

65
export default function (client: ScramjetClient, self: Self) {
76
if (iswindow)
@@ -82,7 +81,7 @@ export default function (client: ScramjetClient, self: Self) {
8281
};
8382
},
8483
});
85-
Object.defineProperty(self, config.globals.wrappostmessagefn, {
84+
Object.defineProperty(self, client.config.globals.wrappostmessagefn, {
8685
value: function (obj: any) {
8786
return obj.postMessage.bind(obj);
8887
},

packages/scramjet/packages/core/src/client/shared/requests/websocket.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import { config } from "@/shared";
21
import { type BareWebSocket } from "@mercuryworkshop/bare-mux-custom";
32
import { ScramjetClient } from "@client/index";
43

@@ -31,7 +30,9 @@ export default function (client: ScramjetClient, self: typeof globalThis) {
3130
new WeakMap();
3231
client.Proxy("WebSocket", {
3332
construct(ctx) {
34-
if (config.allowedwebsockets.some((w) => ctx.args[0].startsWith(w))) {
33+
if (
34+
client.config.allowedwebsockets.some((w) => ctx.args[0].startsWith(w))
35+
) {
3536
return ctx.return(client.natives.construct("WebSocket", ...ctx.args));
3637
}
3738
const fakeWebSocket = new EventTarget() as WebSocket;

packages/scramjet/packages/core/src/client/shared/requests/xmlhttprequest.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { config, flagEnabled, ScramjetContext } from "@/shared";
1+
import { flagEnabled, ScramjetContext } from "@/shared";
22
import { rewriteUrl, unrewriteUrl, URLMeta } from "@rewriters/url";
33
import { ScramjetClient } from "@client/index";
44

packages/scramjet/packages/core/src/client/shared/sourcemaps.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import { config, flagEnabled } from "@/shared";
21
import { SCRAMJETCLIENT, SCRAMJETCLIENTNAME } from "@/symbols";
32
import { ProxyCtx, ScramjetClient } from "@client/index";
43

@@ -162,7 +161,7 @@ export const enabled = (client: ScramjetClient) =>
162161

163162
export default function (client: ScramjetClient, self: Self) {
164163
// every script will push a sourcemap
165-
Object.defineProperty(self, config.globals.pushsourcemapfn, {
164+
Object.defineProperty(self, client.config.globals.pushsourcemapfn, {
166165
value: (buf: Array<number>, tag: string) => {
167166
const before = performance.now();
168167
registerRewrites(client, buf, tag);

0 commit comments

Comments
 (0)