Skip to content

Commit aee3244

Browse files
committed
extract traceUtil
1 parent c799d23 commit aee3244

File tree

11 files changed

+274
-267
lines changed

11 files changed

+274
-267
lines changed

jest/tests/wrappers.test.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,10 @@ import { TAG_EXCEPTION, TAG_UNDEFINED } from '../../src/api/clone.ts';
1212
import {
1313
TAG_EVAL_RETURN_SET_TIMEOUT,
1414
TAG_EVAL_RETURN_SET_INTERVAL,
15-
TRACE_ERROR_MESSAGE,
1615
TAG_MISSFORTUNE,
1716
} from '../../src/api/const.ts';
1817
import { EWrapperCallstackType } from '../../src/api/settings.ts';
18+
import { TRACE_ERROR_MESSAGE } from '../../src/wrapper/traceUtil.ts';
1919

2020
const TEST_STACK = `Error: ${TRACE_ERROR_MESSAGE}
2121
at <anonymous>:1:1
@@ -383,7 +383,7 @@ describe('wrappers', () => {
383383
{ name: 'call1', link: 'https://example1.com/bundle2.js:3:4' },
384384
{ name: 'call2', link: 'https://example2.com/bundle3.js:4:5' },
385385
];
386-
const { trace } = wrapper.createCallstack(
386+
const { trace } = wrapper.traceUtil.createCallstack(
387387
<Error>{ stack: TEST_STACK },
388388
null
389389
);
@@ -400,7 +400,7 @@ describe('wrappers', () => {
400400
{ name: 'call2', link: 'https://example2.com/bundle3.js:4:5' },
401401
];
402402
wrapper.setCallstackType(EWrapperCallstackType.SHORT);
403-
const { trace } = wrapper.createCallstack(
403+
const { trace } = wrapper.traceUtil.createCallstack(
404404
<Error>{ stack: TEST_STACK },
405405
null
406406
);

src/api-monitor-cs-main.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import {
1111
doMediaCommand,
1212
type TMediaTelemetry,
1313
} from './api/mediaMonitor.ts';
14-
import { Wrapper, TimerType, type TWrapperMetrics } from './wrapper/main.ts';
14+
import { Wrapper, ETimerType, type TWrapperMetrics } from './wrapper/main.ts';
1515
import { panelsArray2Map, type TPanelVisibilityMap } from './api/settings.ts';
1616

1717
export interface TMetrics {
@@ -59,7 +59,7 @@ windowListen((o) => {
5959
wrapper.cleanHistory();
6060
!tick.isPending && tick.trigger();
6161
} else if (o.msg === 'clear-timer-handler') {
62-
if (o.type === TimerType.TIMEOUT) {
62+
if (o.type === ETimerType.TIMEOUT) {
6363
window.clearTimeout(o.handler);
6464
} else {
6565
window.clearInterval(o.handler);

src/api/communication.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
import { APPLICATION_NAME } from './env.ts';
1414
import { ERRORS_IGNORED } from './const.ts';
1515
import type { TMetrics } from '../api-monitor-cs-main.ts';
16-
import type { TTimerType } from '../wrapper/main.ts';
16+
import { ETimerType } from '../wrapper/main.ts';
1717
import type { TSettings } from './settings.ts';
1818

1919
let port: chrome.runtime.Port | null = null;
@@ -106,7 +106,7 @@ export interface TMsgResetHistory {
106106
}
107107
export interface TMsgClearHandler {
108108
msg: 'clear-timer-handler';
109-
type: TTimerType;
109+
type: ETimerType;
110110
handler: number;
111111
}
112112
export interface TMsgLoaded {

src/api/const.ts

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ export const cancelIdleCallback =
2727
export const lessEval = /*@__PURE__*/ window.eval.bind(window);
2828

2929
export const TAG_MISSFORTUNE = '❓\u00A0⟪N/A⟫';
30-
export const TAG_INVALID_CALLSTACK_LINK = '⟪N/A⟫';
3130
export const TAG_EVAL_RETURN_SET_TIMEOUT = '(N/A - via setTimeout)';
3231
export const TAG_EVAL_RETURN_SET_INTERVAL = '(N/A - via setInterval)';
3332

@@ -127,22 +126,3 @@ export const READY_STATE = [
127126
'HAVE_FUTURE_DATA',
128127
'HAVE_ENOUGH_DATA',
129128
];
130-
131-
export const TRACE_ERROR_MESSAGE = 'browser-api-monitor';
132-
export const REGEX_STACKTRACE_SPLIT = /*@__PURE__*/ new RegExp(/\n\s+at\s/);
133-
export const REGEX_STACKTRACE_NAME = /*@__PURE__*/ new RegExp(/^(.+)\(.*/);
134-
export const REGEX_STACKTRACE_LINK = /*@__PURE__*/ new RegExp(
135-
/.*\((async )?(.*)\)$/
136-
);
137-
export const REGEX_STACKTRACE_CLEAN_URL = /*@__PURE__*/ new RegExp(
138-
/(.*):\d+:\d+$/
139-
);
140-
export const REGEX_STACKTRACE_LINE_NUMBER = /*@__PURE__*/ new RegExp(
141-
/.*:(\d+):\d+$/
142-
);
143-
export const REGEX_STACKTRACE_COLUMN_NUMBER = /*@__PURE__*/ new RegExp(
144-
/.*:\d+:(\d+)$/
145-
);
146-
export const REGEX_STACKTRACE_LINK_PROTOCOL = /*@__PURE__*/ new RegExp(
147-
/http[s]?\:\/\//
148-
);

src/view/components/TimersMetrics.svelte

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<script lang="ts">
22
import type { TMetrics } from '../../api-monitor-cs-main.ts';
3-
import { TimerType, type TOnlineTimerMetrics } from '../../wrapper/main.ts';
3+
import { ETimerType, type TOnlineTimerMetrics } from '../../wrapper/main.ts';
44
import ActiveTimers from './ActiveTimers.svelte';
55
import TimersSetHistory from './TimersSetHistory.svelte';
66
import TimersClearHistory from './TimersClearHistory.svelte';
@@ -21,7 +21,7 @@
2121
metrics.onlineTimers.sort(compareByDelayThenHandlerDescending);
2222
2323
for (const timer of metrics.onlineTimers) {
24-
if (timer.type === TimerType.TIMEOUT) {
24+
if (timer.type === ETimerType.TIMEOUT) {
2525
timeouts.push(timer);
2626
} else {
2727
intervals.push(timer);

src/view/components/Trace.svelte

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<script lang="ts">
2-
import type { TTrace } from '../../wrapper/main.ts';
2+
import type { TTrace } from '../../wrapper/traceUtil.ts';
33
import TraceLink from './TraceLink.svelte';
44
55
let { trace }: { trace: TTrace[] } = $props();
Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
<script lang="ts">
2-
import { TraceDomain, type TTraceDomain } from 'src/wrapper/main.ts';
2+
import { ETraceDomain } from '../../wrapper/traceUtil.ts';
33
4-
let { traceDomain }: { traceDomain: TTraceDomain } = $props();
4+
let { traceDomain }: { traceDomain: ETraceDomain } = $props();
55
</script>
66

7-
{#if traceDomain === TraceDomain.SAME}
7+
{#if traceDomain === ETraceDomain.SAME}
88
<span class="icon -small -trace-local" title="Same domain"></span>
9-
{:else if traceDomain === TraceDomain.EXTERNAL}
9+
{:else if traceDomain === ETraceDomain.EXTERNAL}
1010
<span class="icon -small -trace-external" title="External domain"></span>
11-
{:else if traceDomain === TraceDomain.EXTENSION}
11+
{:else if traceDomain === ETraceDomain.EXTENSION}
1212
<span class="icon -small -trace-extension" title="Local extension"></span>
13-
{:else if traceDomain === TraceDomain.UNKNOWN}
13+
{:else if traceDomain === ETraceDomain.UNKNOWN}
1414
<span title="Unknown domain">❓</span>
1515
{/if}

src/view/components/TraceLink.svelte

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
REGEX_STACKTRACE_COLUMN_NUMBER,
55
REGEX_STACKTRACE_LINE_NUMBER,
66
TAG_INVALID_CALLSTACK_LINK,
7-
} from '../../api/const.ts';
7+
} from 'src/wrapper/traceUtil.ts';
88
99
let {
1010
name,

0 commit comments

Comments
 (0)