Skip to content

Commit 79a6872

Browse files
DavenportEmmacodebytere
authored andcommitted
src: remove duplicate field env in CryptoJob class
Removed field env from cryptojob class, replaced with function env() inherited from ThreadPoolWork PR-URL: #31554 Reviewed-By: James M Snell <[email protected]> Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: Benjamin Gruenbaum <[email protected]> Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: David Carlier <[email protected]> Reviewed-By: Rich Trott <[email protected]> Reviewed-By: Tobias Nießen <[email protected]>
1 parent 5e19c4a commit 79a6872

File tree

3 files changed

+37
-33
lines changed

3 files changed

+37
-33
lines changed

‎src/node_crypto.cc‎

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -6192,9 +6192,8 @@ bool ECDH::IsKeyPairValid(){
61926192
// TODO(addaleax): If there is an `AsyncWrap`, it currently has no access to
61936193
// this object. This makes proper reporting of memory usage impossible.
61946194
structCryptoJob : publicThreadPoolWork{
6195-
Environment* const env;
61966195
std::unique_ptr<AsyncWrap> async_wrap;
6197-
inlineexplicitCryptoJob(Environment* env) : ThreadPoolWork(env), env(env){}
6196+
inlineexplicitCryptoJob(Environment* env) : ThreadPoolWork(env){}
61986197
inlinevoidAfterThreadPoolWork(int status) final;
61996198
virtualvoidAfterThreadPoolWork() = 0;
62006199
staticinlinevoidRun(std::unique_ptr<CryptoJob> job, Local<Value> wrap);
@@ -6205,8 +6204,8 @@ void CryptoJob::AfterThreadPoolWork(int status){
62056204
CHECK(status == 0 || status == UV_ECANCELED);
62066205
std::unique_ptr<CryptoJob> job(this);
62076206
if (status == UV_ECANCELED) return;
6208-
HandleScope handle_scope(env->isolate());
6209-
Context::Scope context_scope(env->context());
6207+
HandleScope handle_scope(env()->isolate());
6208+
Context::Scope context_scope(env()->context());
62106209
CHECK_EQ(false, async_wrap->persistent().IsWeak());
62116210
AfterThreadPoolWork();
62126211
}
@@ -6247,12 +6246,12 @@ struct RandomBytesJob : public CryptoJob{
62476246

62486247
inlinevoidAfterThreadPoolWork() override{
62496248
Local<Value> arg = ToResult();
6250-
async_wrap->MakeCallback(env->ondone_string(), 1, &arg);
6249+
async_wrap->MakeCallback(env()->ondone_string(), 1, &arg);
62516250
}
62526251

62536252
inline Local<Value> ToResult() const{
6254-
if (errors.empty()) returnUndefined(env->isolate());
6255-
return errors.ToException(env).ToLocalChecked();
6253+
if (errors.empty()) returnUndefined(env()->isolate());
6254+
return errors.ToException(env()).ToLocalChecked();
62566255
}
62576256
};
62586257

@@ -6304,11 +6303,11 @@ struct PBKDF2Job : public CryptoJob{
63046303

63056304
inlinevoidAfterThreadPoolWork() override{
63066305
Local<Value> arg = ToResult();
6307-
async_wrap->MakeCallback(env->ondone_string(), 1, &arg);
6306+
async_wrap->MakeCallback(env()->ondone_string(), 1, &arg);
63086307
}
63096308

63106309
inline Local<Value> ToResult() const{
6311-
returnBoolean::New(env->isolate(), success.FromJust());
6310+
returnBoolean::New(env()->isolate(), success.FromJust());
63126311
}
63136312

63146313
inlinevoidCleanse(){
@@ -6384,12 +6383,12 @@ struct ScryptJob : public CryptoJob{
63846383

63856384
inlinevoidAfterThreadPoolWork() override{
63866385
Local<Value> arg = ToResult();
6387-
async_wrap->MakeCallback(env->ondone_string(), 1, &arg);
6386+
async_wrap->MakeCallback(env()->ondone_string(), 1, &arg);
63886387
}
63896388

63906389
inline Local<Value> ToResult() const{
6391-
if (errors.empty()) returnUndefined(env->isolate());
6392-
return errors.ToException(env).ToLocalChecked();
6390+
if (errors.empty()) returnUndefined(env()->isolate());
6391+
return errors.ToException(env()).ToLocalChecked();
63936392
}
63946393

63956394
inlinevoidCleanse(){
@@ -6653,22 +6652,22 @@ class GenerateKeyPairJob : public CryptoJob{
66536652
inlinevoidAfterThreadPoolWork() override{
66546653
Local<Value> args[3];
66556654
ToResult(&args[0], &args[1], &args[2]);
6656-
async_wrap->MakeCallback(env->ondone_string(), 3, args);
6655+
async_wrap->MakeCallback(env()->ondone_string(), 3, args);
66576656
}
66586657

66596658
inlinevoidToResult(Local<Value>* err,
66606659
Local<Value>* pubkey,
66616660
Local<Value>* privkey){
66626661
if (pkey_ && EncodeKeys(pubkey, privkey)){
66636662
CHECK(errors_.empty());
6664-
*err = Undefined(env->isolate());
6663+
*err = Undefined(env()->isolate());
66656664
} else{
66666665
if (errors_.empty())
66676666
errors_.Capture();
66686667
CHECK(!errors_.empty());
6669-
*err = errors_.ToException(env).ToLocalChecked();
6670-
*pubkey = Undefined(env->isolate());
6671-
*privkey = Undefined(env->isolate());
6668+
*err = errors_.ToException(env()).ToLocalChecked();
6669+
*pubkey = Undefined(env()->isolate());
6670+
*privkey = Undefined(env()->isolate());
66726671
}
66736672
}
66746673

@@ -6677,20 +6676,21 @@ class GenerateKeyPairJob : public CryptoJob{
66776676
if (public_key_encoding_.output_key_object_){
66786677
// Note that this has the downside of containing sensitive data of the
66796678
// private key.
6680-
if (!KeyObject::Create(env, kKeyTypePublic, pkey_).ToLocal(pubkey))
6679+
if (!KeyObject::Create(env(), kKeyTypePublic, pkey_).ToLocal(pubkey))
66816680
returnfalse;
66826681
} else{
6683-
if (!WritePublicKey(env, pkey_.get(), public_key_encoding_)
6682+
if (!WritePublicKey(env(), pkey_.get(), public_key_encoding_)
66846683
.ToLocal(pubkey))
66856684
returnfalse;
66866685
}
66876686

66886687
// Now do the same for the private key.
66896688
if (private_key_encoding_.output_key_object_){
6690-
if (!KeyObject::Create(env, kKeyTypePrivate, pkey_).ToLocal(privkey))
6689+
if (!KeyObject::Create(env(), kKeyTypePrivate, pkey_)
6690+
.ToLocal(privkey))
66916691
returnfalse;
66926692
} else{
6693-
if (!WritePrivateKey(env, pkey_.get(), private_key_encoding_)
6693+
if (!WritePrivateKey(env(), pkey_.get(), private_key_encoding_)
66946694
.ToLocal(privkey))
66956695
returnfalse;
66966696
}

‎src/node_internals.h‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -267,6 +267,8 @@ class ThreadPoolWork{
267267
virtualvoidDoThreadPoolWork() = 0;
268268
virtualvoidAfterThreadPoolWork(int status) = 0;
269269

270+
Environment* env() const{return env_}
271+
270272
private:
271273
Environment* env_;
272274
uv_work_t work_req_;

‎src/node_zlib.cc‎

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -348,7 +348,7 @@ class CompressionStream : public AsyncWrap, public ThreadPoolWork{
348348

349349
if (!async){
350350
// sync version
351-
env()->PrintSyncTrace();
351+
AsyncWrap::env()->PrintSyncTrace();
352352
DoThreadPoolWork();
353353
if (CheckError()){
354354
UpdateWriteResult();
@@ -397,16 +397,17 @@ class CompressionStream : public AsyncWrap, public ThreadPoolWork{
397397

398398
CHECK_EQ(status, 0);
399399

400-
HandleScope handle_scope(env()->isolate());
401-
Context::Scope context_scope(env()->context());
400+
Environment* env = AsyncWrap::env();
401+
HandleScope handle_scope(env->isolate());
402+
Context::Scope context_scope(env->context());
402403

403404
if (!CheckError())
404405
return;
405406

406407
UpdateWriteResult();
407408

408409
// call the write() cb
409-
Local<Function> cb = PersistentToLocal::Default(env()->isolate(),
410+
Local<Function> cb = PersistentToLocal::Default(env->isolate(),
410411
write_js_callback_);
411412
MakeCallback(cb, 0, nullptr);
412413

@@ -416,16 +417,17 @@ class CompressionStream : public AsyncWrap, public ThreadPoolWork{
416417

417418
// TODO(addaleax): Switch to modern error system (node_errors.h).
418419
voidEmitError(const CompressionError& err){
420+
Environment* env = AsyncWrap::env();
419421
// If you hit this assertion, you forgot to enter the v8::Context first.
420-
CHECK_EQ(env()->context(), env()->isolate()->GetCurrentContext());
422+
CHECK_EQ(env->context(), env->isolate()->GetCurrentContext());
421423

422-
HandleScope scope(env()->isolate());
424+
HandleScope scope(env->isolate());
423425
Local<Value> args[3] ={
424-
OneByteString(env()->isolate(), err.message),
425-
Integer::New(env()->isolate(), err.err),
426-
OneByteString(env()->isolate(), err.code)
426+
OneByteString(env->isolate(), err.message),
427+
Integer::New(env->isolate(), err.err),
428+
OneByteString(env->isolate(), err.code)
427429
};
428-
MakeCallback(env()->onerror_string(), arraysize(args), args);
430+
MakeCallback(env->onerror_string(), arraysize(args), args);
429431

430432
// no hope of rescue.
431433
write_in_progress_ = false;
@@ -454,7 +456,7 @@ class CompressionStream : public AsyncWrap, public ThreadPoolWork{
454456

455457
voidInitStream(uint32_t* write_result, Local<Function> write_js_callback){
456458
write_result_ = write_result;
457-
write_js_callback_.Reset(env()->isolate(), write_js_callback);
459+
write_js_callback_.Reset(AsyncWrap::env()->isolate(), write_js_callback);
458460
init_done_ = true;
459461
}
460462

@@ -500,7 +502,7 @@ class CompressionStream : public AsyncWrap, public ThreadPoolWork{
500502
if (report == 0) return;
501503
CHECK_IMPLIES(report < 0, zlib_memory_ >= static_cast<size_t>(-report));
502504
zlib_memory_ += report;
503-
env()->isolate()->AdjustAmountOfExternalAllocatedMemory(report);
505+
AsyncWrap::env()->isolate()->AdjustAmountOfExternalAllocatedMemory(report);
504506
}
505507

506508
structAllocScope{

0 commit comments

Comments
(0)