Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nodejs/node.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorbcoe <bencoe@google.com>2021-06-13 19:21:40 +0300
committerDanielle Adams <adamzdanielle@gmail.com>2021-06-22 04:48:23 +0300
commiteddde6c31a57a0a832ca85b3ed99574c43b3d11b (patch)
treef66e68af7715f99ae7ea05362e4c69b3ce650b0e /lib
parentd2b972ee5280a3b71912b1b5f8276be116f0bbf1 (diff)
errors: don't rekey on primitive type
If an error is thrown before a module is loaded, we attempt to cache source map against error object, rather than module object. We can't do this if the error is a primitive type Fixes #38945 PR-URL: https://github.com/nodejs/node/pull/39025 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Rich Trott <rtrott@gmail.com> Reviewed-By: Michaƫl Zasso <targos@protonmail.com> Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
Diffstat (limited to 'lib')
-rw-r--r--lib/internal/modules/cjs/loader.js16
-rw-r--r--lib/internal/source_map/source_map_cache.js9
2 files changed, 1 insertions, 24 deletions
diff --git a/lib/internal/modules/cjs/loader.js b/lib/internal/modules/cjs/loader.js
index 4f2b5947552..d969a6449cf 100644
--- a/lib/internal/modules/cjs/loader.js
+++ b/lib/internal/modules/cjs/loader.js
@@ -74,9 +74,7 @@ module.exports = {
const { NativeModule } = require('internal/bootstrap/loaders');
const {
- getSourceMapsEnabled,
maybeCacheSourceMap,
- rekeySourceMap
} = require('internal/source_map/source_map_cache');
const { pathToFileURL, fileURLToPath, isURLInstance } = require('internal/url');
const { deprecate } = require('internal/util');
@@ -815,19 +813,7 @@ Module._load = function(request, parent, isMain) {
let threw = true;
try {
- // Intercept exceptions that occur during the first tick and rekey them
- // on error instance rather than module instance (which will immediately be
- // garbage collected).
- if (getSourceMapsEnabled()) {
- try {
- module.load(filename);
- } catch (err) {
- rekeySourceMap(Module._cache[filename], err);
- throw err; /* node-do-not-add-exception-line */
- }
- } else {
- module.load(filename);
- }
+ module.load(filename);
threw = false;
} finally {
if (threw) {
diff --git a/lib/internal/source_map/source_map_cache.js b/lib/internal/source_map/source_map_cache.js
index f0d911f78fa..07cdf8a337a 100644
--- a/lib/internal/source_map/source_map_cache.js
+++ b/lib/internal/source_map/source_map_cache.js
@@ -172,14 +172,6 @@ function sourcesToAbsolute(baseURL, data) {
return data;
}
-// Move source map from garbage collected module to alternate key.
-function rekeySourceMap(cjsModuleInstance, newInstance) {
- const sourceMap = cjsSourceMapCache.get(cjsModuleInstance);
- if (sourceMap) {
- cjsSourceMapCache.set(newInstance, sourceMap);
- }
-}
-
// WARNING: The `sourceMapCacheToObject` and `appendCJSCache` run during
// shutdown. In particular, they also run when Workers are terminated, making
// it important that they do not call out to any user-provided code, including
@@ -240,6 +232,5 @@ module.exports = {
findSourceMap,
getSourceMapsEnabled,
maybeCacheSourceMap,
- rekeySourceMap,
sourceMapCacheToObject,
};