We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 21e21a2 commit ac57dadCopy full SHA for ac57dad
2 files changed
lib/vm.js
@@ -319,6 +319,7 @@ function runInThisContext(code, options) {
319
320
function compileFunction(code, params, options = kEmptyObject) {
321
validateString(code, 'code');
322
+ validateObject(options, 'options');
323
if (params !== undefined) {
324
validateStringArray(params, 'params');
325
}
test/parallel/test-vm-basic.js
@@ -172,7 +172,30 @@ const vm = require('vm');
172
'Received null'
173
});
174
175
- // vm.compileFunction('', undefined, null);
+ // Test for invalid options type
176
+ assert.throws(() => {
177
+ vm.compileFunction('', [], null);
178
+ }, {
179
+ name: 'TypeError',
180
+ code: 'ERR_INVALID_ARG_TYPE',
181
+ message: 'The "options" argument must be of type object. Received null'
182
+ });
183
+
184
185
+ vm.compileFunction('', [], 'string');
186
187
188
189
+ message: 'The "options" argument must be of type object. Received type string (\'string\')'
190
191
192
193
+ vm.compileFunction('', [], 123);
194
195
196
197
+ message: 'The "options" argument must be of type object. Received type number (123)'
198
199
200
const optionTypes = {
201
'filename': 'string',
0 commit comments