diff --git a/lib/internal/vm.js b/lib/internal/vm.js index ba5e2324667374..70dbd866e66bd7 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/es-module/test-vm-compile-function-lineoffset.js b/test/es-module/test-vm-compile-function-lineoffset.js new file mode 100644 index 00000000000000..0d54598d2464df --- /dev/null +++ b/test/es-module/test-vm-compile-function-lineoffset.js @@ -0,0 +1,34 @@ +'use strict'; + +require('../common'); + +const assert = require('assert'); +const { compileFunction } = require('node:vm'); + +const min = -2147483648; +const max = 2147483647; + +compileFunction('', [], { lineOffset: min, columnOffset: min }); +compileFunction('', [], { lineOffset: max, columnOffset: max }); + +assert.throws( + () => { + compileFunction('', [], { lineOffset: min - 1 , columnOffset: max}); + }, + { + code: 'ERR_OUT_OF_RANGE', + name: 'RangeError', + message: /The value of "options.lineOffset" is out of range/, + } +); + +assert.throws( + () => { + compileFunction('', [], { lineOffset: min, columnOffset: min - 1 }); + }, + { + code: 'ERR_OUT_OF_RANGE', + name: 'RangeError', + message: /The value of "options.columnOffset" is out of range/, + } +);