src: remove unnecessary `Environment::GetCurrent()` calls · nodejs/node@8e182e5 · GitHub
Skip to content

Commit 8e182e5

Browse files
iknoomaduh95
authored andcommitted
src: remove unnecessary Environment::GetCurrent() calls
PR-URL: #59814 Reviewed-By: Chengzhong Wu <legendecas@gmail.com> Reviewed-By: Gerhard Stöbich <deb2001-github@yahoo.de>
1 parent 4bc366f commit 8e182e5

16 files changed

Lines changed: 32 additions & 60 deletions

src/cares_wrap.cc

Lines changed: 1 addition & 3 deletions

src/crypto/crypto_keys.cc

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -799,12 +799,11 @@ int GetOKPCurveFromName(const char* name) {
799799
}
800800

801801
void KeyObjectHandle::InitEDRaw(const FunctionCallbackInfo<Value>& args) {
802-
Environment* env = Environment::GetCurrent(args);
803802
KeyObjectHandle* key;
804803
ASSIGN_OR_RETURN_UNWRAP(&key, args.This());
805804

806805
CHECK(args[0]->IsString());
807-
Utf8Value name(env->isolate(), args[0]);
806+
Utf8Value name(args.GetIsolate(), args[0]);
808807

809808
ArrayBufferOrViewContents<unsigned char> key_data(args[1]);
810809
KeyType type = FromV8Value<KeyType>(args[2]);

src/crypto/crypto_tls.cc

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1357,8 +1357,6 @@ void TLSWrap::EnableALPNCb(const FunctionCallbackInfo<Value>& args) {
13571357
}
13581358

13591359
void TLSWrap::GetServername(const FunctionCallbackInfo<Value>& args) {
1360-
Environment* env = Environment::GetCurrent(args);
1361-
13621360
TLSWrap* wrap;
13631361
ASSIGN_OR_RETURN_UNWRAP(&wrap, args.This());
13641362

@@ -1368,15 +1366,13 @@ void TLSWrap::GetServername(const FunctionCallbackInfo<Value>& args) {
13681366
if (servername.has_value()) {
13691367
auto& sn = servername.value();
13701368
args.GetReturnValue().Set(
1371-
OneByteString(env->isolate(), sn.data(), sn.length()));
1369+
OneByteString(args.GetIsolate(), sn.data(), sn.length()));
13721370
} else {
13731371
args.GetReturnValue().Set(false);
13741372
}
13751373
}
13761374

13771375
void TLSWrap::SetServername(const FunctionCallbackInfo<Value>& args) {
1378-
Environment* env = Environment::GetCurrent(args);
1379-
13801376
TLSWrap* wrap;
13811377
ASSIGN_OR_RETURN_UNWRAP(&wrap, args.This());
13821378

@@ -1387,7 +1383,7 @@ void TLSWrap::SetServername(const FunctionCallbackInfo<Value>& args) {
13871383

13881384
CHECK(wrap->ssl_);
13891385

1390-
Utf8Value servername(env->isolate(), args[0].As<String>());
1386+
Utf8Value servername(args.GetIsolate(), args[0].As<String>());
13911387
SSL_set_tlsext_host_name(wrap->ssl_.get(), *servername);
13921388
}
13931389

@@ -2109,11 +2105,10 @@ void TLSWrap::GetEphemeralKeyInfo(const FunctionCallbackInfo<Value>& args) {
21092105
}
21102106

21112107
void TLSWrap::GetProtocol(const FunctionCallbackInfo<Value>& args) {
2112-
Environment* env = Environment::GetCurrent(args);
21132108
TLSWrap* w;
21142109
ASSIGN_OR_RETURN_UNWRAP(&w, args.This());
21152110
args.GetReturnValue().Set(
2116-
OneByteString(env->isolate(), SSL_get_version(w->ssl_.get())));
2111+
OneByteString(args.GetIsolate(), SSL_get_version(w->ssl_.get())));
21172112
}
21182113

21192114
void TLSWrap::GetALPNNegotiatedProto(const FunctionCallbackInfo<Value>& args) {

src/crypto/crypto_util.cc

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -705,10 +705,9 @@ void SecureBuffer(const FunctionCallbackInfo<Value>& args) {
705705
}
706706

707707
void SecureHeapUsed(const FunctionCallbackInfo<Value>& args) {
708-
Environment* env = Environment::GetCurrent(args);
709708
if (CRYPTO_secure_malloc_initialized())
710709
args.GetReturnValue().Set(
711-
BigInt::New(env->isolate(), CRYPTO_secure_used()));
710+
BigInt::New(args.GetIsolate(), CRYPTO_secure_used()));
712711
}
713712
} // namespace
714713

