@@ -361,31 +361,31 @@ class CryptoJob : public AsyncWrap, public ThreadPoolWork {
361361 v8::HandleScope handle_scope (env->isolate ());
362362 v8::Context::Scope context_scope (env->context ());
363363
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.
366364 v8::Local<v8::Value> exception;
367365 v8::Local<v8::Value> args[2 ];
368366 {
369367 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 ()) {
372372 CHECK (try_catch.HasCaught ());
373+ CHECK (try_catch.CanContinue ());
373374 exception = try_catch.Exception ();
374- } else if (!ret.FromJust ()) {
375- return ;
376375 }
377376 }
378377
379- if (exception.IsEmpty ()) {
380- ptr->MakeCallback (env->ondone_string (), arraysize (args), args);
381- } else {
378+ if (!exception.IsEmpty ()) {
382379 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);
383384 }
384385 }
385386
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;
389389
390390 CryptoJobMode mode () const { return mode_; }
391391
@@ -413,8 +413,9 @@ class CryptoJob : public AsyncWrap, public ThreadPoolWork {
413413 v8::Local<v8::Value> ret[2 ];
414414 env->PrintSyncTrace ();
415415 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 ());
418419 args.GetReturnValue ().Set (
419420 v8::Array::New (env->isolate (), ret, arraysize (ret)));
420421 }
@@ -504,9 +505,8 @@ class DeriveBitsJob final : public CryptoJob<DeriveBitsTraits> {
504505 success_ = true ;
505506 }
506507
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 {
510510 Environment* env = AsyncWrap::env ();
511511 CryptoErrorStore* errors = CryptoJob<DeriveBitsTraits>::errors ();
512512 if (success_) {
@@ -515,16 +515,19 @@ class DeriveBitsJob final : public CryptoJob<DeriveBitsTraits> {
515515 if (!DeriveBitsTraits::EncodeOutput (
516516 env, *CryptoJob<DeriveBitsTraits>::params (), &out_)
517517 .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 >();
519526 }
520- return v8::Just (true );
521527 }
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 ();
528531 }
529532
530533 SET_SELF_SIZE (DeriveBitsJob)
0 commit comments