diff --git a/lib/internal/vm.js b/lib/internal/vm.js index 100118e7b4dbb5..f348ef6d2d612f 100644 --- a/lib/internal/vm.js +++ b/lib/internal/vm.js @@ -16,9 +16,9 @@ const { validateObject, validateString, validateStringArray, - validateUint32, kValidateObjectAllowArray, kValidateObjectAllowNullable, + validateInt32, } = require('internal/validators'); const { ERR_INVALID_ARG_TYPE, @@ -48,8 +48,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..47846a3aa6eb8b --- /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/, + } +);