Skip to content

Commit 2288dae

Browse files
committed
🐛 修复toString.call(window)返回内容不正确 #260
1 parent ded11ca commit 2288dae

File tree

3 files changed

+8
-1
lines changed

3 files changed

+8
-1
lines changed
File renamed without changes.

src/runtime/content/utils.test.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,12 +55,16 @@ describe("兼容问题", () => {
5555
});
5656
});
5757

58-
// 允许往global写入Symbol属性,影响内容: https://bbs.tampermonkey.net.cn/thread-5509-1-1.html
5958
describe("Symbol", () => {
6059
const _this = proxyContext({}, {});
60+
// 允许往global写入Symbol属性,影响内容: https://bbs.tampermonkey.net.cn/thread-5509-1-1.html
6161
it("Symbol", () => {
6262
const s = Symbol("test");
6363
_this[s] = "ok";
6464
expect(_this[s]).toEqual("ok");
6565
});
66+
// toString.call(window)返回的是'[object Object]'而不是'[object Window]',影响内容: https://github.com/scriptscat/scriptcat/issues/260
67+
it("Window", () => {
68+
expect(toString.call(_this)).toEqual("[object Window]");
69+
});
6670
});

src/runtime/content/utils.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,8 @@ export function proxyContext(
229229
}
230230
} else if (name === Symbol.unscopables) {
231231
return unscopables;
232+
} else if (name === Symbol.toStringTag) {
233+
return name;
232234
}
233235
}
234236
return undefined;
@@ -317,6 +319,7 @@ export function proxyContext(
317319
}
318320
},
319321
});
322+
proxy[Symbol.toStringTag] = "Window";
320323
return proxy;
321324
}
322325

0 commit comments

Comments
 (0)