GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — lib: lazy-load deps in source_map_cache.js · nodejs/node@baa280a

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • lib/internal/source_map
    • source_map_cache.js
  • test/parallel
    • test-bootstrap-modules.js
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎lib/internal/source_map/source_map_cache.js‎

Copy file name to clipboardExpand all lines: lib/internal/source_map/source_map_cache.js
+12-8Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -24,17 +24,19 @@ let debug = require('internal/util/debuglog').debuglog('source_map', (fn) => {
2424
debug = fn;
2525
});
2626
const { getOptionValue } = require('internal/options');
27-
const { IterableWeakMap } = require('internal/util/iterable_weak_map');
28-
const {
29-
normalizeReferrerURL,
30-
} = require('internal/modules/helpers');
27+
3128
const { validateBoolean } = require('internal/validators');
3229
const { setMaybeCacheGeneratedSourceMap } = internalBinding('errors');
30+
const { getLazy } = require('internal/util');
3331

3432
// Since the CJS module cache is mutable, which leads to memory leaks when
3533
// modules are deleted, we use a WeakMap so that the source map cache will
3634
// be purged automatically:
37-
const cjsSourceMapCache = new IterableWeakMap();
35+
const getCjsSourceMapCache = getLazy(() => {
36+
const { IterableWeakMap } = require('internal/util/iterable_weak_map');
37+
return new IterableWeakMap();
38+
});
39+
3840
// The esm cache is not mutable, so we can use a Map without memory concerns:
3941
const esmSourceMapCache = new SafeMap();
4042
// The generated sources is not mutable, so we can use a Map without memory concerns:
@@ -44,6 +46,7 @@ const kSourceMappingURLMagicComment = /\/[*/]#\s+sourceMappingURL=(?<sourceMappi
4446
const kSourceURLMagicComment = /\/[*/]#\s+sourceURL=(?<sourceURL>[^\s]+)/g;
4547

4648
const { fileURLToPath, pathToFileURL, URL } = require('internal/url');
49+
4750
let SourceMap;
4851

4952
let sourceMapsEnabled;
@@ -114,6 +117,7 @@ function maybeCacheSourceMap(filename, content, cjsModuleInstance, isGeneratedSo
114117
const sourceMapsEnabled = getSourceMapsEnabled();
115118
if (!(process.env.NODE_V8_COVERAGE || sourceMapsEnabled)) return;
116119
try {
120+
const { normalizeReferrerURL } = require('internal/modules/helpers');
117121
filename = normalizeReferrerURL(filename);
118122
} catch (err) {
119123
// This is most likely an invalid filename in sourceURL of [eval]-wrapper.
@@ -137,7 +141,7 @@ function maybeCacheSourceMap(filename, content, cjsModuleInstance, isGeneratedSo
137141
const data = dataFromUrl(filename, sourceMapURL);
138142
const url = data ? null : sourceMapURL;
139143
if (cjsModuleInstance) {
140-
cjsSourceMapCache.set(cjsModuleInstance, {
144+
getCjsSourceMapCache().set(cjsModuleInstance, {
141145
filename,
142146
lineLengths: lineLengths(content),
143147
data,
@@ -291,7 +295,7 @@ function sourceMapCacheToObject() {
291295
}
292296

293297
function appendCJSCache(obj) {
294-
for (const value of cjsSourceMapCache) {
298+
for (const value of getCjsSourceMapCache()) {
295299
obj[ObjectGetValueSafe(value, 'filename')] = {
296300
lineLengths: ObjectGetValueSafe(value, 'lineLengths'),
297301
data: ObjectGetValueSafe(value, 'data'),
@@ -309,7 +313,7 @@ function findSourceMap(sourceURL) {
309313
}
310314
let sourceMap = esmSourceMapCache.get(sourceURL) ?? generatedSourceMapCache.get(sourceURL);
311315
if (sourceMap === undefined) {
312-
for (const value of cjsSourceMapCache) {
316+
for (const value of getCjsSourceMapCache()) {
313317
const filename = ObjectGetValueSafe(value, 'filename');
314318
const cachedSourceURL = ObjectGetValueSafe(value, 'sourceURL');
315319
if (sourceURL === filename || sourceURL === cachedSourceURL) {
Collapse file

‎test/parallel/test-bootstrap-modules.js‎

Copy file name to clipboardExpand all lines: test/parallel/test-bootstrap-modules.js
-1Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,6 @@ const expectedModules = new Set([
8585
'NativeModule internal/util',
8686
'NativeModule internal/util/debuglog',
8787
'NativeModule internal/util/inspect',
88-
'NativeModule internal/util/iterable_weak_map',
8988
'NativeModule internal/util/types',
9089
'NativeModule internal/validators',
9190
'NativeModule internal/vm',

0 commit comments

Comments
0 (0)
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.