Skip to content

Commit 2c47e58

Browse files
cola119danielleadams
authored andcommitted
src: fix regression that a source marker is lost
PR-URL: #43086 Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Ben Coe <bencoe@gmail.com> Reviewed-By: Chengzhong Wu <legendecas@gmail.com>
1 parent 5aa3b21 commit 2c47e58

File tree

2 files changed

+11
-3
lines changed

2 files changed

+11
-3
lines changed

src/node_errors.cc

+2-1
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,8 @@ static std::string GetErrorSource(Isolate* isolate,
6262
// added in the JavaScript context:
6363
Environment* env = Environment::GetCurrent(isolate);
6464
const bool has_source_map_url =
65-
!message->GetScriptOrigin().SourceMapUrl().IsEmpty();
65+
!message->GetScriptOrigin().SourceMapUrl().IsEmpty() &&
66+
!message->GetScriptOrigin().SourceMapUrl()->IsUndefined();
6667
if (has_source_map_url && env != nullptr && env->source_maps_enabled()) {
6768
return sourceline;
6869
}

test/parallel/test-error-reporting.js

+9-2
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,10 @@ const assert = require('assert');
2525
const exec = require('child_process').exec;
2626
const fixtures = require('../common/fixtures');
2727

28-
function errExec(script, callback) {
29-
const cmd = `"${process.argv[0]}" "${fixtures.path(script)}"`;
28+
function errExec(script, option, callback) {
29+
callback = typeof option === 'function' ? option : callback;
30+
option = typeof option === 'string' ? option : '';
31+
const cmd = `"${process.argv[0]}" ${option} "${fixtures.path(script)}"`;
3032
return exec(cmd, (err, stdout, stderr) => {
3133
// There was some error
3234
assert.ok(err);
@@ -79,3 +81,8 @@ errExec('throws_error6.js', common.mustCall((err, stdout, stderr) => {
7981
errExec('throws_error7.js', common.mustCall((err, stdout, stderr) => {
8082
assert.match(stderr, /throw {\r?\n\^\r?\n{ toString: \[Function: toString] }\r?\n\r?\nNode\.js \S+\r?\n$/);
8183
}));
84+
85+
// Regression tests for https://github.com/nodejs/node/issues/39149
86+
errExec('throws_error7.js', '--enable-source-maps', common.mustCall((err, stdout, stderr) => {
87+
assert.match(stderr, /throw {\r?\n\^\r?\n{ toString: \[Function: toString] }\r?\n\r?\nNode\.js \S+\r?\n$/);
88+
}));

0 commit comments

Comments
 (0)