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 — console: improve inspectOptions validation · nodejs/node@272ddb1

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • lib/internal/console
    • constructor.js
  • test/parallel
    • test-console-instance.js
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎lib/internal/console/constructor.js‎

Copy file name to clipboardExpand all lines: lib/internal/console/constructor.js
+3-1Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,13 +91,15 @@ function Console(options /* or: stdout, stderr, ignoreErrors = true */) {
9191
if (typeof colorMode !== 'boolean' && colorMode !== 'auto')
9292
throw new ERR_INVALID_ARG_VALUE('colorMode', colorMode);
9393

94-
if (inspectOptions) {
94+
if (typeof inspectOptions === 'object' && inspectOptions !== null) {
9595
if (inspectOptions.colors !== undefined &&
9696
options.colorMode !== undefined) {
9797
throw new ERR_INCOMPATIBLE_OPTION_PAIR(
9898
'inspectOptions.color', 'colorMode');
9999
}
100100
optionsMap.set(this, inspectOptions);
101+
} else if (inspectOptions !== undefined) {
102+
throw new ERR_INVALID_ARG_TYPE('inspectOptions', 'object', inspectOptions);
101103
}
102104

103105
// Bind the prototype functions to this Console instance
Collapse file

‎test/parallel/test-console-instance.js‎

Copy file name to clipboardExpand all lines: test/parallel/test-console-instance.js
+18Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,3 +128,21 @@ out.write = err.write = (d) => {};
128128
assert.throws(() => c2.warn('foo'), /^Error: err$/);
129129
assert.throws(() => c2.dir('foo'), /^Error: out$/);
130130
}
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+
});

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.