workerFakeDom.js 1.0 KB

123456789101112131415161718
  1. var document = self.document = { parentNode: null, nodeType: 9, toString: function () { return "FakeDocument" } };
  2. var window = self.window = self;
  3. var fakeElement = Object.create(document);
  4. fakeElement.nodeType = 1;
  5. fakeElement.toString = function () { return "FakeElement" };
  6. fakeElement.parentNode = fakeElement.firstChild = fakeElement.lastChild = fakeElement;
  7. fakeElement.ownerDocument = document;
  8. document.head = document.body = fakeElement;
  9. document.ownerDocument = document.documentElement = document;
  10. document.getElementById = document.createElement = function () { return fakeElement; };
  11. document.createDocumentFragment = function () { return this; };
  12. document.getElementsByTagName = document.getElementsByClassName = function () { return [fakeElement]; };
  13. document.getAttribute = document.setAttribute = document.removeChild =
  14. document.addEventListener = document.removeEventListener =
  15. function () { return null; };
  16. document.cloneNode = document.appendChild = function () { return this; };
  17. document.appendChild = function (child) { return child; };