lib: add validation for options in compileFunction
PR-URL: https://github.com/nodejs/node/pull/56023 Reviewed-By: Chengzhong Wu <legendecas@gmail.com> Reviewed-By: Juan José Arboleda <soyjuanarbol@gmail.com>
This commit is contained in:
parent
7904bc0976
commit
56c8360f87
@ -319,6 +319,7 @@ function runInThisContext(code, options) {
|
|||||||
|
|
||||||
function compileFunction(code, params, options = kEmptyObject) {
|
function compileFunction(code, params, options = kEmptyObject) {
|
||||||
validateString(code, 'code');
|
validateString(code, 'code');
|
||||||
|
validateObject(options, 'options');
|
||||||
if (params !== undefined) {
|
if (params !== undefined) {
|
||||||
validateStringArray(params, 'params');
|
validateStringArray(params, 'params');
|
||||||
}
|
}
|
||||||
|
@ -172,7 +172,30 @@ const vm = require('vm');
|
|||||||
'Received null'
|
'Received null'
|
||||||
});
|
});
|
||||||
|
|
||||||
// vm.compileFunction('', undefined, null);
|
// Test for invalid options type
|
||||||
|
assert.throws(() => {
|
||||||
|
vm.compileFunction('', [], null);
|
||||||
|
}, {
|
||||||
|
name: 'TypeError',
|
||||||
|
code: 'ERR_INVALID_ARG_TYPE',
|
||||||
|
message: 'The "options" argument must be of type object. Received null'
|
||||||
|
});
|
||||||
|
|
||||||
|
assert.throws(() => {
|
||||||
|
vm.compileFunction('', [], 'string');
|
||||||
|
}, {
|
||||||
|
name: 'TypeError',
|
||||||
|
code: 'ERR_INVALID_ARG_TYPE',
|
||||||
|
message: 'The "options" argument must be of type object. Received type string (\'string\')'
|
||||||
|
});
|
||||||
|
|
||||||
|
assert.throws(() => {
|
||||||
|
vm.compileFunction('', [], 123);
|
||||||
|
}, {
|
||||||
|
name: 'TypeError',
|
||||||
|
code: 'ERR_INVALID_ARG_TYPE',
|
||||||
|
message: 'The "options" argument must be of type object. Received type number (123)'
|
||||||
|
});
|
||||||
|
|
||||||
const optionTypes = {
|
const optionTypes = {
|
||||||
'filename': 'string',
|
'filename': 'string',
|
||||||
|
Loading…
x
Reference in New Issue
Block a user