mirror of
https://github.com/nodejs/node.git
synced 2025-08-15 13:48:44 +02:00
lib: fix compileFunction throws range error for negative numbers
PR-URL: https://github.com/nodejs/node/pull/49855 Fixes: https://github.com/nodejs/node/issues/49848 Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com> Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
This commit is contained in:
parent
2fe511ba23
commit
d4c5fe488e
2 changed files with 37 additions and 3 deletions
|
@ -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');
|
||||
|
|
34
test/es-module/test-vm-compile-function-lineoffset.js
Normal file
34
test/es-module/test-vm-compile-function-lineoffset.js
Normal file
|
@ -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/,
|
||||
}
|
||||
);
|
Loading…
Add table
Add a link
Reference in a new issue