Skip to content

Commit

Permalink
🐛 修复toString.call(window)返回内容不正确 #260
Browse files Browse the repository at this point in the history
  • Loading branch information
CodFrm committed Feb 26, 2024
1 parent ded11ca commit 2288dae
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 1 deletion.
File renamed without changes.
6 changes: 5 additions & 1 deletion src/runtime/content/utils.test.ts
Expand Up @@ -55,12 +55,16 @@ describe("兼容问题", () => {
});
});

// 允许往global写入Symbol属性,影响内容: https://bbs.tampermonkey.net.cn/thread-5509-1-1.html
describe("Symbol", () => {
const _this = proxyContext({}, {});
// 允许往global写入Symbol属性,影响内容: https://bbs.tampermonkey.net.cn/thread-5509-1-1.html
it("Symbol", () => {
const s = Symbol("test");
_this[s] = "ok";
expect(_this[s]).toEqual("ok");
});
// toString.call(window)返回的是'[object Object]'而不是'[object Window]',影响内容: https://github.com/scriptscat/scriptcat/issues/260
it("Window", () => {
expect(toString.call(_this)).toEqual("[object Window]");
});
});
3 changes: 3 additions & 0 deletions src/runtime/content/utils.ts
Expand Up @@ -229,6 +229,8 @@ export function proxyContext(
}
} else if (name === Symbol.unscopables) {
return unscopables;
} else if (name === Symbol.toStringTag) {
return name;
}
}
return undefined;
Expand Down Expand Up @@ -317,6 +319,7 @@ export function proxyContext(
}
},
});
proxy[Symbol.toStringTag] = "Window";
return proxy;
}

Expand Down

0 comments on commit 2288dae

Please sign in to comment.