Skip to content

Commit aa6a494

Browse files
committed
src: convert more Maybe<bool> to Maybe<void>
1 parent 69a5082 commit aa6a494

File tree

5 files changed

+70
-59
lines changed

5 files changed

+70
-59
lines changed

src/crypto/crypto_cipher.h

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -249,9 +249,8 @@ class CipherJob final : public CryptoJob<CipherTraits> {
249249
}
250250
}
251251

252-
v8::Maybe<bool> ToResult(
253-
v8::Local<v8::Value>* err,
254-
v8::Local<v8::Value>* result) override {
252+
v8::Maybe<void> ToResult(v8::Local<v8::Value>* err,
253+
v8::Local<v8::Value>* result) override {
255254
Environment* env = AsyncWrap::env();
256255
CryptoErrorStore* errors = CryptoJob<CipherTraits>::errors();
257256

@@ -262,11 +261,18 @@ class CipherJob final : public CryptoJob<CipherTraits> {
262261
CHECK(errors->Empty());
263262
*err = v8::Undefined(env->isolate());
264263
*result = out_.ToArrayBuffer(env);
265-
return v8::Just(!result->IsEmpty());
264+
if (result->IsEmpty()) {
265+
return v8::Nothing<void>();
266+
}
267+
} else {
268+
*result = v8::Undefined(env->isolate());
269+
if (!errors->ToException(env).ToLocal(err)) {
270+
return v8::Nothing<void>();
271+
}
266272
}
267-
268-
*result = v8::Undefined(env->isolate());
269-
return v8::Just(errors->ToException(env).ToLocal(err));
273+
CHECK(!result->IsEmpty());
274+
CHECK(!err->IsEmpty());
275+
return v8::JustVoid();
270276
}
271277

272278
SET_SELF_SIZE(CipherJob)

src/crypto/crypto_keygen.cc

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ namespace node {
1414

1515
using v8::FunctionCallbackInfo;
1616
using v8::Int32;
17-
using v8::Just;
1817
using v8::JustVoid;
1918
using v8::Local;
2019
using v8::Maybe;
@@ -81,7 +80,7 @@ KeyGenJobStatus SecretKeyGenTraits::DoKeyGen(Environment* env,
8180
}
8281

8382
MaybeLocal<Value> SecretKeyGenTraits::EncodeKey(Environment* env,
84-
SecretKeyGenConfig* params) {
83+
SecretKeyGenConfig* params) {
8584
std::shared_ptr<KeyObjectData> data =
8685
KeyObjectData::CreateSecret(std::move(params->out));
8786
Local<Value> ret;

src/crypto/crypto_keygen.h

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -91,9 +91,8 @@ class KeyGenJob final : public CryptoJob<KeyGenTraits> {
9191
}
9292
}
9393

94-
v8::Maybe<bool> ToResult(
95-
v8::Local<v8::Value>* err,
96-
v8::Local<v8::Value>* result) override {
94+
v8::Maybe<void> ToResult(v8::Local<v8::Value>* err,
95+
v8::Local<v8::Value>* result) override {
9796
Environment* env = AsyncWrap::env();
9897
CryptoErrorStore* errors = CryptoJob<KeyGenTraits>::errors();
9998
AdditionalParams* params = CryptoJob<KeyGenTraits>::params();
@@ -108,14 +107,17 @@ class KeyGenJob final : public CryptoJob<KeyGenTraits> {
108107
*result = Undefined(env->isolate());
109108
*err = try_catch.Exception();
110109
}
111-
return v8::Just(true);
110+
} else {
111+
if (errors->Empty()) errors->Capture();
112+
CHECK(!errors->Empty());
113+
*result = Undefined(env->isolate());
114+
if (!errors->ToException(env).ToLocal(err)) {
115+
return v8::Nothing<void>();
116+
}
112117
}
113-
114-
if (errors->Empty())
115-
errors->Capture();
116-
CHECK(!errors->Empty());
117-
*result = Undefined(env->isolate());
118-
return v8::Just(errors->ToException(env).ToLocal(err));
118+
CHECK(!result->IsEmpty());
119+
CHECK(!err->IsEmpty());
120+
return v8::JustVoid();
119121
}
120122

121123
SET_SELF_SIZE(KeyGenJob)
@@ -183,9 +185,8 @@ struct KeyPairGenTraits final {
183185
return KeyGenJobStatus::OK;
184186
}
185187

186-
static v8::MaybeLocal<v8::Value> EncodeKey(
187-
Environment* env,
188-
AdditionalParameters* params) {
188+
static v8::MaybeLocal<v8::Value> EncodeKey(Environment* env,
189+
AdditionalParameters* params) {
189190
v8::Local<v8::Value> keys[2];
190191
if (params->key
191192
.ToEncodedPublicKey(env, params->public_key_encoding, &keys[0])
@@ -224,9 +225,8 @@ struct SecretKeyGenTraits final {
224225
Environment* env,
225226
SecretKeyGenConfig* params);
226227

227-
static v8::MaybeLocal<v8::Value> EncodeKey(
228-
Environment* env,
229-
SecretKeyGenConfig* params);
228+
static v8::MaybeLocal<v8::Value> EncodeKey(Environment* env,
229+
SecretKeyGenConfig* params);
230230
};
231231

232232
template <typename AlgorithmParams>

src/crypto/crypto_keys.h

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -369,23 +369,28 @@ class KeyExportJob final : public CryptoJob<KeyExportTraits> {
369369
}
370370
}
371371

372-
v8::Maybe<bool> ToResult(
373-
v8::Local<v8::Value>* err,
374-
v8::Local<v8::Value>* result) override {
372+
v8::Maybe<void> ToResult(v8::Local<v8::Value>* err,
373+
v8::Local<v8::Value>* result) override {
375374
Environment* env = AsyncWrap::env();
376375
CryptoErrorStore* errors = CryptoJob<KeyExportTraits>::errors();
377376
if (out_.size() > 0) {
378377
CHECK(errors->Empty());
379378
*err = v8::Undefined(env->isolate());
380379
*result = out_.ToArrayBuffer(env);
381-
return v8::Just(!result->IsEmpty());
380+
if (result->IsEmpty()) {
381+
return v8::Nothing<void>();
382+
}
383+
} else {
384+
if (errors->Empty()) errors->Capture();
385+
CHECK(!errors->Empty());
386+
*result = v8::Undefined(env->isolate());
387+
if (!errors->ToException(env).ToLocal(err)) {
388+
return v8::Nothing<void>();
389+
}
382390
}
383-
384-
if (errors->Empty())
385-
errors->Capture();
386-
CHECK(!errors->Empty());
387-
*result = v8::Undefined(env->isolate());
388-
return v8::Just(errors->ToException(env).ToLocal(err));
391+
CHECK(!result->IsEmpty());
392+
CHECK(!err->IsEmpty());
393+
return v8::JustVoid();
389394
}
390395

391396
SET_SELF_SIZE(KeyExportJob)

src/crypto/crypto_util.h

Lines changed: 25 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -367,25 +367,23 @@ class CryptoJob : public AsyncWrap, public ThreadPoolWork {
367367
v8::Local<v8::Value> args[2];
368368
{
369369
node::errors::TryCatchScope try_catch(env);
370-
v8::Maybe<bool> ret = ptr->ToResult(&args[0], &args[1]);
371-
if (!ret.IsJust()) {
370+
if (ptr->ToResult(&args[0], &args[1]).IsNothing()) {
372371
CHECK(try_catch.HasCaught());
372+
CHECK(try_catch.CanContinue());
373373
exception = try_catch.Exception();
374-
} else if (!ret.FromJust()) {
374+
ptr->MakeCallback(env->ondone_string(), 1, &exception);
375375
return;
376376
}
377377
}
378378

379-
if (exception.IsEmpty()) {
380-
ptr->MakeCallback(env->ondone_string(), arraysize(args), args);
381-
} else {
382-
ptr->MakeCallback(env->ondone_string(), 1, &exception);
383-
}
379+
CHECK(!args[0].IsEmpty());
380+
CHECK(!args[1].IsEmpty());
381+
382+
ptr->MakeCallback(env->ondone_string(), arraysize(args), args);
384383
}
385384

386-
virtual v8::Maybe<bool> ToResult(
387-
v8::Local<v8::Value>* err,
388-
v8::Local<v8::Value>* result) = 0;
385+
virtual v8::Maybe<void> ToResult(v8::Local<v8::Value>* err,
386+
v8::Local<v8::Value>* result) = 0;
389387

390388
CryptoJobMode mode() const { return mode_; }
391389

@@ -413,8 +411,9 @@ class CryptoJob : public AsyncWrap, public ThreadPoolWork {
413411
v8::Local<v8::Value> ret[2];
414412
env->PrintSyncTrace();
415413
job->DoThreadPoolWork();
416-
v8::Maybe<bool> result = job->ToResult(&ret[0], &ret[1]);
417-
if (result.IsJust() && result.FromJust()) {
414+
if (job->ToResult(&ret[0], &ret[1]).IsJust()) {
415+
CHECK(!ret[0].IsEmpty());
416+
CHECK(!ret[1].IsEmpty());
418417
args.GetReturnValue().Set(
419418
v8::Array::New(env->isolate(), ret, arraysize(ret)));
420419
}
@@ -504,9 +503,8 @@ class DeriveBitsJob final : public CryptoJob<DeriveBitsTraits> {
504503
success_ = true;
505504
}
506505

507-
v8::Maybe<bool> ToResult(
508-
v8::Local<v8::Value>* err,
509-
v8::Local<v8::Value>* result) override {
506+
v8::Maybe<void> ToResult(v8::Local<v8::Value>* err,
507+
v8::Local<v8::Value>* result) override {
510508
Environment* env = AsyncWrap::env();
511509
CryptoErrorStore* errors = CryptoJob<DeriveBitsTraits>::errors();
512510
if (success_) {
@@ -515,16 +513,19 @@ class DeriveBitsJob final : public CryptoJob<DeriveBitsTraits> {
515513
if (!DeriveBitsTraits::EncodeOutput(
516514
env, *CryptoJob<DeriveBitsTraits>::params(), &out_)
517515
.ToLocal(result)) {
518-
return v8::Nothing<bool>();
516+
return v8::Nothing<void>();
517+
}
518+
} else {
519+
if (errors->Empty()) errors->Capture();
520+
CHECK(!errors->Empty());
521+
*result = v8::Undefined(env->isolate());
522+
if (!errors->ToException(env).ToLocal(err)) {
523+
return v8::Nothing<void>();
519524
}
520-
return v8::Just(true);
521525
}
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));
526+
CHECK(!result->IsEmpty());
527+
CHECK(!err->IsEmpty());
528+
return v8::JustVoid();
528529
}
529530

530531
SET_SELF_SIZE(DeriveBitsJob)

0 commit comments

Comments
 (0)