- 在Headers和Response polyfill中添加globalThis存在性检查,避免在不支持globalThis的环境中报错 - 优化全局对象判断条件,确保只有在globalThis存在且对应对象未定义时才注册polyfill
@@ -72,7 +72,7 @@ class Headers {
}
// 全局注册(如果需要)
- if (typeof globalThis.Headers === 'undefined') {
+ if (typeof globalThis !== 'undefined' && typeof globalThis.Headers === 'undefined') {
globalThis.Headers = Headers;
@@ -81,7 +81,7 @@ class ResponsePolyfill {
- if (typeof globalThis.Response === 'undefined') {
+ if (typeof globalThis !== 'undefined' && typeof globalThis.Response === 'undefined') {
globalThis.Response = ResponsePolyfill as any