@@ -89,11 +89,13 @@ void ResetHashCache(Environment* env,
8989 Isolate* isolate = env->isolate ();
9090 Local<Context> context = isolate->GetCurrentContext ();
9191 for (const auto & entry : cache->aliases ()) {
92- algorithm_cache
93- ->Set (context,
94- OneByteString (isolate, entry.first ),
95- Int32::New (isolate, -1 ))
96- .Check ();
92+ if (algorithm_cache
93+ ->Set (context,
94+ OneByteString (isolate, entry.first ),
95+ Int32::New (isolate, -1 ))
96+ .IsNothing ()) {
97+ return ;
98+ }
9799 }
98100 }
99101 cache->reset (generation);
@@ -135,6 +137,7 @@ MaybeCachedMD FetchAndMaybeCacheMD(
135137 Local<Object> algorithm_cache = Local<Object>(),
136138 const char* fetch_name = nullptr) {
137139 SynchronizeHashCache (env, algorithm_cache);
140+ if (env->isolate ()->HasPendingException ()) return {};
138141 ncrypto::DigestCache* cache = env->provider_digest_cache .get ();
139142 CHECK_NOT_NULL (cache);
140143 const uint64_t generation = env->hash_cache_generation ;
@@ -320,6 +323,7 @@ const EVP_MD* GetDigestImplementation(
320323 if (cache_id != -1 ) {
321324 // Alias already cached, return the cached EVP_MD*.
322325 if (const EVP_MD * md = GetCachedMDByID (env, cache_id, cache)) return md;
326+ if (env->isolate ()->HasPendingException ()) return nullptr ;
323327 }
324328
325329 // Only decode the algorithm when we don't have it cached to avoid
@@ -328,6 +332,7 @@ const EVP_MD* GetDigestImplementation(
328332 Utf8Value utf8 (isolate, algorithm);
329333
330334 auto result = FetchAndMaybeCacheMD (env, *utf8, cache);
335+ if (env->isolate ()->HasPendingException ()) return nullptr ;
331336 if (result.cache_id != -1 ) {
332337 // Add the alias to the JavaScript side to speed up the next lookup. The
333338 // native cache added it while inserting the implementation.
@@ -539,6 +544,7 @@ void Hash::OneShotDigest(const FunctionCallbackInfo<Value>& args) {
539544 GetCachedMDByID (env, cache_id, args[2 ].As <Object>())) {
540545 return OneShotDigestWithMD (env, args, md, nullptr );
541546 }
547+ if (env->isolate ()->HasPendingException ()) return ;
542548 }
543549#else
544550 Utf8Value utf8 (env->isolate (), args[0 ]);
@@ -554,12 +560,14 @@ void Hash::OneShotDigest(const FunctionCallbackInfo<Value>& args) {
554560 std::optional<ncrypto::Digest> digest_owner;
555561 const EVP_MD * md =
556562 GetDigestImplementation (env, args[0 ], args[1 ], args[2 ], digest_owner);
563+ if (env->isolate ()->HasPendingException ()) return ;
557564 return OneShotDigestWithMD (env, args, md, &options);
558565 }
559566
560567 std::optional<ncrypto::Digest> digest_owner;
561568 const EVP_MD * md =
562569 GetDigestImplementation (env, args[0 ], args[1 ], args[2 ], digest_owner);
570+ if (env->isolate ()->HasPendingException ()) return ;
563571 OneShotDigestWithMD (env, args, md, nullptr );
564572}
565573
@@ -627,6 +635,7 @@ void Hash::New(const FunctionCallbackInfo<Value>& args) {
627635 }
628636 return ;
629637 }
638+ if (env->isolate ()->HasPendingException ()) return ;
630639 }
631640 }
632641#endif
@@ -640,6 +649,7 @@ void Hash::New(const FunctionCallbackInfo<Value>& args) {
640649 md = orig->mdctx_ .getDigest ();
641650 } else {
642651 md = GetDigestImplementation (env, args[0 ], args[2 ], args[3 ], digest_owner);
652+ if (env->isolate ()->HasPendingException ()) return ;
643653 }
644654
645655 Hash* hash = new Hash (env, args.This ());
0 commit comments