Skip to content

Commit 787265b

Browse files
committed
[core] add dpsc globals
1 parent 7215171 commit 787265b

File tree

4 files changed

+88
-28
lines changed

4 files changed

+88
-28
lines changed

rewriter/wasm/src/jsr.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,10 +49,8 @@ fn get_config(scramjet: &Object) -> Result<Config> {
4949
Ok(Config {
5050
prefix: get_str(config, "prefix")?,
5151

52-
wrapgetbase: get_str(globals, "wrapgetbase")?,
53-
wrapsetbase: get_str(globals, "wrapsetbase")?,
54-
wrapcomputedgetfn: get_str(globals, "wrapcomputedgetfn")?,
55-
wrapcomputedsetfn: get_str(globals, "wrapcomputedsetfn")?,
52+
wrappropertybase: get_str(globals, "wrappropertybase")?,
53+
wrappropertyfn: get_str(globals, "wrappropertyfn")?,
5654
wrapfn: get_str(globals, "wrapfn")?,
5755
importfn: get_str(globals, "importfn")?,
5856
rewritefn: get_str(globals, "rewritefn")?,

src/client/shared/wrap.ts

Lines changed: 82 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import { indirectEval } from "@client/shared/eval";
77

88
export function createWrapFn(client: ScramjetClient, self: typeof globalThis) {
99
return function (identifier: any, strict: boolean) {
10-
if (identifier === self) return client.globalProxy;
1110
if (identifier === self.location) return client.locationProxy;
1211
if (identifier === eval) return indirectEval.bind(client, strict);
1312

@@ -18,10 +17,8 @@ export function createWrapFn(client: ScramjetClient, self: typeof globalThis) {
1817
return self.parent[SCRAMJETCLIENT].globalProxy;
1918
} else {
2019
// ... then we should pretend we aren't nested and return the current window
21-
return client.globalProxy;
20+
return self;
2221
}
23-
} else if (identifier === self.document) {
24-
return client.documentProxy;
2522
} else if (identifier === self.top) {
2623
// instead of returning top, we need to return the uppermost parent that's inside a scramjet context
2724
let current = self;
@@ -37,7 +34,7 @@ export function createWrapFn(client: ScramjetClient, self: typeof globalThis) {
3734
current = test;
3835
}
3936

40-
return current[SCRAMJETCLIENT].globalProxy;
37+
return current;
4138
}
4239
}
4340

@@ -47,27 +44,96 @@ export function createWrapFn(client: ScramjetClient, self: typeof globalThis) {
4744

4845
export const order = 4;
4946
export default function (client: ScramjetClient, self: typeof globalThis) {
50-
// the main magic of the proxy. all attempts to access any "banned objects" will be redirected here, and instead served a proxy object
51-
// this contrasts from how other proxies will leave the root object alone and instead attempt to catch every member access
52-
// this presents some issues (see element.ts), but makes us a good bit faster at runtime!
5347
Object.defineProperty(self, config.globals.wrapfn, {
5448
value: client.wrapfn,
5549
writable: false,
5650
configurable: false,
51+
enumerable: false,
5752
});
58-
Object.defineProperty(self, config.globals.wrapcomputedgetfn, {
59-
value: function (val, prop) {
60-
if (val === self) {
61-
console.log(prop);
53+
Object.defineProperty(self, config.globals.wrappropertyfn, {
54+
value: function (str) {
55+
if (
56+
str === "location" ||
57+
str === "parent" ||
58+
str === "top" ||
59+
str === "eval"
60+
)
61+
return config.globals.wrappropertybase + str;
6262

63-
return null;
64-
}
65-
66-
return Reflect.get(val, prop);
63+
return str;
6764
},
6865
writable: false,
6966
configurable: false,
67+
enumerable: false,
7068
});
69+
console.log(config.globals.wrappropertybase);
70+
71+
Object.defineProperty(
72+
self.Object.prototype,
73+
config.globals.wrappropertybase + "location",
74+
{
75+
get: function () {
76+
if (this === self) {
77+
return client.locationProxy;
78+
}
79+
80+
return this.location;
81+
},
82+
set(value: any) {
83+
if (this === self) {
84+
client.locationProxy = value;
85+
86+
return;
87+
}
88+
this.location = value;
89+
},
90+
configurable: false,
91+
enumerable: false,
92+
}
93+
);
94+
Object.defineProperty(
95+
self.Object.prototype,
96+
config.globals.wrappropertybase + "parent",
97+
{
98+
get: function () {
99+
return client.wrapfn(this.parent, false);
100+
},
101+
set(value: any) {
102+
// i guess??
103+
this.parent = value;
104+
},
105+
configurable: false,
106+
enumerable: false,
107+
}
108+
);
109+
Object.defineProperty(
110+
self.Object.prototype,
111+
config.globals.wrappropertybase + "top",
112+
{
113+
get: function () {
114+
return client.wrapfn(this.top, false);
115+
},
116+
set(value: any) {
117+
this.top = value;
118+
},
119+
configurable: false,
120+
enumerable: false,
121+
}
122+
);
123+
Object.defineProperty(
124+
self.Object.prototype,
125+
config.globals.wrappropertybase + "eval",
126+
{
127+
get: function () {
128+
return client.wrapfn(this.eval, true);
129+
},
130+
set(value: any) {
131+
this.eval = value;
132+
},
133+
configurable: false,
134+
enumerable: false,
135+
}
136+
);
71137

72138
self.$scramitize = function (v) {
73139
if (v === self) debugger;

src/controller/index.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,8 @@ export class ScramjetController {
1717
prefix: "/scramjet/",
1818
globals: {
1919
wrapfn: "$scramjet$wrap",
20-
wrapgetbase: "$scramjet$get_",
21-
wrapsetbase: "$scramjet$get_",
22-
wrapcomputedgetfn: "$scramjet$get",
23-
wrapcomputedsetfn: "$scramjet$get",
20+
wrappropertybase: "$scramjet__",
21+
wrappropertyfn: "$scramjet$prop",
2422
trysetfn: "$scramjet$tryset",
2523
importfn: "$scramjet$import",
2624
rewritefn: "$scramjet$rewrite",

src/types.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,8 @@ export interface ScramjetConfig {
1919
prefix: string;
2020
globals: {
2121
wrapfn: string;
22-
wrapsetbase: string;
23-
wrapgetbase: string;
24-
wrapcomputedgetfn: string;
25-
wrapcomputedsetfn: string;
22+
wrappropertybase: string;
23+
wrappropertyfn: string;
2624
trysetfn: string;
2725
importfn: string;
2826
rewritefn: string;

0 commit comments

Comments
 (0)