| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 65d485b commit 272ddb1
2 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -91,13 +91,15 @@ function Console(options /* or: stdout, stderr, ignoreErrors = true */) { | |||
| 91 | 91 | if (typeof colorMode !== 'boolean' && colorMode !== 'auto') | |
| 92 | 92 | throw new ERR_INVALID_ARG_VALUE('colorMode', colorMode); | |
| 93 | 93 | ||
| 94 | - if (inspectOptions) { | ||
| 94 | + if (typeof inspectOptions === 'object' && inspectOptions !== null) { | ||
| 95 | 95 | if (inspectOptions.colors !== undefined && | |
| 96 | 96 | options.colorMode !== undefined) { | |
| 97 | 97 | throw new ERR_INCOMPATIBLE_OPTION_PAIR( | |
| 98 | 98 | 'inspectOptions.color', 'colorMode'); | |
| 99 | 99 | } | |
| 100 | 100 | optionsMap.set(this, inspectOptions); | |
| 101 | + } else if (inspectOptions !== undefined) { | ||
| 102 | + throw new ERR_INVALID_ARG_TYPE('inspectOptions', 'object', inspectOptions); | ||
| 101 | 103 | } | |
| 102 | 104 | ||
| 103 | 105 | // Bind the prototype functions to this Console instance | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -128,3 +128,21 @@ out.write = err.write = (d) => {}; | |||
| 128 | 128 | assert.throws(() => c2.warn('foo'), /^Error: err$/); | |
| 129 | 129 | assert.throws(() => c2.dir('foo'), /^Error: out$/); | |
| 130 | 130 | } | |
| 131 | + | ||
| 132 | + // Console constructor throws if inspectOptions is not an object. | ||
| 133 | + [null, true, false, 'foo', 5, Symbol()].forEach((inspectOptions) => { | ||
| 134 | + assert.throws( | ||
| 135 | + () => { | ||
| 136 | + new Console({ | ||
| 137 | + stdout: out, | ||
| 138 | + stderr: err, | ||
| 139 | + inspectOptions | ||
| 140 | + }); | ||
| 141 | + }, | ||
| 142 | + { | ||
| 143 | + message: 'The "inspectOptions" argument must be of type object.' + | ||
| 144 | + ` Received type ${typeof inspectOptions}`, | ||
| 145 | + code: 'ERR_INVALID_ARG_TYPE' | ||
| 146 | + } | ||
| 147 | + ); | ||
| 148 | + }); | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments