mirror of https://github.com/nodejs/node.git
src: fix undefined script name in error source
PR-URL: https://github.com/nodejs/node/pull/56502 Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>pull/49292/merge
parent
6b3937a072
commit
483e3d5e4b
|
@ -136,8 +136,13 @@ static std::string GetErrorSource(Isolate* isolate,
|
|||
|
||||
// Print (filename):(line number): (message).
|
||||
ScriptOrigin origin = message->GetScriptOrigin();
|
||||
node::Utf8Value filename(isolate, message->GetScriptResourceName());
|
||||
const char* filename_string = *filename;
|
||||
std::string filename_string;
|
||||
if (message->GetScriptResourceName()->IsUndefined()) {
|
||||
filename_string = "<anonymous_script>";
|
||||
} else {
|
||||
node::Utf8Value filename(isolate, message->GetScriptResourceName());
|
||||
filename_string = filename.ToString();
|
||||
}
|
||||
int linenum = message->GetLineNumber(context).FromJust();
|
||||
|
||||
int script_start = (linenum - origin.LineOffset()) == 1
|
||||
|
|
|
@ -0,0 +1,9 @@
|
|||
'use strict';
|
||||
require('../../common');
|
||||
|
||||
Error.stackTraceLimit = 1;
|
||||
eval(`
|
||||
|
||||
throw new Error('error in anonymous script');
|
||||
|
||||
`)
|
|
@ -0,0 +1,8 @@
|
|||
<anonymous_script>:*
|
||||
throw new Error('error in anonymous script');
|
||||
^
|
||||
|
||||
Error: error in anonymous script
|
||||
at eval (eval at <anonymous> (*throw_in_eval_anonymous.js:*:*), <anonymous>:*:*)
|
||||
|
||||
Node.js *
|
|
@ -0,0 +1,9 @@
|
|||
'use strict';
|
||||
require('../../common');
|
||||
|
||||
Error.stackTraceLimit = 1;
|
||||
eval(`
|
||||
|
||||
throw new Error('error in named script');
|
||||
|
||||
//# sourceURL=evalscript.js`)
|
|
@ -0,0 +1,8 @@
|
|||
evalscript.js:*
|
||||
throw new Error('error in named script');
|
||||
^
|
||||
|
||||
Error: error in named script
|
||||
at eval (evalscript.js:*:*)
|
||||
|
||||
Node.js *
|
|
@ -63,6 +63,8 @@ describe('errors output', { concurrency: !process.env.TEST_PARALLEL }, () => {
|
|||
{ name: 'errors/if-error-has-good-stack.js', transform: errTransform },
|
||||
{ name: 'errors/throw_custom_error.js', transform: errTransform },
|
||||
{ name: 'errors/throw_error_with_getter_throw.js', transform: errTransform },
|
||||
{ name: 'errors/throw_in_eval_anonymous.js', transform: errTransform },
|
||||
{ name: 'errors/throw_in_eval_named.js', transform: errTransform },
|
||||
{ name: 'errors/throw_in_line_with_tabs.js', transform: errTransform },
|
||||
{ name: 'errors/throw_non_error.js', transform: errTransform },
|
||||
{ name: 'errors/throw_null.js', transform: errTransform },
|
||||
|
|
Loading…
Reference in New Issue