Skip to content

Commit

Permalink
🐛 修复往global写入Symbol属性问题
Browse files Browse the repository at this point in the history
  • Loading branch information
CodFrm committed Dec 18, 2023
1 parent 96280a2 commit d8bb2f1
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 39 deletions.
10 changes: 10 additions & 0 deletions src/runtime/content/utils.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,3 +54,13 @@ describe("兼容问题", () => {
expect(() => _this.Object.freeze({})).not.toThrow();
});
});

// 允许往global写入Symbol属性,影响内容: https://bbs.tampermonkey.net.cn/thread-5509-1-1.html
describe("Symbol", () => {
const _this = proxyContext({}, {});
it("Symbol", () => {
const s = Symbol("test");
_this[s] = "ok";
expect(_this[s]).toEqual("ok");
});
});
84 changes: 45 additions & 39 deletions src/runtime/content/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -197,37 +197,39 @@ export function proxyContext(
default:
break;
}
if (typeof name === "string" && name !== "undefined") {
if (name !== "undefined") {
if (has(thisContext, name)) {
// @ts-ignore
return thisContext[name];
}
if (context[name]) {
if (contextKeyword[name]) {
return undefined;
if (typeof name === "string") {
if (context[name]) {
if (contextKeyword[name]) {
return undefined;
}
return context[name];
}
return context[name];
}
if (special[name] !== undefined) {
if (
typeof special[name] === "function" &&
!(<{ prototype: any }>special[name]).prototype
) {
return (<{ bind: any }>special[name]).bind(global);
if (special[name] !== undefined) {
if (
typeof special[name] === "function" &&
!(<{ prototype: any }>special[name]).prototype
) {
return (<{ bind: any }>special[name]).bind(global);
}
return special[name];
}
return special[name];
}
if (global[name] !== undefined) {
if (
typeof global[name] === "function" &&
!(<{ prototype: any }>global[name]).prototype
) {
return (<{ bind: any }>global[name]).bind(global);
if (global[name] !== undefined) {
if (
typeof global[name] === "function" &&
!(<{ prototype: any }>global[name]).prototype
) {
return (<{ bind: any }>global[name]).bind(global);
}
return global[name];
}
return global[name];
} else if (name === Symbol.unscopables) {
return unscopables;
}
} else if (name === Symbol.unscopables) {
return unscopables;
}
return undefined;
},
Expand All @@ -246,24 +248,28 @@ export function proxyContext(
default:
break;
}
if (typeof name === "string" && name !== "undefined") {
if (unscopables[name]) {
return false;
}
if (has(thisContext, name)) {
return true;
}
if (context[name]) {
if (contextKeyword[name]) {
if (name !== "undefined") {
if (typeof name === "string") {
if (unscopables[name]) {
return false;
}
return true;
}
if (special[name] !== undefined) {
return true;
}
if (global[name] !== undefined) {
return true;
if (has(thisContext, name)) {
return true;
}
if (context[name]) {
if (contextKeyword[name]) {
return false;
}
return true;
}
if (special[name] !== undefined) {
return true;
}
if (global[name] !== undefined) {
return true;
}
} else if (typeof name === "symbol") {
return has(thisContext, name);
}
}
return false;
Expand Down

0 comments on commit d8bb2f1

Please sign in to comment.