|
|
@ -2,80 +2,95 @@ |
|
|
|
* 用于 jquery 在 worker 环境或者 V8 引擎的 polyfill |
|
|
|
* 用于 jquery 在 worker 环境或者 V8 引擎的 polyfill |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
import { _global } from "@/core/0.foundation"; |
|
|
|
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;
|
|
|
|
parentNode: null, |
|
|
|
|
|
|
|
nodeType: 9, |
|
|
|
const document = {}; |
|
|
|
head: fakeElement, |
|
|
|
const fakeElement = Object.create(document); |
|
|
|
body: fakeElement, |
|
|
|
|
|
|
|
ownerDocument: document, |
|
|
|
Object.assign(document, { |
|
|
|
documentElement: document, |
|
|
|
parentNode: null, |
|
|
|
toString() { |
|
|
|
nodeType: 9, |
|
|
|
return "FakeDocument"; |
|
|
|
head: fakeElement, |
|
|
|
}, |
|
|
|
body: fakeElement, |
|
|
|
appendChild(child) { |
|
|
|
ownerDocument: document, |
|
|
|
return child; |
|
|
|
documentElement: document, |
|
|
|
}, |
|
|
|
toString() { |
|
|
|
implementation: { |
|
|
|
return "FakeDocument"; |
|
|
|
createHTMLDocument() { |
|
|
|
}, |
|
|
|
return { |
|
|
|
appendChild(child) { |
|
|
|
body: { |
|
|
|
return child; |
|
|
|
childNodes: [], |
|
|
|
}, |
|
|
|
}, |
|
|
|
implementation: { |
|
|
|
}; |
|
|
|
createHTMLDocument() { |
|
|
|
}, |
|
|
|
return { |
|
|
|
createDocumentFragment() { |
|
|
|
body: { |
|
|
|
return this; |
|
|
|
childNodes: [], |
|
|
|
}, |
|
|
|
}, |
|
|
|
}, |
|
|
|
}; |
|
|
|
getElementById() { |
|
|
|
|
|
|
|
return fakeElement; |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
createElement() { |
|
|
|
|
|
|
|
return fakeElement; |
|
|
|
|
|
|
|
}, |
|
|
|
}, |
|
|
|
createDocumentFragment() { |
|
|
|
createDocumentFragment() { |
|
|
|
return this; |
|
|
|
return this; |
|
|
|
}, |
|
|
|
}, |
|
|
|
cloneNode() { |
|
|
|
}, |
|
|
|
return this; |
|
|
|
getElementById() { |
|
|
|
}, |
|
|
|
return fakeElement; |
|
|
|
getElementsByTagName() { |
|
|
|
}, |
|
|
|
return [fakeElement]; |
|
|
|
createElement() { |
|
|
|
}, |
|
|
|
return fakeElement; |
|
|
|
getElementsByClassName() { |
|
|
|
}, |
|
|
|
return [fakeElement]; |
|
|
|
createDocumentFragment() { |
|
|
|
}, |
|
|
|
return this; |
|
|
|
setAttribute() { |
|
|
|
}, |
|
|
|
return null; |
|
|
|
cloneNode() { |
|
|
|
}, |
|
|
|
return this; |
|
|
|
getAttribute() { |
|
|
|
}, |
|
|
|
return null; |
|
|
|
getElementsByTagName() { |
|
|
|
}, |
|
|
|
return [fakeElement]; |
|
|
|
removeChild() { |
|
|
|
}, |
|
|
|
return null; |
|
|
|
getElementsByClassName() { |
|
|
|
}, |
|
|
|
return [fakeElement]; |
|
|
|
addEventListener() { |
|
|
|
}, |
|
|
|
return null; |
|
|
|
setAttribute() { |
|
|
|
}, |
|
|
|
return null; |
|
|
|
removeEventListener() { |
|
|
|
}, |
|
|
|
return null; |
|
|
|
getAttribute() { |
|
|
|
}, |
|
|
|
return null; |
|
|
|
}); |
|
|
|
}, |
|
|
|
|
|
|
|
removeChild() { |
|
|
|
|
|
|
|
return null; |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
addEventListener() { |
|
|
|
|
|
|
|
return null; |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
removeEventListener() { |
|
|
|
|
|
|
|
return null; |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
Object.assign(fakeElement, { |
|
|
|
Object.assign(fakeElement, { |
|
|
|
nodeType: 1, |
|
|
|
nodeType: 1, |
|
|
|
style: {}, |
|
|
|
style: {}, |
|
|
|
ownerDocument: document, |
|
|
|
ownerDocument: document, |
|
|
|
parentNod: fakeElement, |
|
|
|
parentNod: fakeElement, |
|
|
|
firstChild: fakeElement, |
|
|
|
firstChild: fakeElement, |
|
|
|
lastChild: fakeElement, |
|
|
|
lastChild: fakeElement, |
|
|
|
toString() { |
|
|
|
toString() { |
|
|
|
return "FakeElement"; |
|
|
|
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); |
|
|
|