Skip to content

src: fix ^ in stack trace with vm's columnOffset #15771

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions src/node.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1714,6 +1714,7 @@ void AppendExceptionLine(Environment* env,
}

// Print (filename):(line number): (message).
ScriptOrigin origin = message->GetScriptOrigin();
node::Utf8Value filename(env->isolate(), message->GetScriptResourceName());
const char* filename_string = *filename;
int linenum = message->GetLineNumber();
Expand Down Expand Up @@ -1742,8 +1743,16 @@ void AppendExceptionLine(Environment* env,
// sourceline to 78 characters, and we end up not providing very much
// useful debugging info to the user if we remove 62 characters.

int script_start =
(linenum - origin.ResourceLineOffset()->Value()) == 1 ?
origin.ResourceColumnOffset()->Value() : 0;
int start = message->GetStartColumn(env->context()).FromMaybe(0);
int end = message->GetEndColumn(env->context()).FromMaybe(0);
if (start >= script_start) {
CHECK_GE(end, start);
start -= script_start;
end -= script_start;
}

char arrow[1024];
int max_off = sizeof(arrow) - 2;
Expand Down
5 changes: 3 additions & 2 deletions test/parallel/test-vm-context.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,13 +93,14 @@ assert.strictEqual(script.runInContext(ctx), false);
// Error on the first line of a module should
// have the correct line and column number
assert.throws(() => {
vm.runInContext('throw new Error()', context, {
vm.runInContext(' throw new Error()', context, {
filename: 'expected-filename.js',
lineOffset: 32,
columnOffset: 123
});
}, (err) => {
return /expected-filename\.js:33:130/.test(err.stack);
return /^ \^/m.test(err.stack) &&
/expected-filename\.js:33:131/.test(err.stack);
}, 'Expected appearance of proper offset in Error stack');

// https://github.com/nodejs/node/issues/6158
Expand Down