Skip to content

Commit abd71e6

Browse files
committed
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.
1 parent 95245a7 commit abd71e6

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)