summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorTristian Flanagan <tflanagan@datacollaborative.com>2015-09-14 18:26:59 -0400
committercjihrig <cjihrig@gmail.com>2015-11-20 16:26:24 -0500
commitdfee4e3712ac4673b5fc472a8f77ac65bdc65f87 (patch)
tree143fd17bf90eaa8fec46ee72c4b1705de20f2d38 /test
parent94c3507f5c66a2c2da24591f9b28867465918675 (diff)
downloadandroid-node-v8-dfee4e3712ac4673b5fc472a8f77ac65bdc65f87.tar.gz
android-node-v8-dfee4e3712ac4673b5fc472a8f77ac65bdc65f87.tar.bz2
android-node-v8-dfee4e3712ac4673b5fc472a8f77ac65bdc65f87.zip
module: fix column offsets in errors
Because Node modules are wrapped, errors on the first line of a file leak the wrapper to the user and report the wrong column number. This commit adds a line break to the module wrapper so that the first line is treated the same as all other lines. To compensate for the additional line, a line offset of -1 is also applied to errors. Fixes: https://github.com/nodejs/node/issues/2860 PR-URL: https://github.com/nodejs/node/pull/2867 Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Diffstat (limited to 'test')
-rw-r--r--test/fixtures/test-error-first-line-offset.js1
-rw-r--r--test/parallel/test-vm-context.js12
-rw-r--r--test/sequential/test-module-loading.js8
3 files changed, 21 insertions, 0 deletions
diff --git a/test/fixtures/test-error-first-line-offset.js b/test/fixtures/test-error-first-line-offset.js
new file mode 100644
index 0000000000..9aeeab047d
--- /dev/null
+++ b/test/fixtures/test-error-first-line-offset.js
@@ -0,0 +1 @@
+error
diff --git a/test/parallel/test-vm-context.js b/test/parallel/test-vm-context.js
index 45e19e6638..e1cd2ef01e 100644
--- a/test/parallel/test-vm-context.js
+++ b/test/parallel/test-vm-context.js
@@ -60,3 +60,15 @@ var ctx = {};
Object.defineProperty(ctx, 'b', { configurable: false });
ctx = vm.createContext(ctx);
assert.equal(script.runInContext(ctx), false);
+
+// Error on the first line of a module should
+// have the correct line and column number
+assert.throws(function() {
+ vm.runInContext('throw new Error()', context, {
+ filename: 'expected-filename.js',
+ lineOffset: 32,
+ columnOffset: 123
+ });
+}, function(err) {
+ return /expected-filename.js:33:130/.test(err.stack);
+}, 'Expected appearance of proper offset in Error stack');
diff --git a/test/sequential/test-module-loading.js b/test/sequential/test-module-loading.js
index d53de512f2..a8696f84cd 100644
--- a/test/sequential/test-module-loading.js
+++ b/test/sequential/test-module-loading.js
@@ -279,3 +279,11 @@ process.on('exit', function() {
// #1440 Loading files with a byte order marker.
assert.equal(42, require('../fixtures/utf8-bom.js'));
assert.equal(42, require('../fixtures/utf8-bom.json'));
+
+// Error on the first line of a module should
+// have the correct line and column number
+assert.throws(function() {
+ require('../fixtures/test-error-first-line-offset.js');
+}, function(err) {
+ return /test-error-first-line-offset.js:1:1/.test(err.stack);
+}, 'Expected appearance of proper offset in Error stack');