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

tls: use optional chaining to simplify checks #41337

Merged
merged 1 commit into from
Jan 5, 2022
Merged
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
6 changes: 2 additions & 4 deletions lib/internal/tls/secure-context.js
Original file line number Diff line number Diff line change
Expand Up @@ -161,11 +161,9 @@ function configSecureContext(context, options = {}, name = 'options') {
for (let i = 0; i < key.length; ++i) {
const val = key[i];
const pem = (
val !== undefined && val !== null &&
val.pem !== undefined ? val.pem : val);
val?.pem !== undefined ? val.pem : val);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
val?.pem !== undefined ? val.pem : val);
val?.pem ?? val);

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What if val.pem is null?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using ?? would change the current behavior. If we want to keep this a refactoring, we can't use ??. Now, if we know that val.pem can never be null, we can make that change safely - but maybe in a separate commit?

const pass = (
val !== undefined && val !== null &&
val.passphrase !== undefined ? val.passphrase : passphrase);
val?.passphrase !== undefined ? val.passphrase : passphrase);
setKey(context, pem, pass, name);
}
} else {
Expand Down