diff --git a/src/node_crypto.cc b/src/node_crypto.cc
index e129c7f3f595ae..2c3fd3c802fa09 100644
--- a/src/node_crypto.cc
+++ b/src/node_crypto.cc
@@ -2789,14 +2789,10 @@ void SSLWrap::ExportKeyingMaterial(
AllocatedBuffer out = env->AllocateManaged(olen);
- ByteSource key;
-
- int useContext = 0;
- if (!args[2]->IsNull() && Buffer::HasInstance(args[2])) {
- key = ByteSource::FromBuffer(args[2]);
-
- useContext = 1;
- }
+ ByteSource context;
+ bool use_context = !args[2]->IsUndefined();
+ if (use_context)
+ context = ByteSource::FromBuffer(args[2]);
if (SSL_export_keying_material(w->ssl_.get(),
reinterpret_cast(out.data()),
@@ -2804,9 +2800,9 @@ void SSLWrap::ExportKeyingMaterial(
*label,
label.length(),
reinterpret_cast(
- key.get()),
- key.size(),
- useContext) != 1) {
+ context.get()),
+ context.size(),
+ use_context) != 1) {
return ThrowCryptoError(env, ERR_get_error(), "SSL_export_keying_material");
}