|
|
|
@ -2,9 +2,10 @@
|
|
|
|
|
* 用于 jquery 在 worker 环境或者 V8 引擎的 polyfill |
|
|
|
|
*/ |
|
|
|
|
import { _global } from "@/core/0.foundation"; |
|
|
|
|
if (!_global.window) { |
|
|
|
|
_global.window = _global; |
|
|
|
|
const document = (_global.document = {}); |
|
|
|
|
|
|
|
|
|
// const _global = globalThis;
|
|
|
|
|
|
|
|
|
|
const document = {}; |
|
|
|
|
const fakeElement = Object.create(document); |
|
|
|
|
|
|
|
|
|
Object.assign(document, { |
|
|
|
@ -78,4 +79,18 @@ if (!_global.window) {
|
|
|
|
|
return "FakeElement"; |
|
|
|
|
}, |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
function polyfillProps(key, obj) { |
|
|
|
|
_global[key] = _global[key] || obj; |
|
|
|
|
if (typeof obj === "object") { |
|
|
|
|
try { |
|
|
|
|
Object.assign(_global[key], obj); |
|
|
|
|
} catch(err) { |
|
|
|
|
// _global[key] 可能只有 get 方法
|
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
_global.window = _global; |
|
|
|
|
polyfillProps("XMLHttpRequest", function () {}); |
|
|
|
|
polyfillProps("document", document); |
|
|
|
|