Odoo18-Base/addons/web/static/lib/hoot/mock/console.js
2025-01-06 10:57:38 +07:00

33 lines
1.1 KiB
JavaScript

/** @odoo-module */
//-----------------------------------------------------------------------------
// Global
//-----------------------------------------------------------------------------
const { console } = globalThis;
//-----------------------------------------------------------------------------
// Internal
//-----------------------------------------------------------------------------
const DISPATCHING_METHODS = ["error", "trace", "warn"];
//-----------------------------------------------------------------------------
// Exports
//-----------------------------------------------------------------------------
export class MockConsole extends EventTarget {
static {
for (const [name, value] of Object.entries(console)) {
if (DISPATCHING_METHODS.includes(name)) {
this.prototype[name] = function (...args) {
this.dispatchEvent(new CustomEvent(name, { detail: args }));
return value.apply(this, arguments);
};
} else {
this.prototype[name] = value;
}
}
}
}