|
1 | 1 | import { MessageManager } from "@App/app/message/message";
|
2 | 2 | import { ScriptRunResouce } from "@App/app/repo/scripts";
|
3 | 3 | import { v4 as uuidv4 } from "uuid";
|
| 4 | +import { has } from "lodash"; |
4 | 5 | import GMApi, { ApiValue, GMContext } from "./gm_api";
|
5 | 6 |
|
6 | 7 | // 构建脚本运行代码
|
@@ -143,9 +144,11 @@ Object.keys(descs).forEach((key) => {
|
143 | 144 | // 拦截上下文
|
144 | 145 | export function proxyContext(global: any, context: any) {
|
145 | 146 | const special = Object.assign(writables);
|
| 147 | + // 处理某些特殊的属性 |
146 | 148 | // 后台脚本要不要考虑不能使用eval?
|
147 | 149 | const thisContext: { [key: string]: any } = {
|
148 | 150 | eval: global.eval,
|
| 151 | + define: undefined, |
149 | 152 | };
|
150 | 153 | // keyword是与createContext时同步的,避免访问到context的内部变量
|
151 | 154 | const contextKeyword: { [key: string]: any } = {
|
@@ -184,7 +187,7 @@ export function proxyContext(global: any, context: any) {
|
184 | 187 | break;
|
185 | 188 | }
|
186 | 189 | if (typeof name === "string" && name !== "undefined") {
|
187 |
| - if (thisContext[name]) { |
| 190 | + if (has(thisContext, name)) { |
188 | 191 | return thisContext[name];
|
189 | 192 | }
|
190 | 193 | if (context[name]) {
|
@@ -230,7 +233,7 @@ export function proxyContext(global: any, context: any) {
|
230 | 233 | break;
|
231 | 234 | }
|
232 | 235 | if (typeof name === "string" && name !== "undefined") {
|
233 |
| - if (thisContext[name]) { |
| 236 | + if (has(thisContext, name)) { |
234 | 237 | return true;
|
235 | 238 | }
|
236 | 239 | if (context[name]) {
|
|
0 commit comments