mirror of
https://github.com/nodejs/node.git
synced 2025-12-28 07:50:41 +00:00
src: fix undefined script name in error source
Some checks are pending
Coverage Linux (without intl) / coverage-linux-without-intl (push) Waiting to run
Coverage Linux / coverage-linux (push) Waiting to run
Coverage Windows / coverage-windows (push) Waiting to run
Test and upload documentation to artifacts / build-docs (push) Waiting to run
Linters / lint-addon-docs (push) Waiting to run
Linters / lint-cpp (push) Waiting to run
Linters / format-cpp (push) Waiting to run
Linters / lint-js-and-md (push) Waiting to run
Linters / lint-py (push) Waiting to run
Linters / lint-yaml (push) Waiting to run
Linters / lint-sh (push) Waiting to run
Linters / lint-codeowners (push) Waiting to run
Linters / lint-pr-url (push) Waiting to run
Linters / lint-readme (push) Waiting to run
Notify on Push / Notify on Force Push on `main` (push) Waiting to run
Notify on Push / Notify on Push on `main` that lacks metadata (push) Waiting to run
Scorecard supply-chain security / Scorecard analysis (push) Waiting to run
Some checks are pending
Coverage Linux (without intl) / coverage-linux-without-intl (push) Waiting to run
Coverage Linux / coverage-linux (push) Waiting to run
Coverage Windows / coverage-windows (push) Waiting to run
Test and upload documentation to artifacts / build-docs (push) Waiting to run
Linters / lint-addon-docs (push) Waiting to run
Linters / lint-cpp (push) Waiting to run
Linters / format-cpp (push) Waiting to run
Linters / lint-js-and-md (push) Waiting to run
Linters / lint-py (push) Waiting to run
Linters / lint-yaml (push) Waiting to run
Linters / lint-sh (push) Waiting to run
Linters / lint-codeowners (push) Waiting to run
Linters / lint-pr-url (push) Waiting to run
Linters / lint-readme (push) Waiting to run
Notify on Push / Notify on Force Push on `main` (push) Waiting to run
Notify on Push / Notify on Push on `main` that lacks metadata (push) Waiting to run
Scorecard supply-chain security / Scorecard analysis (push) Waiting to run
PR-URL: https://github.com/nodejs/node/pull/56502 Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
This commit is contained in:
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
|
||||
|
||||
9
test/fixtures/errors/throw_in_eval_anonymous.js
vendored
Normal file
9
test/fixtures/errors/throw_in_eval_anonymous.js
vendored
Normal file
@ -0,0 +1,9 @@
|
||||
'use strict';
|
||||
require('../../common');
|
||||
|
||||
Error.stackTraceLimit = 1;
|
||||
eval(`
|
||||
|
||||
throw new Error('error in anonymous script');
|
||||
|
||||
`)
|
||||
8
test/fixtures/errors/throw_in_eval_anonymous.snapshot
vendored
Normal file
8
test/fixtures/errors/throw_in_eval_anonymous.snapshot
vendored
Normal file
@ -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 *
|
||||
9
test/fixtures/errors/throw_in_eval_named.js
vendored
Normal file
9
test/fixtures/errors/throw_in_eval_named.js
vendored
Normal file
@ -0,0 +1,9 @@
|
||||
'use strict';
|
||||
require('../../common');
|
||||
|
||||
Error.stackTraceLimit = 1;
|
||||
eval(`
|
||||
|
||||
throw new Error('error in named script');
|
||||
|
||||
//# sourceURL=evalscript.js`)
|
||||
8
test/fixtures/errors/throw_in_eval_named.snapshot
vendored
Normal file
8
test/fixtures/errors/throw_in_eval_named.snapshot
vendored
Normal file
@ -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
Block a user