Skip to content

Commit adce20c

Browse files
legendecasaduh95
authored andcommitted
test: print stack immediately avoiding GC interleaving
`require(mod)` does not keep the mod in require cache if mod throws synchronously. This fixes the tests to print the stack immediately in case that source map cache could be cleaned up when the CJS module is reclaimed by GC in the next event loop tick. PR-URL: #61699 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Michaël Zasso <targos@protonmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Minwoo Jung <nodecorelab@gmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
1 parent c1c6641 commit adce20c

File tree

3 files changed

+6
-6
lines changed

3 files changed

+6
-6
lines changed

lib/internal/source_map/source_map_cache_map.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@ const {
1313
source_map_data_private_symbol,
1414
},
1515
} = internalBinding('util');
16+
let debug = require('internal/util/debuglog').debuglog('source_map', (fn) => {
17+
debug = fn;
18+
});
1619

1720
/**
1821
* Specialized map of WeakRefs to module instances that caches source map
@@ -46,6 +49,7 @@ class SourceMapCacheMap {
4649
ArrayPrototypeForEach(keys, (key) => {
4750
const ref = this.#weakModuleMap.get(key);
4851
if (ref && ref.deref() === undefined) {
52+
debug(`Cleanup obsolete source map cache entry with key: ${key}`);
4953
this.#weakModuleMap.delete(key);
5054
}
5155
});

test/fixtures/source-map/output/source_map_sourcemapping_url_string.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,5 @@ Error.stackTraceLimit = 2;
77
try {
88
require('../typescript-sourcemapping_url_string');
99
} catch (err) {
10-
setTimeout(() => {
11-
console.info(err);
12-
}, 10);
10+
console.info(err);
1311
}

test/fixtures/source-map/output/source_map_throw_catch.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,5 @@ Error.stackTraceLimit = 2;
77
try {
88
require('../typescript-throw');
99
} catch (err) {
10-
setTimeout(() => {
11-
console.info(err);
12-
}, 10);
10+
console.info(err);
1311
}

0 commit comments

Comments
 (0)