From ec1645b1f0db68863fdf2661ec6a088b5d160113 Mon Sep 17 00:00:00 2001 From: cola119 Date: Wed, 18 May 2022 22:39:10 +0900 Subject: [PATCH] src: fix regression that a source marker is lost PR-URL: https://github.com/nodejs/node/pull/43086 Reviewed-By: Joyee Cheung Reviewed-By: James M Snell Reviewed-By: Colin Ihrig Reviewed-By: Ben Coe Reviewed-By: Chengzhong Wu --- src/node_errors.cc | 3 ++- test/parallel/test-error-reporting.js | 11 +++++++++-- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/src/node_errors.cc b/src/node_errors.cc index 8c29dd854862c1..b3929c0c5141c9 100644 --- a/src/node_errors.cc +++ b/src/node_errors.cc @@ -62,7 +62,8 @@ static std::string GetErrorSource(Isolate* isolate, // added in the JavaScript context: Environment* env = Environment::GetCurrent(isolate); const bool has_source_map_url = - !message->GetScriptOrigin().SourceMapUrl().IsEmpty(); + !message->GetScriptOrigin().SourceMapUrl().IsEmpty() && + !message->GetScriptOrigin().SourceMapUrl()->IsUndefined(); if (has_source_map_url && env != nullptr && env->source_maps_enabled()) { return sourceline; } diff --git a/test/parallel/test-error-reporting.js b/test/parallel/test-error-reporting.js index 75574641ec7b79..39cb5f9558926d 100644 --- a/test/parallel/test-error-reporting.js +++ b/test/parallel/test-error-reporting.js @@ -25,8 +25,10 @@ const assert = require('assert'); const exec = require('child_process').exec; const fixtures = require('../common/fixtures'); -function errExec(script, callback) { - const cmd = `"${process.argv[0]}" "${fixtures.path(script)}"`; +function errExec(script, option, callback) { + callback = typeof option === 'function' ? option : callback; + option = typeof option === 'string' ? option : ''; + const cmd = `"${process.argv[0]}" ${option} "${fixtures.path(script)}"`; return exec(cmd, (err, stdout, stderr) => { // There was some error assert.ok(err); @@ -80,3 +82,8 @@ errExec('throws_error7.js', common.mustCall((err, stdout, stderr) => { assert.match(stderr, /throw {\r?\n\^\r?\n{ toString: \[Function: toString] }\r?\n$/); })); + +// Regression tests for https://github.com/nodejs/node/issues/39149 +errExec('throws_error7.js', '--enable-source-maps', common.mustCall((err, stdout, stderr) => { + assert.match(stderr, /throw {\r?\n\^\r?\n{ toString: \[Function: toString] }\r?\n$/); +}));