| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253 |
- /**
- * Minimal DOM shim so js/statum.js can be loaded under QuickJS.
- *
- * statum.js is an IIFE that attaches `window.statum` and calls autoInit()
- * at load time. autoInit() only needs `document.readyState` (we report
- * 'loading' so it registers a DOMContentLoaded listener instead of running),
- * and the rest of the boot path is never exercised by the markdown tests.
- *
- * Set `__STATUM_TEST__` before loading statum.js to expose
- * `statum._testMarkdown` (see the comment at the bottom of statum.js).
- */
- export function installShim() {
- var listeners = {};
- function makeElement() {
- return {
- tagName: 'DIV', style: {}, dataset: {}, attributes: [], children: [],
- setAttribute: function () {}, removeAttribute: function () {},
- hasAttribute: function () { return false; },
- getAttribute: function () { return null; },
- addEventListener: function () {}, removeEventListener: function () {},
- appendChild: function (c) { return c; },
- removeChild: function (c) { return c; },
- replaceWith: function () {},
- querySelectorAll: function () { return []; },
- querySelector: function () { return null; },
- classList: { add: function () {}, remove: function () {}, contains: function () { return false; } },
- contains: function () { return false; }
- };
- }
- globalThis.console = {
- log: function () {}, warn: function () {}, error: function () {},
- info: function () {}, debug: function () {}
- };
- globalThis.document = {
- readyState: 'loading', cookie: '',
- head: makeElement(), body: makeElement(), documentElement: makeElement(),
- addEventListener: function (t, f) { (listeners[t] = listeners[t] || []).push(f); },
- removeEventListener: function () {},
- getElementById: function () { return null; },
- querySelectorAll: function () { return []; },
- querySelector: function () { return null; },
- createElement: function () { return makeElement(); },
- createTextNode: function (t) { return { nodeType: 3, textContent: t }; }
- };
- globalThis.window = globalThis;
- globalThis.location = { href: 'http://localhost/', protocol: 'http:', addEventListener: function () {} };
- globalThis.navigator = { userAgent: 'qjs' };
- globalThis.addEventListener = function (t, f) { (listeners[t] = listeners[t] || []).push(f); };
- globalThis.removeEventListener = function () {};
- globalThis.__STATUM_TEST__ = true;
- }
|