@@ -104,17 +104,6 @@ const getAllPropertyDescriptors = (obj: any, callback: ForEachCallback<[string |
104104 }
105105} ;
106106
107- // mySandbox 不进行with变量拦截
108- const unscopables : Record < PropertyKey , any > = {
109- this : true ,
110- arguments : true ,
111- // "await": true,
112- // "define": true,
113- // "module": true,
114- // "exports": true,
115- [ Symbol . unscopables ] : true ,
116- } ;
117-
118107// 在 CacheSet 加入的propKeys将会在 mySandbox 实装阶段时设置
119108const descsCache : Set < string | symbol > = new Set ( [ "eval" , "window" , "self" , "globalThis" , "top" , "parent" ] ) ;
120109
@@ -174,6 +163,8 @@ descsCache.clear(); // 内存释放
174163const sharedInitCopy = Object . create ( null , {
175164 ...initOwnDescs ,
176165 ...overridedDescs ,
166+ // Symbol.toStringTag设置为 Window
167+ [ Symbol . toStringTag ] : { value : "Window" , writable : false , enumerable : false , configurable : true } ,
177168} ) ;
178169
179170type GMWorldContext = typeof globalThis & Record < PropertyKey , any > ;
@@ -290,12 +281,6 @@ export const createProxyContext = <const Context extends GMWorldContext>(context
290281 // 把初始Copy加上特殊变量后,生成一份新Copy
291282 mySandbox = Object . create ( Object . getPrototypeOf ( sharedInitCopy ) , ownDescs ) ;
292283
293- // 用於避开 mySandbox 的with拦截
294- mySandbox [ Symbol . unscopables ] = {
295- ...( mySandbox [ Symbol . unscopables ] || { } ) ,
296- ...unscopables ,
297- } ;
298-
299284 // 处理特殊关键字,不能穿越出沙盒,也不能被外部修改
300285 for ( const key of [ "define" , "module" , "exports" ] ) {
301286 mySandbox [ key ] = undefined ;
0 commit comments