@@ -7,7 +7,6 @@ import { indirectEval } from "@client/shared/eval";
77
88export 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
4845export const order = 4 ;
4946export 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 ;
0 commit comments