mirror of https://github.com/nodejs/node.git
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>pull/56191/head
parent
7904bc0976
commit
56c8360f87
|
@ -319,6 +319,7 @@ function runInThisContext(code, options) {
|
|||
|
||||
function compileFunction(code, params, options = kEmptyObject) {
|
||||
validateString(code, 'code');
|
||||
validateObject(options, 'options');
|
||||
if (params !== undefined) {
|
||||
validateStringArray(params, 'params');
|
||||
}
|
||||
|
|
|
@ -172,7 +172,30 @@ const vm = require('vm');
|
|||
'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 = {
|
||||
'filename': 'string',
|
||||
|
|
Loading…
Reference in New Issue