diff options
author | bcoe <bencoe@google.com> | 2021-06-13 19:21:40 +0300 |
---|---|---|
committer | Danielle Adams <adamzdanielle@gmail.com> | 2021-06-22 04:48:23 +0300 |
commit | eddde6c31a57a0a832ca85b3ed99574c43b3d11b (patch) | |
tree | f66e68af7715f99ae7ea05362e4c69b3ce650b0e /test | |
parent | d2b972ee5280a3b71912b1b5f8276be116f0bbf1 (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 'test')
-rw-r--r-- | test/fixtures/source-map/throw-string-original.js | 8 | ||||
-rw-r--r-- | test/fixtures/source-map/throw-string.js | 2 | ||||
-rw-r--r-- | test/parallel/test-source-map-enable.js | 17 |
3 files changed, 27 insertions, 0 deletions
diff --git a/test/fixtures/source-map/throw-string-original.js b/test/fixtures/source-map/throw-string-original.js new file mode 100644 index 00000000000..fe177b669fd --- /dev/null +++ b/test/fixtures/source-map/throw-string-original.js @@ -0,0 +1,8 @@ +/* + * comments dropped by uglify. + */ +function Hello() { + throw 'goodbye'; +} + +Hello(); diff --git a/test/fixtures/source-map/throw-string.js b/test/fixtures/source-map/throw-string.js new file mode 100644 index 00000000000..7a810e12f5f --- /dev/null +++ b/test/fixtures/source-map/throw-string.js @@ -0,0 +1,2 @@ +function Hello(){throw"goodbye"}Hello(); +//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbInRocm93LXN0cmluZy1vcmlnaW5hbC5qcyJdLCJuYW1lcyI6WyJIZWxsbyJdLCJtYXBwaW5ncyI6IkFBR0EsU0FBU0EsUUFDUCxLQUFNLFVBR1JBIn0= diff --git a/test/parallel/test-source-map-enable.js b/test/parallel/test-source-map-enable.js index 766c1e29554..e0c222d1a33 100644 --- a/test/parallel/test-source-map-enable.js +++ b/test/parallel/test-source-map-enable.js @@ -307,6 +307,23 @@ function nextdir() { assert.ok(sourceMap); } +// Does not throw TypeError when primitive value is thrown. +{ + const coverageDirectory = nextdir(); + const output = spawnSync(process.execPath, [ + '--enable-source-maps', + require.resolve('../fixtures/source-map/throw-string.js'), + ], { env: { ...process.env, NODE_V8_COVERAGE: coverageDirectory } }); + const sourceMap = getSourceMapFromCache( + 'throw-string.js', + coverageDirectory + ); + // Original stack trace. + assert.match(output.stderr.toString(), /goodbye/); + // Source map should have been serialized. + assert.ok(sourceMap); +} + function getSourceMapFromCache(fixtureFile, coverageDirectory) { const jsonFiles = fs.readdirSync(coverageDirectory); for (const jsonFile of jsonFiles) { |