|
20 | 20 | // USE OR OTHER DEALINGS IN THE SOFTWARE.
|
21 | 21 |
|
22 | 22 | 'use strict';
|
23 |
| -require('../common'); |
| 23 | +const common = require('../common'); |
24 | 24 | const assert = require('assert');
|
25 | 25 | const vm = require('vm');
|
26 | 26 |
|
@@ -69,3 +69,56 @@ assert.strictEqual(result, 'undefined');
|
69 | 69 | const sandbox3 = {};
|
70 | 70 | const context2 = vm.createContext(sandbox3);
|
71 | 71 | 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