mirror of
https://github.com/zebrajr/node.git
synced 2025-12-06 00:20:08 +01: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
|
|
@ -16,9 +16,9 @@ const {
|
||||||
validateObject,
|
validateObject,
|
||||||
validateString,
|
validateString,
|
||||||
validateStringArray,
|
validateStringArray,
|
||||||
validateUint32,
|
|
||||||
kValidateObjectAllowArray,
|
kValidateObjectAllowArray,
|
||||||
kValidateObjectAllowNullable,
|
kValidateObjectAllowNullable,
|
||||||
|
validateInt32,
|
||||||
} = require('internal/validators');
|
} = require('internal/validators');
|
||||||
const {
|
const {
|
||||||
ERR_INVALID_ARG_TYPE,
|
ERR_INVALID_ARG_TYPE,
|
||||||
|
|
@ -48,8 +48,8 @@ function internalCompileFunction(code, params, options) {
|
||||||
} = options;
|
} = options;
|
||||||
|
|
||||||
validateString(filename, 'options.filename');
|
validateString(filename, 'options.filename');
|
||||||
validateUint32(columnOffset, 'options.columnOffset');
|
validateInt32(columnOffset, 'options.columnOffset');
|
||||||
validateUint32(lineOffset, 'options.lineOffset');
|
validateInt32(lineOffset, 'options.lineOffset');
|
||||||
if (cachedData !== undefined)
|
if (cachedData !== undefined)
|
||||||
validateBuffer(cachedData, 'options.cachedData');
|
validateBuffer(cachedData, 'options.cachedData');
|
||||||
validateBoolean(produceCachedData, 'options.produceCachedData');
|
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…
Reference in New Issue
Block a user