Skip to content

Commit

Permalink
lib: fix compileFunction throws range error for -ve ints
Browse files Browse the repository at this point in the history
  • Loading branch information
MrJithil committed Sep 25, 2023
1 parent 3922d18 commit 74641e5
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 3 deletions.
6 changes: 3 additions & 3 deletions lib/internal/vm.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ const {
validateObject,
validateString,
validateStringArray,
validateUint32,
validateInt32,
} = require('internal/validators');
const {
ERR_INVALID_ARG_TYPE,
Expand Down Expand Up @@ -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');
Expand Down
34 changes: 34 additions & 0 deletions test/es-module/test-vm-compile-function-lineoffset.js
Original file line number Diff line number Diff line change
@@ -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});

Check failure on line 16 in test/es-module/test-vm-compile-function-lineoffset.js

View workflow job for this annotation

GitHub Actions / lint-js-and-md

There should be no space before ','

Check failure on line 16 in test/es-module/test-vm-compile-function-lineoffset.js

View workflow job for this annotation

GitHub Actions / lint-js-and-md

A space is required before '}'
},
{
code: 'ERR_OUT_OF_RANGE',
name: 'RangeError',
message: /The value of "options.lineOffset" is out of range/,

Check failure on line 21 in test/es-module/test-vm-compile-function-lineoffset.js

View workflow job for this annotation

GitHub Actions / lint-js-and-md

Unescaped dot character in regular expression
}
);

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/,

Check failure on line 32 in test/es-module/test-vm-compile-function-lineoffset.js

View workflow job for this annotation

GitHub Actions / lint-js-and-md

Unescaped dot character in regular expression
}
);

0 comments on commit 74641e5

Please sign in to comment.