Skip to content

Commit 117b20e

Browse files
gillesdemeyevanlucas
authored andcommitted
test: adds tests for vm invalid arguments
PR-URL: #18282 Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: Weijia Wang <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Luigi Pinca <[email protected]>
1 parent 45051fa commit 117b20e

File tree

1 file changed

+54
-1
lines changed

1 file changed

+54
-1
lines changed

test/parallel/test-vm-basic.js

+54-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
// USE OR OTHER DEALINGS IN THE SOFTWARE.
2121

2222
'use strict';
23-
require('../common');
23+
const common = require('../common');
2424
const assert = require('assert');
2525
const vm = require('vm');
2626

@@ -69,3 +69,56 @@ assert.strictEqual(result, 'undefined');
6969
const sandbox3 = {};
7070
const context2 = vm.createContext(sandbox3);
7171
assert.strictEqual(sandbox3, context2);
72+
73+
// Test 6: invalid arguments
74+
common.expectsError(() => {
75+
vm.createContext({}, null);
76+
}, {
77+
code: 'ERR_INVALID_ARG_TYPE',
78+
type: TypeError,
79+
message: 'The "options" argument must be of type object. Received type null'
80+
});
81+
82+
common.expectsError(() => {
83+
vm.createContext({}, 'string');
84+
}, {
85+
code: 'ERR_INVALID_ARG_TYPE',
86+
type: TypeError,
87+
message: 'The "options" argument must be of type object. Received type string'
88+
});
89+
90+
common.expectsError(() => {
91+
vm.createContext({}, { name: null });
92+
}, {
93+
code: 'ERR_INVALID_ARG_TYPE',
94+
type: TypeError,
95+
message: 'The "options.name" property must be of type string. ' +
96+
'Received type null'
97+
});
98+
99+
common.expectsError(() => {
100+
vm.createContext({}, { origin: null });
101+
}, {
102+
code: 'ERR_INVALID_ARG_TYPE',
103+
type: TypeError,
104+
message: 'The "options.origin" property must be of type string. ' +
105+
'Received type null'
106+
});
107+
108+
common.expectsError(() => {
109+
vm.runInNewContext('', {}, { contextName: null });
110+
}, {
111+
code: 'ERR_INVALID_ARG_TYPE',
112+
type: TypeError,
113+
message: 'The "options.contextName" property must be of type string. ' +
114+
'Received type null'
115+
});
116+
117+
common.expectsError(() => {
118+
vm.runInNewContext('', {}, { contextOrigin: null });
119+
}, {
120+
code: 'ERR_INVALID_ARG_TYPE',
121+
type: TypeError,
122+
message: 'The "options.contextOrigin" property must be of type string. ' +
123+
'Received type null'
124+
});

0 commit comments

Comments
 (0)