src: fix ^ in stack trace with vm's columnOffset · nodejs/node@931addb

2 files changed

lines changed

Original file line numberDiff line numberDiff line change

@@ -1585,6 +1585,7 @@ void AppendExceptionLine(Environment* env,

15851585

}

15861586
15871587

// Print (filename):(line number): (message).

1588+

ScriptOrigin origin = message->GetScriptOrigin();

15881589

node::Utf8Value filename(env->isolate(), message->GetScriptResourceName());

15891590

const char* filename_string = *filename;

15901591

int linenum = message->GetLineNumber();

@@ -1613,8 +1614,16 @@ void AppendExceptionLine(Environment* env,

16131614

// sourceline to 78 characters, and we end up not providing very much

16141615

// useful debugging info to the user if we remove 62 characters.

16151616
1617+

int script_start =

1618+

(linenum - origin.ResourceLineOffset()->Value()) == 1 ?

1619+

origin.ResourceColumnOffset()->Value() : 0;

16161620

int start = message->GetStartColumn(env->context()).FromMaybe(0);

16171621

int end = message->GetEndColumn(env->context()).FromMaybe(0);

1622+

if (start >= script_start) {

1623+

CHECK_GE(end, start);

1624+

start -= script_start;

1625+

end -= script_start;

1626+

}

16181627
16191628

char arrow[1024];

16201629

int max_off = sizeof(arrow) - 2;

Original file line numberDiff line numberDiff line change

@@ -72,13 +72,14 @@ assert.strictEqual(script.runInContext(ctx), false);

7272

// Error on the first line of a module should

7373

// have the correct line and column number

7474

assert.throws(() => {

75-

vm.runInContext('throw new Error()', context, {

75+

vm.runInContext(' throw new Error()', context, {

7676

filename: 'expected-filename.js',

7777

lineOffset: 32,

7878

columnOffset: 123

7979

});

8080

}, (err) => {

81-

return /expected-filename\.js:33:130/.test(err.stack);

81+

return /^ \^/m.test(err.stack) &&

82+

/expected-filename\.js:33:131/.test(err.stack);

8283

}, 'Expected appearance of proper offset in Error stack');

8384
8485

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