@@ -226,9 +226,9 @@ static int NoPasswordCallback(char* buf, int size, int rwflag, void* u) {
226
226
227
227
// namespace node::crypto::error
228
228
namespace error {
229
- void Decorate (Environment* env, Local<Object> obj,
229
+ Maybe< bool > Decorate (Environment* env, Local<Object> obj,
230
230
unsigned long err) { // NOLINT(runtime/int)
231
- if (err == 0 ) return ; // No decoration possible .
231
+ if (err == 0 ) return Just ( true ) ; // No decoration necessary .
232
232
233
233
const char * ls = ERR_lib_error_string (err);
234
234
const char * fs = ERR_func_error_string (err);
@@ -240,19 +240,19 @@ void Decorate(Environment* env, Local<Object> obj,
240
240
if (ls != nullptr ) {
241
241
if (obj->Set (context, env->library_string (),
242
242
OneByteString (isolate, ls)).IsNothing ()) {
243
- return ;
243
+ return Nothing< bool >() ;
244
244
}
245
245
}
246
246
if (fs != nullptr ) {
247
247
if (obj->Set (context, env->function_string (),
248
248
OneByteString (isolate, fs)).IsNothing ()) {
249
- return ;
249
+ return Nothing< bool >() ;
250
250
}
251
251
}
252
252
if (rs != nullptr ) {
253
253
if (obj->Set (context, env->reason_string (),
254
254
OneByteString (isolate, rs)).IsNothing ()) {
255
- return ;
255
+ return Nothing< bool >() ;
256
256
}
257
257
258
258
// SSL has no API to recover the error name from the number, so we
@@ -325,8 +325,10 @@ void Decorate(Environment* env, Local<Object> obj,
325
325
if (obj->Set (env->isolate ()->GetCurrentContext (),
326
326
env->code_string (),
327
327
OneByteString (env->isolate (), code)).IsNothing ())
328
- return ;
328
+ return Nothing< bool >() ;
329
329
}
330
+
331
+ return Just (true );
330
332
}
331
333
} // namespace error
332
334
@@ -342,7 +344,7 @@ struct CryptoErrorVector : public std::vector<std::string> {
342
344
std::reverse (begin (), end ());
343
345
}
344
346
345
- inline Local <Value> ToException (
347
+ inline MaybeLocal <Value> ToException (
346
348
Environment* env,
347
349
Local<String> exception_string = Local<String>()) const {
348
350
if (exception_string.IsEmpty ()) {
@@ -364,10 +366,11 @@ struct CryptoErrorVector : public std::vector<std::string> {
364
366
if (!empty ()) {
365
367
CHECK (exception_v->IsObject ());
366
368
Local<Object> exception = exception_v.As <Object>();
367
- exception ->Set (env->context (),
369
+ Maybe< bool > ok = exception ->Set (env->context (),
368
370
env->openssl_error_stack (),
369
- ToV8Value (env->context (), *this ).ToLocalChecked ())
370
- .Check ();
371
+ ToV8Value (env->context (), *this ).ToLocalChecked ());
372
+ if (ok.IsNothing ())
373
+ return MaybeLocal<Value>();
371
374
}
372
375
373
376
return exception_v;
@@ -386,16 +389,19 @@ void ThrowCryptoError(Environment* env,
386
389
message = message_buffer;
387
390
}
388
391
HandleScope scope (env->isolate ());
389
- auto exception_string =
392
+ Local<String> exception_string =
390
393
String::NewFromUtf8 (env->isolate (), message, NewStringType::kNormal )
391
394
.ToLocalChecked ();
392
395
CryptoErrorVector errors;
393
396
errors.Capture ();
394
- Local<Value> exception = errors.ToException (env, exception_string);
397
+ Local<Value> exception ;
398
+ if (!errors.ToException (env, exception_string).ToLocal (&exception ))
399
+ return ;
395
400
Local<Object> obj;
396
401
if (!exception ->ToObject (env->context ()).ToLocal (&obj))
397
402
return ;
398
- error::Decorate (env, obj, err);
403
+ if (error::Decorate (env, obj, err).IsNothing ())
404
+ return ;
399
405
env->isolate ()->ThrowException (exception );
400
406
}
401
407
@@ -5872,7 +5878,7 @@ struct RandomBytesJob : public CryptoJob {
5872
5878
5873
5879
inline Local<Value> ToResult () const {
5874
5880
if (errors.empty ()) return Undefined (env->isolate ());
5875
- return errors.ToException (env);
5881
+ return errors.ToException (env). ToLocalChecked () ;
5876
5882
}
5877
5883
};
5878
5884
@@ -6009,7 +6015,7 @@ struct ScryptJob : public CryptoJob {
6009
6015
6010
6016
inline Local<Value> ToResult () const {
6011
6017
if (errors.empty ()) return Undefined (env->isolate ());
6012
- return errors.ToException (env);
6018
+ return errors.ToException (env). ToLocalChecked () ;
6013
6019
}
6014
6020
6015
6021
inline void Cleanse () {
@@ -6285,7 +6291,7 @@ class GenerateKeyPairJob : public CryptoJob {
6285
6291
if (errors_.empty ())
6286
6292
errors_.Capture ();
6287
6293
CHECK (!errors_.empty ());
6288
- *err = errors_.ToException (env);
6294
+ *err = errors_.ToException (env). ToLocalChecked () ;
6289
6295
*pubkey = Undefined (env->isolate ());
6290
6296
*privkey = Undefined (env->isolate ());
6291
6297
}
0 commit comments