Skip to content

Commit 99c8c6d

Browse files
DavenportEmmajasnell
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 aec9ad8 commit 99c8c6d

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
@@ -6194,9 +6194,8 @@ bool ECDH::IsKeyPairValid() {
61946194
// TODO(addaleax): If there is an `AsyncWrap`, it currently has no access to
61956195
// this object. This makes proper reporting of memory usage impossible.
61966196
struct CryptoJob : public ThreadPoolWork {
6197-
Environment* const env;
61986197
std::unique_ptr<AsyncWrap> async_wrap;
6199-
inline explicit CryptoJob(Environment* env) : ThreadPoolWork(env), env(env) {}
6198+
inline explicit CryptoJob(Environment* env) : ThreadPoolWork(env) {}
62006199
inline void AfterThreadPoolWork(int status) final;
62016200
virtual void AfterThreadPoolWork() = 0;
62026201
static inline void Run(std::unique_ptr<CryptoJob> job, Local<Value> wrap);
@@ -6207,8 +6206,8 @@ void CryptoJob::AfterThreadPoolWork(int status) {
62076206
CHECK(status == 0 || status == UV_ECANCELED);
62086207
std::unique_ptr<CryptoJob> job(this);
62096208
if (status == UV_ECANCELED) return;
6210-
HandleScope handle_scope(env->isolate());
6211-
Context::Scope context_scope(env->context());
6209+
HandleScope handle_scope(env()->isolate());
6210+
Context::Scope context_scope(env()->context());
62126211
CHECK_EQ(false, async_wrap->persistent().IsWeak());
62136212
AfterThreadPoolWork();
62146213
}
@@ -6249,12 +6248,12 @@ struct RandomBytesJob : public CryptoJob {
62496248

62506249
inline void AfterThreadPoolWork() override {
62516250
Local<Value> arg = ToResult();
6252-
async_wrap->MakeCallback(env->ondone_string(), 1, &arg);
6251+
async_wrap->MakeCallback(env()->ondone_string(), 1, &arg);
62536252
}
62546253

62556254
inline Local<Value> ToResult() const {
6256-
if (errors.empty()) return Undefined(env->isolate());
6257-
return errors.ToException(env).ToLocalChecked();
6255+
if (errors.empty()) return Undefined(env()->isolate());
6256+
return errors.ToException(env()).ToLocalChecked();
62586257
}
62596258
};
62606259

@@ -6306,11 +6305,11 @@ struct PBKDF2Job : public CryptoJob {
63066305

63076306
inline void AfterThreadPoolWork() override {
63086307
Local<Value> arg = ToResult();
6309-
async_wrap->MakeCallback(env->ondone_string(), 1, &arg);
6308+
async_wrap->MakeCallback(env()->ondone_string(), 1, &arg);
63106309
}
63116310

63126311
inline Local<Value> ToResult() const {
6313-
return Boolean::New(env->isolate(), success.FromJust());
6312+
return Boolean::New(env()->isolate(), success.FromJust());
63146313
}
63156314

63166315
inline void Cleanse() {
@@ -6386,12 +6385,12 @@ struct ScryptJob : public CryptoJob {
63866385

63876386
inline void AfterThreadPoolWork() override {
63886387
Local<Value> arg = ToResult();
6389-
async_wrap->MakeCallback(env->ondone_string(), 1, &arg);
6388+
async_wrap->MakeCallback(env()->ondone_string(), 1, &arg);
63906389
}
63916390

63926391
inline Local<Value> ToResult() const {
6393-
if (errors.empty()) return Undefined(env->isolate());
6394-
return errors.ToException(env).ToLocalChecked();
6392+
if (errors.empty()) return Undefined(env()->isolate());
6393+
return errors.ToException(env()).ToLocalChecked();
63956394
}
63966395

63976396
inline void Cleanse() {
@@ -6720,22 +6719,22 @@ class GenerateKeyPairJob : public CryptoJob {
67206719
inline void AfterThreadPoolWork() override {
67216720
Local<Value> args[3];
67226721
ToResult(&args[0], &args[1], &args[2]);
6723-
async_wrap->MakeCallback(env->ondone_string(), 3, args);
6722+
async_wrap->MakeCallback(env()->ondone_string(), 3, args);
67246723
}
67256724

67266725
inline void ToResult(Local<Value>* err,
67276726
Local<Value>* pubkey,
67286727
Local<Value>* privkey) {
67296728
if (pkey_ && EncodeKeys(pubkey, privkey)) {
67306729
CHECK(errors_.empty());
6731-
*err = Undefined(env->isolate());
6730+
*err = Undefined(env()->isolate());
67326731
} else {
67336732
if (errors_.empty())
67346733
errors_.Capture();
67356734
CHECK(!errors_.empty());
6736-
*err = errors_.ToException(env).ToLocalChecked();
6737-
*pubkey = Undefined(env->isolate());
6738-
*privkey = Undefined(env->isolate());
6735+
*err = errors_.ToException(env()).ToLocalChecked();
6736+
*pubkey = Undefined(env()->isolate());
6737+
*privkey = Undefined(env()->isolate());
67396738
}
67406739
}
67416740

@@ -6744,20 +6743,21 @@ class GenerateKeyPairJob : public CryptoJob {
67446743
if (public_key_encoding_.output_key_object_) {
67456744
// Note that this has the downside of containing sensitive data of the
67466745
// private key.
6747-
if (!KeyObject::Create(env, kKeyTypePublic, pkey_).ToLocal(pubkey))
6746+
if (!KeyObject::Create(env(), kKeyTypePublic, pkey_).ToLocal(pubkey))
67486747
return false;
67496748
} else {
6750-
if (!WritePublicKey(env, pkey_.get(), public_key_encoding_)
6749+
if (!WritePublicKey(env(), pkey_.get(), public_key_encoding_)
67516750
.ToLocal(pubkey))
67526751
return false;
67536752
}
67546753

67556754
// Now do the same for the private key.
67566755
if (private_key_encoding_.output_key_object_) {
6757-
if (!KeyObject::Create(env, kKeyTypePrivate, pkey_).ToLocal(privkey))
6756+
if (!KeyObject::Create(env(), kKeyTypePrivate, pkey_)
6757+
.ToLocal(privkey))
67586758
return false;
67596759
} else {
6760-
if (!WritePrivateKey(env, pkey_.get(), private_key_encoding_)
6760+
if (!WritePrivateKey(env(), pkey_.get(), private_key_encoding_)
67616761
.ToLocal(privkey))
67626762
return false;
67636763
}

src/node_internals.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -268,6 +268,8 @@ class ThreadPoolWork {
268268
virtual void DoThreadPoolWork() = 0;
269269
virtual void AfterThreadPoolWork(int status) = 0;
270270

271+
Environment* env() const { return env_; }
272+
271273
private:
272274
Environment* env_;
273275
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
void EmitError(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
void InitStream(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
struct AllocScope {

0 commit comments

Comments
 (0)