Browse Source

KERNEL-14316 fix:worker polyfill

es6
Treecat 2 years ago
parent
commit
e3bafd8af0
  1. 155
      packages/fineui/src/core/platform/web/jquery/jquery.polyfill.js
  2. 1
      packages/fineui/webpack/webpack.prod.js

155
packages/fineui/src/core/platform/web/jquery/jquery.polyfill.js

@ -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);

1
packages/fineui/webpack/webpack.prod.js

@ -19,6 +19,7 @@ module.exports = merge(common, {
entry: { entry: {
"fineui.min": attachments.fineui, "fineui.min": attachments.fineui,
"fineui.worker.min": attachments.fineuiForWorker, "fineui.worker.min": attachments.fineuiForWorker,
"fineui.worker": attachments.fineuiForWorker
}, },
output: { output: {

Loading…
Cancel
Save