diff --git a/lib/internal/vm.js b/lib/internal/vm.js index b14ba13e7e4cfb..d2063c78e6315d 100644 --- a/lib/internal/vm.js +++ b/lib/internal/vm.js @@ -16,7 +16,7 @@ const { validateObject, validateString, validateStringArray, - validateUint32, + validateInt32, } = require('internal/validators'); const { ERR_INVALID_ARG_TYPE, @@ -46,8 +46,8 @@ function internalCompileFunction(code, params, options) { } = options; validateString(filename, 'options.filename'); - validateUint32(columnOffset, 'options.columnOffset'); - validateUint32(lineOffset, 'options.lineOffset'); + validateInt32(columnOffset, 'options.columnOffset'); + validateInt32(lineOffset, 'options.lineOffset'); if (cachedData !== undefined) validateBuffer(cachedData, 'options.cachedData'); validateBoolean(produceCachedData, 'options.produceCachedData'); diff --git a/test/parallel/test-vm-basic.js b/test/parallel/test-vm-basic.js index f2424128b66e9f..f70141e2b17a22 100644 --- a/test/parallel/test-vm-basic.js +++ b/test/parallel/test-vm-basic.js @@ -254,6 +254,28 @@ const vm = require('vm'); // Setting value to run the last three tests Error.stackTraceLimit = 1; + assert.throws(() => { + vm.compileFunction( + 'throw new Error("Sample Error")', + [], + { lineOffset: -1 } + )(); + }, { + message: 'Sample Error', + stack: 'Error: Sample Error\n at ' + }); + + assert.throws(() => { + vm.compileFunction( + 'throw new Error("Sample Error")', + [], + { lineOffset: -2 } + )(); + }, { + message: 'Sample Error', + stack: 'Error: Sample Error\n at :-1:7' + }); + assert.throws(() => { vm.compileFunction('throw new Error("Sample Error")')(); }, { @@ -272,6 +294,17 @@ const vm = require('vm'); stack: 'Error: Sample Error\n at :4:7' }); + assert.throws(() => { + vm.compileFunction( + 'throw new Error("Sample Error")', + [], + { columnOffset: -1 } + )(); + }, { + message: 'Sample Error', + stack: 'Error: Sample Error\n at :1:6' + }); + assert.throws(() => { vm.compileFunction( 'throw new Error("Sample Error")',