Skip to content

vm: support negative number lineOffset and columnOffset #48169

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
33 changes: 33 additions & 0 deletions test/parallel/test-vm-basic.js
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,28 @@ const vm = require('vm');
// Setting value to run the last three tests
Error.stackTraceLimit = 1;

assert.throws(() => {
vm.compileFunction(
'throw new Error("Sample Error")',
[],
{ lineOffset: -1 }
)();
}, {
message: 'Sample Error',
stack: 'Error: Sample Error\n at <anonymous>'
});

assert.throws(() => {
vm.compileFunction(
'throw new Error("Sample Error")',
[],
{ lineOffset: -2 }
)();
}, {
message: 'Sample Error',
stack: 'Error: Sample Error\n at <anonymous>:-1:7'
});

assert.throws(() => {
vm.compileFunction('throw new Error("Sample Error")')();
}, {
Expand All @@ -272,6 +294,17 @@ const vm = require('vm');
stack: 'Error: Sample Error\n at <anonymous>:4:7'
});

assert.throws(() => {
vm.compileFunction(
'throw new Error("Sample Error")',
[],
{ columnOffset: -1 }
)();
}, {
message: 'Sample Error',
stack: 'Error: Sample Error\n at <anonymous>:1:6'
});

assert.throws(() => {
vm.compileFunction(
'throw new Error("Sample Error")',
Expand Down