|
|
|
@ -2,12 +2,13 @@
|
|
|
|
|
* 用于 jquery 在 worker 环境或者 V8 引擎的 polyfill |
|
|
|
|
*/ |
|
|
|
|
import { _global } from "@/core/0.foundation"; |
|
|
|
|
if (!_global.window) { |
|
|
|
|
_global.window = _global; |
|
|
|
|
const document = (_global.document = {}); |
|
|
|
|
const fakeElement = Object.create(document); |
|
|
|
|
|
|
|
|
|
Object.assign(document, { |
|
|
|
|
// const _global = globalThis;
|
|
|
|
|
|
|
|
|
|
const document = {}; |
|
|
|
|
const fakeElement = Object.create(document); |
|
|
|
|
|
|
|
|
|
Object.assign(document, { |
|
|
|
|
parentNode: null, |
|
|
|
|
nodeType: 9, |
|
|
|
|
head: fakeElement, |
|
|
|
@ -65,9 +66,9 @@ if (!_global.window) {
|
|
|
|
|
removeEventListener() { |
|
|
|
|
return null; |
|
|
|
|
}, |
|
|
|
|
}); |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
Object.assign(fakeElement, { |
|
|
|
|
Object.assign(fakeElement, { |
|
|
|
|
nodeType: 1, |
|
|
|
|
style: {}, |
|
|
|
|
ownerDocument: document, |
|
|
|
@ -77,5 +78,19 @@ if (!_global.window) {
|
|
|
|
|
toString() { |
|
|
|
|
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); |
|
|
|
|