Skip to content

Commit b799a74

Browse files
committed
src: fix line numbers on core errors
In dfee4e3, the module wrapper and line offset used when wrapping module code was changed to better report errors on the first line of modules. However, that commit did not update the runInThisContext() call used to execute the core modules, so their error line numbers have been off by one. This commit provides the correct lineOffset for core modules. Refs: #2867 PR-URL: #4254 Reviewed-By: Brian White <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Minwoo Jung <[email protected]> Reviewed-By: Ben Noordhuis <[email protected]>
1 parent 36ac3d6 commit b799a74

File tree

3 files changed

+30
-1
lines changed

3 files changed

+30
-1
lines changed

src/node.js

+4-1
Original file line numberDiff line numberDiff line change
@@ -966,7 +966,10 @@
966966
var source = NativeModule.getSource(this.id);
967967
source = NativeModule.wrap(source);
968968

969-
var fn = runInThisContext(source, { filename: this.filename });
969+
var fn = runInThisContext(source, {
970+
filename: this.filename,
971+
lineOffset: -1
972+
});
970973
fn(this.exports, NativeModule.require, this, this.filename);
971974

972975
this.loaded = true;

test/message/core_line_numbers.js

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
'use strict';
2+
const common = require('../common');
3+
const punycode = require('punycode');
4+
5+
// This test verifies that line numbers in core modules are reported correctly.
6+
// The punycode module was chosen for testing because it changes infrequently.
7+
// If this test begins failing, it is likely due to a punycode update, and the
8+
// test's assertions simply need to be updated to reflect the changes. If a
9+
// punycode update was not made, and this test begins failing, then line numbers
10+
// are probably actually broken.
11+
punycode.decode('x');

test/message/core_line_numbers.out

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
punycode.js:67
2+
throw new RangeError(errors[type]);
3+
^
4+
5+
RangeError: Invalid input
6+
at error (punycode.js:67:*)
7+
at Object.decode (punycode.js:*:*)
8+
at Object.<anonymous> (*test*message*core_line_numbers.js:*:*)
9+
at Module._compile (module.js:*:*)
10+
at Object.Module._extensions..js (module.js:*:*)
11+
at Module.load (module.js:*:*)
12+
at Function.Module._load (module.js:*:*)
13+
at Function.Module.runMain (module.js:*:*)
14+
at startup (node.js:*:*)
15+
at node.js:*:*

0 commit comments

Comments
 (0)