@@ -361,31 +361,31 @@ class CryptoJob : public AsyncWrap, public ThreadPoolWork {
361
361
v8::HandleScope handle_scope (env->isolate ());
362
362
v8::Context::Scope context_scope (env->context ());
363
363
364
- // TODO(tniessen): Remove the exception handling logic here as soon as we
365
- // can verify that no code path in ToResult will ever throw an exception.
366
364
v8::Local<v8::Value> exception ;
367
365
v8::Local<v8::Value> args[2 ];
368
366
{
369
367
node::errors::TryCatchScope try_catch (env);
370
- v8::Maybe<bool > ret = ptr->ToResult (&args[0 ], &args[1 ]);
371
- if (!ret.IsJust ()) {
368
+ // If ToResult returns Nothing, then an exception should have been
369
+ // thrown and we should have caught it. Otherwise, args[0] and args[1]
370
+ // both should have been set to a value, even if the value is undefined.
371
+ if (ptr->ToResult (&args[0 ], &args[1 ]).IsNothing ()) {
372
372
CHECK (try_catch.HasCaught ());
373
+ CHECK (try_catch.CanContinue ());
373
374
exception = try_catch.Exception ();
374
- } else if (!ret.FromJust ()) {
375
- return ;
376
375
}
377
376
}
378
377
379
- if (exception .IsEmpty ()) {
380
- ptr->MakeCallback (env->ondone_string (), arraysize (args), args);
381
- } else {
378
+ if (!exception .IsEmpty ()) {
382
379
ptr->MakeCallback (env->ondone_string (), 1 , &exception );
380
+ } else {
381
+ CHECK (!args[0 ].IsEmpty ());
382
+ CHECK (!args[1 ].IsEmpty ());
383
+ ptr->MakeCallback (env->ondone_string (), arraysize (args), args);
383
384
}
384
385
}
385
386
386
- virtual v8::Maybe<bool > ToResult (
387
- v8::Local<v8::Value>* err,
388
- v8::Local<v8::Value>* result) = 0;
387
+ virtual v8::Maybe<void > ToResult (v8::Local<v8::Value>* err,
388
+ v8::Local<v8::Value>* result) = 0;
389
389
390
390
CryptoJobMode mode () const { return mode_; }
391
391
@@ -413,8 +413,9 @@ class CryptoJob : public AsyncWrap, public ThreadPoolWork {
413
413
v8::Local<v8::Value> ret[2 ];
414
414
env->PrintSyncTrace ();
415
415
job->DoThreadPoolWork ();
416
- v8::Maybe<bool > result = job->ToResult (&ret[0 ], &ret[1 ]);
417
- if (result.IsJust () && result.FromJust ()) {
416
+ if (job->ToResult (&ret[0 ], &ret[1 ]).IsJust ()) {
417
+ CHECK (!ret[0 ].IsEmpty ());
418
+ CHECK (!ret[1 ].IsEmpty ());
418
419
args.GetReturnValue ().Set (
419
420
v8::Array::New (env->isolate (), ret, arraysize (ret)));
420
421
}
@@ -504,9 +505,8 @@ class DeriveBitsJob final : public CryptoJob<DeriveBitsTraits> {
504
505
success_ = true ;
505
506
}
506
507
507
- v8::Maybe<bool > ToResult (
508
- v8::Local<v8::Value>* err,
509
- v8::Local<v8::Value>* result) override {
508
+ v8::Maybe<void > ToResult (v8::Local<v8::Value>* err,
509
+ v8::Local<v8::Value>* result) override {
510
510
Environment* env = AsyncWrap::env ();
511
511
CryptoErrorStore* errors = CryptoJob<DeriveBitsTraits>::errors ();
512
512
if (success_) {
@@ -515,16 +515,19 @@ class DeriveBitsJob final : public CryptoJob<DeriveBitsTraits> {
515
515
if (!DeriveBitsTraits::EncodeOutput (
516
516
env, *CryptoJob<DeriveBitsTraits>::params (), &out_)
517
517
.ToLocal (result)) {
518
- return v8::Nothing<bool >();
518
+ return v8::Nothing<void >();
519
+ }
520
+ } else {
521
+ if (errors->Empty ()) errors->Capture ();
522
+ CHECK (!errors->Empty ());
523
+ *result = v8::Undefined (env->isolate ());
524
+ if (!errors->ToException (env).ToLocal (err)) {
525
+ return v8::Nothing<void >();
519
526
}
520
- return v8::Just (true );
521
527
}
522
-
523
- if (errors->Empty ())
524
- errors->Capture ();
525
- CHECK (!errors->Empty ());
526
- *result = v8::Undefined (env->isolate ());
527
- return v8::Just (errors->ToException (env).ToLocal (err));
528
+ CHECK (!result->IsEmpty ());
529
+ CHECK (!err->IsEmpty ());
530
+ return v8::JustVoid ();
528
531
}
529
532
530
533
SET_SELF_SIZE (DeriveBitsJob)
0 commit comments