Skip to content

Commit aec036b

Browse files
committed
feat(core)!: Remove memoBuilder export & WeakSet fallback
All envs targeted for v9 should support WeakSet.
1 parent 888b05a commit aec036b

File tree

4 files changed

+27
-57
lines changed

4 files changed

+27
-57
lines changed

docs/migration/v8-to-v9.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,7 @@ Sentry.init({
131131
- The `flatten` export has been removed. There is no replacement.
132132
- The `urlEncode` method has been removed. There is no replacement.
133133
- The `getDomElement` method has been removed. There is no replacement.
134+
- The `memoBuilder` method has been removed. There is no replacement.
134135

135136
### `@sentry/browser`
136137

packages/core/src/utils-hoist/index.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,6 @@ export {
3838
} from './is';
3939
export { isBrowser } from './isBrowser';
4040
export { CONSOLE_LEVELS, consoleSandbox, logger, originalConsoleMethods } from './logger';
41-
// eslint-disable-next-line deprecation/deprecation
42-
export { memoBuilder } from './memo';
4341
export {
4442
addContextToFrame,
4543
addExceptionMechanism,

packages/core/src/utils-hoist/memo.ts

Lines changed: 0 additions & 52 deletions
This file was deleted.

packages/core/src/utils-hoist/normalize.ts

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
import type { Primitive } from '../types-hoist';
22

33
import { isSyntheticEvent, isVueViewModel } from './is';
4-
import type { MemoFunc } from './memo';
5-
import { memoBuilder } from './memo';
64
import { convertToPlainObject } from './object';
75
import { getFunctionName } from './stacktrace';
86

@@ -74,7 +72,6 @@ function visit(
7472
value: unknown,
7573
depth: number = +Infinity,
7674
maxProperties: number = +Infinity,
77-
// eslint-disable-next-line deprecation/deprecation
7875
memo: MemoFunc = memoBuilder(),
7976
): Primitive | ObjOrArray<unknown> {
8077
const [memoize, unmemoize] = memo;
@@ -304,3 +301,29 @@ export function normalizeUrlToBase(url: string, basePath: string): string {
304301
.replace(new RegExp(`(file://)?/*${escapedBase}/*`, 'ig'), 'app:///')
305302
);
306303
}
304+
305+
type MemoFunc = [
306+
// memoize
307+
(obj: object) => boolean,
308+
// unmemoize
309+
(obj: object) => void,
310+
];
311+
312+
/**
313+
* Helper to decycle json objects
314+
*/
315+
function memoBuilder(): MemoFunc {
316+
const inner = new WeakSet<object>();
317+
function memoize(obj: object): boolean {
318+
if (inner.has(obj)) {
319+
return true;
320+
}
321+
322+
return false;
323+
}
324+
325+
function unmemoize(obj: object): void {
326+
inner.delete(obj);
327+
}
328+
return [memoize, unmemoize];
329+
}

0 commit comments

Comments
 (0)