GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — lib: add validation for options in compileFunction · nodejs/node@68dda61

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • lib
    • vm.js
  • test/parallel
    • test-vm-basic.js
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎lib/vm.js‎

Copy file name to clipboardExpand all lines: lib/vm.js
+1Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -319,6 +319,7 @@ function runInThisContext(code, options) {
319319

320320
function compileFunction(code, params, options = kEmptyObject) {
321321
validateString(code, 'code');
322+
validateObject(options, 'options');
322323
if (params !== undefined) {
323324
validateStringArray(params, 'params');
324325
}
Collapse file

‎test/parallel/test-vm-basic.js‎

Copy file name to clipboardExpand all lines: test/parallel/test-vm-basic.js
+24-1Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,30 @@ const vm = require('vm');
172172
'Received null'
173173
});
174174

175-
// vm.compileFunction('', undefined, null);
175+
// 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+
assert.throws(() => {
185+
vm.compileFunction('', [], 'string');
186+
}, {
187+
name: 'TypeError',
188+
code: 'ERR_INVALID_ARG_TYPE',
189+
message: 'The "options" argument must be of type object. Received type string (\'string\')'
190+
});
191+
192+
assert.throws(() => {
193+
vm.compileFunction('', [], 123);
194+
}, {
195+
name: 'TypeError',
196+
code: 'ERR_INVALID_ARG_TYPE',
197+
message: 'The "options" argument must be of type object. Received type number (123)'
198+
});
176199

177200
const optionTypes = {
178201
'filename': 'string',

0 commit comments

Comments
0 (0)
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.