Skip to content

Commit 705641b

Browse files
committed
🐛 修复RegExp需要全局对象的问题
fixes #203
1 parent 4a695ce commit 705641b

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

src/runtime/content/utils.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,11 @@ export const writables: { [key: string]: any } = {
121121
// 记录初始的
122122
export const init = new Map<string, boolean>();
123123

124+
// 需要用到全局的
125+
export const unscopables: { [key: string]: boolean } = {
126+
RegExp: true,
127+
};
128+
124129
// 复制原有的,防止被前端网页复写
125130
const descs = Object.getOwnPropertyDescriptors(global);
126131
Object.keys(descs).forEach((key) => {
@@ -193,6 +198,7 @@ export function proxyContext(
193198
}
194199
if (typeof name === "string" && name !== "undefined") {
195200
if (has(thisContext, name)) {
201+
// @ts-ignore
196202
return thisContext[name];
197203
}
198204
if (context[name]) {
@@ -219,6 +225,8 @@ export function proxyContext(
219225
}
220226
return global[name];
221227
}
228+
} else if (name === Symbol.unscopables) {
229+
return unscopables;
222230
}
223231
return undefined;
224232
},
@@ -238,6 +246,9 @@ export function proxyContext(
238246
break;
239247
}
240248
if (typeof name === "string" && name !== "undefined") {
249+
if (unscopables[name]) {
250+
return false;
251+
}
241252
if (has(thisContext, name)) {
242253
return true;
243254
}
@@ -278,6 +289,7 @@ export function proxyContext(
278289
global[name] = val;
279290
return true;
280291
}
292+
// @ts-ignore
281293
thisContext[name] = val;
282294
return true;
283295
},

0 commit comments

Comments
 (0)