UNPKG

@mtdt.temp/browser-core

Version:
62 lines 1.9 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.startMonitorErrorCollection = startMonitorErrorCollection; exports.setDebugMode = setDebugMode; exports.resetMonitor = resetMonitor; exports.monitored = monitored; exports.monitor = monitor; exports.callMonitored = callMonitored; exports.monitorError = monitorError; exports.displayIfDebugEnabled = displayIfDebugEnabled; const display_1 = require("./display"); let onMonitorErrorCollected; let debugMode = false; function startMonitorErrorCollection(newOnMonitorErrorCollected) { onMonitorErrorCollected = newOnMonitorErrorCollected; } function setDebugMode(newDebugMode) { debugMode = newDebugMode; } function resetMonitor() { onMonitorErrorCollected = undefined; debugMode = false; } function monitored(_, __, descriptor) { const originalMethod = descriptor.value; descriptor.value = function (...args) { const decorated = onMonitorErrorCollected ? monitor(originalMethod) : originalMethod; return decorated.apply(this, args); }; } function monitor(fn) { return function () { // eslint-disable-next-line @typescript-eslint/no-unsafe-return return callMonitored(fn, this, arguments); }; // consider output type has input type } function callMonitored(fn, context, args) { try { // eslint-disable-next-line @typescript-eslint/no-unsafe-return return fn.apply(context, args); } catch (e) { monitorError(e); } } function monitorError(e) { displayIfDebugEnabled(e); if (onMonitorErrorCollected) { try { onMonitorErrorCollected(e); } catch (e) { displayIfDebugEnabled(e); } } } function displayIfDebugEnabled(...args) { if (debugMode) { display_1.display.error('[MONITOR]', ...args); } } //# sourceMappingURL=monitor.js.map