From 414ea74781d941fc1faa1a03afa6b6db02cdf67b Mon Sep 17 00:00:00 2001 From: bcoe Date: Mon, 2 Nov 2020 16:57:33 -0800 Subject: [PATCH 01/10] module: refactor to use iterable-weak-map Using an iterable WeakMap (a data-structure that uses WeakRef and WeakMap), we are able to: stop relying on Module._cache to serialize source maps; stop requiring an error object when calling findSourceMap(). --- doc/api/module.md | 10 +-- .../source_map/prepare_stack_trace.js | 2 +- lib/internal/source_map/source_map_cache.js | 88 ++++++++----------- lib/internal/util/iterable-weak-map.js | 69 +++++++++++++++ node.gyp | 1 + test/parallel/test-bootstrap-modules.js | 1 + test/parallel/test-source-map-api.js | 2 +- 7 files changed, 112 insertions(+), 61 deletions(-) create mode 100644 lib/internal/util/iterable-weak-map.js diff --git a/doc/api/module.md b/doc/api/module.md index 2fb6ca884b4443..aa47181b4055cc 100644 --- a/doc/api/module.md +++ b/doc/api/module.md @@ -135,7 +135,7 @@ import { findSourceMap, SourceMap } from 'module'; const { findSourceMap, SourceMap } = require('module'); ``` -### `module.findSourceMap(path[, error])` +### `module.findSourceMap(path)` * `path` {string} -* `error` {Error} * Returns: {module.SourceMap} `path` is the resolved path for the file for which a corresponding source map should be fetched. -The `error` instance should be passed as the second parameter to `findSourceMap` -in exceptional flows, such as when an overridden -[`Error.prepareStackTrace(error, trace)`][] is invoked. Modules are not added to -the module cache until they are successfully loaded. In these cases, source maps -are associated with the `error` instance along with the `path`. - ### Class: `module.SourceMap` + ### `module.findSourceMap(path)` + - + ### `module.findSourceMap(path)` -* `module.findSourceMap(path[, error])` +* `module.findSourceMap(path)` * Class: `module.SourceMap` * `new SourceMap(payload)` * `sourceMap.payload` diff --git a/lib/internal/util/iterable_weak_map.js b/lib/internal/util/iterable_weak_map.js index 7a4294bf06fb8a..3fa139b23e4b4e 100644 --- a/lib/internal/util/iterable_weak_map.js +++ b/lib/internal/util/iterable_weak_map.js @@ -5,7 +5,7 @@ const { Object, SafeSet, SafeWeakMap, - Symbol, + SymbolIterator, } = primordials; // TODO(aduh95): Add FinalizationRegistry to primordials