src/histogram.cc

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -453,10 +453,9 @@ void HistogramImpl::GetCount(const FunctionCallbackInfo<Value>& args) {
453453
}
454454

455455
void HistogramImpl::GetCountBigInt(const FunctionCallbackInfo<Value>& args) {
456-
Environment* env = Environment::GetCurrent(args);
457456
HistogramImpl* histogram = HistogramImpl::FromJSObject(args.This());
458457
args.GetReturnValue().Set(
459-
BigInt::NewFromUnsigned(env->isolate(), (*histogram)->Count()));
458+
BigInt::NewFromUnsigned(args.GetIsolate(), (*histogram)->Count()));
460459
}
461460

462461
void HistogramImpl::GetMin(const FunctionCallbackInfo<Value>& args) {
@@ -466,9 +465,9 @@ void HistogramImpl::GetMin(const FunctionCallbackInfo<Value>& args) {
466465
}
467466

468467
void HistogramImpl::GetMinBigInt(const FunctionCallbackInfo<Value>& args) {
469-
Environment* env = Environment::GetCurrent(args);
470468
HistogramImpl* histogram = HistogramImpl::FromJSObject(args.This());
471-
args.GetReturnValue().Set(BigInt::New(env->isolate(), (*histogram)->Min()));
469+
args.GetReturnValue().Set(
470+
BigInt::New(args.GetIsolate(), (*histogram)->Min()));
472471
}
473472

474473
void HistogramImpl::GetMax(const FunctionCallbackInfo<Value>& args) {
@@ -478,9 +477,9 @@ void HistogramImpl::GetMax(const FunctionCallbackInfo<Value>& args) {
478477
}
479478

480479
void HistogramImpl::GetMaxBigInt(const FunctionCallbackInfo<Value>& args) {
481-
Environment* env = Environment::GetCurrent(args);
482480
HistogramImpl* histogram = HistogramImpl::FromJSObject(args.This());
483-
args.GetReturnValue().Set(BigInt::New(env->isolate(), (*histogram)->Max()));
481+
args.GetReturnValue().Set(
482+
BigInt::New(args.GetIsolate(), (*histogram)->Max()));
484483
}
485484

486485
void HistogramImpl::GetMean(const FunctionCallbackInfo<Value>& args) {
@@ -495,10 +494,9 @@ void HistogramImpl::GetExceeds(const FunctionCallbackInfo<Value>& args) {
495494
}
496495

497496
void HistogramImpl::GetExceedsBigInt(const FunctionCallbackInfo<Value>& args) {
498-
Environment* env = Environment::GetCurrent(args);
499497
HistogramImpl* histogram = HistogramImpl::FromJSObject(args.This());
500498
args.GetReturnValue().Set(
501-
BigInt::New(env->isolate(), (*histogram)->Exceeds()));
499+
BigInt::New(args.GetIsolate(), (*histogram)->Exceeds()));
502500
}
503501

504502
void HistogramImpl::GetStddev(const FunctionCallbackInfo<Value>& args) {
@@ -516,12 +514,11 @@ void HistogramImpl::GetPercentile(const FunctionCallbackInfo<Value>& args) {
516514

517515
void HistogramImpl::GetPercentileBigInt(
518516
const FunctionCallbackInfo<Value>& args) {
519-
Environment* env = Environment::GetCurrent(args);
520517
HistogramImpl* histogram = HistogramImpl::FromJSObject(args.This());
521518
CHECK(args[0]->IsNumber());
522519
double percentile = args[0].As<Number>()->Value();
523520
int64_t value = (*histogram)->Percentile(percentile);
524-
args.GetReturnValue().Set(BigInt::New(env->isolate(), value));
521+
args.GetReturnValue().Set(BigInt::New(args.GetIsolate(), value));
525522
}
526523

527524
void HistogramImpl::GetPercentiles(const FunctionCallbackInfo<Value>& args) {

src/inspector_js_api.cc

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -128,14 +128,13 @@ class JSBindingsConnection : public BaseObject {
128128
}
129129

130130
static void Dispatch(const FunctionCallbackInfo<Value>& info) {
131-
Environment* env = Environment::GetCurrent(info);
132131
JSBindingsConnection* session;
133132
ASSIGN_OR_RETURN_UNWRAP(&session, info.This());
134133
CHECK(info[0]->IsString());
135134

136135
if (session->session_) {
137136
session->session_->Dispatch(
138-
ToInspectorString(env->isolate(), info[0])->string());
137+
ToInspectorString(info.GetIsolate(), info[0])->string());
139138
}
140139
}
141140

src/node_blob.cc

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,6 @@ namespace {
4646
void Concat(const FunctionCallbackInfo<Value>& args) {
4747
Isolate* isolate = args.GetIsolate();
4848
Local<Context> context = isolate->GetCurrentContext();
49-
Environment* env = Environment::GetCurrent(context);
5049

5150
CHECK(args[0]->IsArray());
5251
Local<Array> array = args[0].As<Array>();
@@ -83,7 +82,7 @@ void Concat(const FunctionCallbackInfo<Value>& args) {
8382
}
8483

8584
std::shared_ptr<BackingStore> store =
86-
ArrayBuffer::NewBackingStore(env->isolate(), total);
85+
ArrayBuffer::NewBackingStore(isolate, total);
8786
uint8_t* ptr = static_cast<uint8_t*>(store->Data());
8887
for (size_t n = 0; n < views.size(); n++) {
8988
uint8_t* from =
@@ -92,7 +91,7 @@ void Concat(const FunctionCallbackInfo<Value>& args) {
9291
ptr += views[n].length;
9392
}
9493

95-
args.GetReturnValue().Set(ArrayBuffer::New(env->isolate(), std::move(store)));
94+
args.GetReturnValue().Set(ArrayBuffer::New(isolate, std::move(store)));
9695
}
9796

9897
void BlobFromFilePath(const FunctionCallbackInfo<Value>& args) {

src/node_i18n.cc

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -324,10 +324,10 @@ void Transcode(const FunctionCallbackInfo<Value>&args) {
324324
}
325325

326326
void ICUErrorName(const FunctionCallbackInfo<Value>& args) {
327-
Environment* env = Environment::GetCurrent(args);
328327
CHECK(args[0]->IsInt32());
329328
UErrorCode status = static_cast<UErrorCode>(args[0].As<Int32>()->Value());
330-
args.GetReturnValue().Set(OneByteString(env->isolate(), u_errorName(status)));
329+
args.GetReturnValue().Set(
330+
OneByteString(args.GetIsolate(), u_errorName(status)));
331331
}
332332

333333
} // anonymous namespace
@@ -369,10 +369,8 @@ size_t Converter::max_char_size() const {
369369
}
370370

371371
void ConverterObject::Has(const FunctionCallbackInfo<Value>& args) {
372-
Environment* env = Environment::GetCurrent(args);
373-
374372
CHECK_GE(args.Length(), 1);
375-
Utf8Value label(env->isolate(), args[0]);
373+
Utf8Value label(args.GetIsolate(), args[0]);
376374

377375
UErrorCode status = U_ZERO_ERROR;
378376
ConverterPointer conv(ucnv_open(*label, &status));
@@ -639,13 +637,12 @@ static int GetColumnWidth(UChar32 codepoint,
639637

640638
// Returns the column width for the given String.
641639
static void GetStringWidth(const FunctionCallbackInfo<Value>& args) {
642-
Environment* env = Environment::GetCurrent(args);
643640
CHECK(args[0]->IsString());
644641

645642
bool ambiguous_as_full_width = args[1]->IsTrue();
646643
bool expand_emoji_sequence = !args[2]->IsBoolean() || args[2]->IsTrue();
647644

648-
TwoByteValue value(env->isolate(), args[0]);
645+
TwoByteValue value(args.GetIsolate(), args[0]);
649646
// reinterpret_cast is required by windows to compile
650647
UChar* str = reinterpret_cast<UChar*>(*value);
651648
static_assert(sizeof(*str) == sizeof(**value),

src/node_os.cc

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -107,8 +107,7 @@ static void GetOSInformation(const FunctionCallbackInfo<Value>& args) {
107107
}
108108

109109
static void GetCPUInfo(const FunctionCallbackInfo<Value>& args) {
110-
Environment* env = Environment::GetCurrent(args);
111-
Isolate* isolate = env->isolate();
110+
Isolate* isolate = args.GetIsolate();
112111

113112
uv_cpu_info_t* cpu_infos;
114113
int count;

src/node_report_module.cc

Lines changed: 3 additions & 6 deletions

0 commit comments

Comments
 (0)