File tree Expand file tree Collapse file tree 1 file changed +29
-0
lines changed Expand file tree Collapse file tree 1 file changed +29
-0
lines changed Original file line number Diff line number Diff line change 1+ type unsafeWindow = typeof window
2+ // eslint-disable-next-line @typescript-eslint/naming-convention
3+ declare const unsafeWindow : unsafeWindow
4+
5+ const Win = typeof unsafeWindow !== 'undefined' ? unsafeWindow : window
6+
7+ const ProtectedFunctionStrings = [ 'toString' , 'apply' ]
8+
9+ Win . Function . prototype . toString = new Proxy ( Win . Function . prototype . toString , {
10+ // eslint-disable-next-line @typescript-eslint/no-unsafe-function-type
11+ apply ( Target : ( ) => string , ThisArg : Function , Args : null ) {
12+ if ( ProtectedFunctionStrings . includes ( ThisArg . name ) ) {
13+ return `function ${ ThisArg . name } () { [native code] }`
14+ } else {
15+ return Reflect . apply ( Target , ThisArg , Args )
16+ }
17+ }
18+ } )
19+
20+ Win . Function . prototype . apply = new Proxy ( Win . Function . prototype . apply , {
21+ // eslint-disable-next-line @typescript-eslint/no-unsafe-function-type
22+ apply ( Target : typeof Function . prototype . apply , ThisArg : Function , Args : unknown [ ] ) {
23+ if ( Args . toString ( ) . includes ( 'debug,' ) ) {
24+ throw new Error ( )
25+ }
26+
27+ return Reflect . apply ( Target , ThisArg , Args )
28+ }
29+ } )
You can’t perform that action at this time.
0 commit comments