From abd71e6dff956628dcf4ef41b328dcc5a9f041be Mon Sep 17 00:00:00 2001 From: Chengzhong Wu Date: Thu, 5 Feb 2026 21:58:28 +0000 Subject: [PATCH] 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. --- lib/internal/source_map/source_map_cache_map.js | 4 ++++ .../source-map/output/source_map_sourcemapping_url_string.js | 4 +--- test/fixtures/source-map/output/source_map_throw_catch.js | 4 +--- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/lib/internal/source_map/source_map_cache_map.js b/lib/internal/source_map/source_map_cache_map.js index dcacfd9bdbf269..10561acffc4bab 100644 --- a/lib/internal/source_map/source_map_cache_map.js +++ b/lib/internal/source_map/source_map_cache_map.js @@ -13,6 +13,9 @@ const { source_map_data_private_symbol, }, } = internalBinding('util'); +let debug = require('internal/util/debuglog').debuglog('source_map', (fn) => { + debug = fn; +}); /** * Specialized map of WeakRefs to module instances that caches source map @@ -46,6 +49,7 @@ class SourceMapCacheMap { ArrayPrototypeForEach(keys, (key) => { const ref = this.#weakModuleMap.get(key); if (ref && ref.deref() === undefined) { + debug(`Cleanup obsolete source map cache entry with key: ${key}`); this.#weakModuleMap.delete(key); } }); diff --git a/test/fixtures/source-map/output/source_map_sourcemapping_url_string.js b/test/fixtures/source-map/output/source_map_sourcemapping_url_string.js index 8dca7a35bfe7b9..1890e6e0b6d429 100644 --- a/test/fixtures/source-map/output/source_map_sourcemapping_url_string.js +++ b/test/fixtures/source-map/output/source_map_sourcemapping_url_string.js @@ -7,7 +7,5 @@ Error.stackTraceLimit = 2; try { require('../typescript-sourcemapping_url_string'); } catch (err) { - setTimeout(() => { - console.info(err); - }, 10); + console.info(err); } diff --git a/test/fixtures/source-map/output/source_map_throw_catch.js b/test/fixtures/source-map/output/source_map_throw_catch.js index c49ffcff865907..75ce228c918870 100644 --- a/test/fixtures/source-map/output/source_map_throw_catch.js +++ b/test/fixtures/source-map/output/source_map_throw_catch.js @@ -7,7 +7,5 @@ Error.stackTraceLimit = 2; try { require('../typescript-throw'); } catch (err) { - setTimeout(() => { - console.info(err); - }, 10); + console.info(err); }