Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

console: improve code readability #24412

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 16 additions & 13 deletions lib/console.js
Original file line number Diff line number Diff line change
Expand Up @@ -97,23 +97,26 @@ function Console(options /* or: stdout, stderr, ignoreErrors = true */) {
throw new ERR_CONSOLE_WRITABLE_STREAM('stderr');
}

var prop = {
const prop = {
writable: true,
enumerable: false,
configurable: true
};
prop.value = stdout;
Object.defineProperty(this, '_stdout', prop);
prop.value = stderr;
Object.defineProperty(this, '_stderr', prop);
prop.value = Boolean(ignoreErrors);
Object.defineProperty(this, '_ignoreErrors', prop);
prop.value = new Map();
Object.defineProperty(this, '_times', prop);
prop.value = createWriteErrorHandler(stdout);
Object.defineProperty(this, '_stdoutErrorHandler', prop);
prop.value = createWriteErrorHandler(stderr);
Object.defineProperty(this, '_stderrErrorHandler', prop);
Object.defineProperty(this, '_stdout', { ...prop, value: stdout });
Object.defineProperty(this, '_stderr', { ...prop, value: stderr });
Object.defineProperty(this, '_ignoreErrors', {
...prop,
value: Boolean(ignoreErrors),
});
Object.defineProperty(this, '_times', { ...prop, value: new Map() });
Object.defineProperty(this, '_stdoutErrorHandler', {
...prop,
value: createWriteErrorHandler(stdout),
});
Object.defineProperty(this, '_stderrErrorHandler', {
...prop,
value: createWriteErrorHandler(stderr),
});

if (typeof colorMode !== 'boolean' && colorMode !== 'auto')
throw new ERR_INVALID_ARG_VALUE('colorMode', colorMode);
Expand Down