Debian Codegraph @

addons/web/static/lib/hoot/mock/console.js

raw
1 /** @odoo-module */
2
3 import { MockEventTarget } from "../hoot_utils";
4 import { logger } from "../core/logger";
5
6 //-----------------------------------------------------------------------------
7 // Global
8 //-----------------------------------------------------------------------------
9
10 const {
11 console,
12 Object: { keys: $keys },
13 } = globalThis;
14
15 //-----------------------------------------------------------------------------
16 // Internal
17 //-----------------------------------------------------------------------------
18
19 const DISPATCHING_METHODS = ["error", "trace", "warn"];
20
21 //-----------------------------------------------------------------------------
22 // Exports
23 //-----------------------------------------------------------------------------
24
25 export class MockConsole extends MockEventTarget {
26 static {
27 for (const fnName of $keys(console)) {
28 if (DISPATCHING_METHODS.includes(fnName)) {
29 const fn = logger[fnName];
30 this.prototype[fnName] = function (...args) {
31 this.dispatchEvent(new CustomEvent(fnName, { detail: args }));
32 return fn.apply(this, arguments);
33 };
34 } else {
35 this.prototype[fnName] = console[fnName];
36 }
37 }
38 }
39 }