Skip to content

Commit f0c20cc

Browse files
iknoomtargos
authored andcommitted
src: remove unnecessary Environment::GetCurrent() calls
PR-URL: #59814 Reviewed-By: Chengzhong Wu <[email protected]> Reviewed-By: Gerhard Stöbich <[email protected]>
1 parent 43e6e54 commit f0c20cc

17 files changed

+34
-64
lines changed

src/cares_wrap.cc

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1668,7 +1668,6 @@ Maybe<int> ReverseTraits::Parse(QueryReverseWrap* wrap,
16681668
namespace {
16691669
template <class Wrap>
16701670
static void Query(const FunctionCallbackInfo<Value>& args) {
1671-
Environment* env = Environment::GetCurrent(args);
16721671
ChannelWrap* channel;
16731672
ASSIGN_OR_RETURN_UNWRAP(&channel, args.This());
16741673

@@ -1680,7 +1679,7 @@ static void Query(const FunctionCallbackInfo<Value>& args) {
16801679
Local<String> string = args[1].As<String>();
16811680
auto wrap = std::make_unique<Wrap>(channel, req_wrap_obj);
16821681

1683-
node::Utf8Value utf8name(env->isolate(), string);
1682+
node::Utf8Value utf8name(args.GetIsolate(), string);
16841683
auto plain_name = utf8name.ToStringView();
16851684
std::string name = ada::idna::to_ascii(plain_name);
16861685
channel->ModifyActivityQueryCount(1);
@@ -1695,7 +1694,6 @@ static void Query(const FunctionCallbackInfo<Value>& args) {
16951694
args.GetReturnValue().Set(err);
16961695
}
16971696

1698-
16991697
void AfterGetAddrInfo(uv_getaddrinfo_t* req, int status, struct addrinfo* res) {
17001698
auto cleanup = OnScopeLeave([&]() { uv_freeaddrinfo(res); });
17011699
BaseObjectPtr<GetAddrInfoReqWrap> req_wrap{

src/crypto/crypto_keys.cc

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -805,12 +805,11 @@ void KeyObjectHandle::InitECRaw(const FunctionCallbackInfo<Value>& args) {
805805
}
806806

807807
void KeyObjectHandle::InitEDRaw(const FunctionCallbackInfo<Value>& args) {
808-
Environment* env = Environment::GetCurrent(args);
809808
KeyObjectHandle* key;
810809
ASSIGN_OR_RETURN_UNWRAP(&key, args.This());
811810

812811
CHECK(args[0]->IsString());
813-
Utf8Value name(env->isolate(), args[0]);
812+
Utf8Value name(args.GetIsolate(), args[0]);
814813

815814
ArrayBufferOrViewContents<unsigned char> key_data(args[1]);
816815
KeyType type = FromV8Value<KeyType>(args[2]);
@@ -850,12 +849,11 @@ void KeyObjectHandle::InitEDRaw(const FunctionCallbackInfo<Value>& args) {
850849

851850
#if OPENSSL_WITH_PQC
852851
void KeyObjectHandle::InitPqcRaw(const FunctionCallbackInfo<Value>& args) {
853-
Environment* env = Environment::GetCurrent(args);
854852
KeyObjectHandle* key;
855853
ASSIGN_OR_RETURN_UNWRAP(&key, args.This());
856854

857855
CHECK(args[0]->IsString());
858-
Utf8Value name(env->isolate(), args[0]);
856+
Utf8Value name(args.GetIsolate(), args[0]);
859857

860858
ArrayBufferOrViewContents<unsigned char> key_data(args[1]);
861859
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

@@ -2095,11 +2091,10 @@ void TLSWrap::GetEphemeralKeyInfo(const FunctionCallbackInfo<Value>& args) {
20952091
}
20962092

20972093
void TLSWrap::GetProtocol(const FunctionCallbackInfo<Value>& args) {
2098-
Environment* env = Environment::GetCurrent(args);
20992094
TLSWrap* w;
21002095
ASSIGN_OR_RETURN_UNWRAP(&w, args.This());
21012096
args.GetReturnValue().Set(
2102-
OneByteString(env->isolate(), SSL_get_version(w->ssl_.get())));
2097+
OneByteString(args.GetIsolate(), SSL_get_version(w->ssl_.get())));
21032098
}
21042099

21052100
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
@@ -714,9 +714,8 @@ void SecureBuffer(const FunctionCallbackInfo<Value>& args) {
714714
}
715715

716716
void SecureHeapUsed(const FunctionCallbackInfo<Value>& args) {
717-
Environment* env = Environment::GetCurrent(args);
718717
args.GetReturnValue().Set(
719-
BigInt::New(env->isolate(), DataPointer::GetSecureHeapUsed()));
718+
BigInt::New(args.GetIsolate(), DataPointer::GetSecureHeapUsed()));
720719
}
721720
} // namespace
722721

src/encoding_binding.cc

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -115,8 +115,7 @@ void BindingData::EncodeInto(const FunctionCallbackInfo<Value>& args) {
115115
// Encode a single string to a UTF-8 Uint8Array (not Buffer).
116116
// Used in TextEncoder.prototype.encode.
117117
void BindingData::EncodeUtf8String(const FunctionCallbackInfo<Value>& args) {
118-
Environment* env = Environment::GetCurrent(args);
119-
Isolate* isolate = env->isolate();
118+
Isolate* isolate = args.GetIsolate();
120119
CHECK_GE(args.Length(), 1);
121120
CHECK(args[0]->IsString());
122121

src/histogram.cc

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

457457
void HistogramImpl::GetCountBigInt(const FunctionCallbackInfo<Value>& args) {
458-
Environment* env = Environment::GetCurrent(args);
459458
HistogramImpl* histogram = HistogramImpl::FromJSObject(args.This());
460459
args.GetReturnValue().Set(
461-
BigInt::NewFromUnsigned(env->isolate(), (*histogram)->Count()));
460+
BigInt::NewFromUnsigned(args.GetIsolate(), (*histogram)->Count()));
462461
}
463462

464463
void HistogramImpl::GetMin(const FunctionCallbackInfo<Value>& args) {
@@ -468,9 +467,9 @@ void HistogramImpl::GetMin(const FunctionCallbackInfo<Value>& args) {
468467
}
469468

470469
void HistogramImpl::GetMinBigInt(const FunctionCallbackInfo<Value>& args) {
471-
Environment* env = Environment::GetCurrent(args);
472470
HistogramImpl* histogram = HistogramImpl::FromJSObject(args.This());
473-
args.GetReturnValue().Set(BigInt::New(env->isolate(), (*histogram)->Min()));
471+
args.GetReturnValue().Set(
472+
BigInt::New(args.GetIsolate(), (*histogram)->Min()));
474473
}
475474

476475
void HistogramImpl::GetMax(const FunctionCallbackInfo<Value>& args) {
@@ -480,9 +479,9 @@ void HistogramImpl::GetMax(const FunctionCallbackInfo<Value>& args) {
480479
}
481480

482481
void HistogramImpl::GetMaxBigInt(const FunctionCallbackInfo<Value>& args) {
483-
Environment* env = Environment::GetCurrent(args);
484482
HistogramImpl* histogram = HistogramImpl::FromJSObject(args.This());
485-
args.GetReturnValue().Set(BigInt::New(env->isolate(), (*histogram)->Max()));
483+
args.GetReturnValue().Set(
484+
BigInt::New(args.GetIsolate(), (*histogram)->Max()));
486485
}
487486

488487
void HistogramImpl::GetMean(const FunctionCallbackInfo<Value>& args) {
@@ -497,10 +496,9 @@ void HistogramImpl::GetExceeds(const FunctionCallbackInfo<Value>& args) {
497496
}
498497

499498
void HistogramImpl::GetExceedsBigInt(const FunctionCallbackInfo<Value>& args) {
500-
Environment* env = Environment::GetCurrent(args);
501499
HistogramImpl* histogram = HistogramImpl::FromJSObject(args.This());
502500
args.GetReturnValue().Set(
503-
BigInt::New(env->isolate(), (*histogram)->Exceeds()));
501+
BigInt::New(args.GetIsolate(), (*histogram)->Exceeds()));
504502
}
505503

506504
void HistogramImpl::GetStddev(const FunctionCallbackInfo<Value>& args) {
@@ -518,12 +516,11 @@ void HistogramImpl::GetPercentile(const FunctionCallbackInfo<Value>& args) {
518516

519517
void HistogramImpl::GetPercentileBigInt(
520518
const FunctionCallbackInfo<Value>& args) {
521-
Environment* env = Environment::GetCurrent(args);
522519
HistogramImpl* histogram = HistogramImpl::FromJSObject(args.This());
523520
CHECK(args[0]->IsNumber());
524521
double percentile = args[0].As<Number>()->Value();
525522
int64_t value = (*histogram)->Percentile(percentile);
526-
args.GetReturnValue().Set(BigInt::New(env->isolate(), value));
523+
args.GetReturnValue().Set(BigInt::New(args.GetIsolate(), value));
527524
}
528525

529526
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
@@ -47,7 +47,6 @@ namespace {
4747
void Concat(const FunctionCallbackInfo<Value>& args) {
4848
Isolate* isolate = args.GetIsolate();
4949
Local<Context> context = isolate->GetCurrentContext();
50-
Environment* env = Environment::GetCurrent(context);
5150

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

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

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

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

src/node_i18n.cc

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

329329
void ICUErrorName(const FunctionCallbackInfo<Value>& args) {
330-
Environment* env = Environment::GetCurrent(args);
331330
CHECK(args[0]->IsInt32());
332331
UErrorCode status = static_cast<UErrorCode>(args[0].As<Int32>()->Value());
333-
args.GetReturnValue().Set(OneByteString(env->isolate(), u_errorName(status)));
332+
args.GetReturnValue().Set(
333+
OneByteString(args.GetIsolate(), u_errorName(status)));
334334
}
335335

336336
} // anonymous namespace
@@ -372,10 +372,8 @@ size_t Converter::max_char_size() const {
372372
}
373373

374374
void ConverterObject::Has(const FunctionCallbackInfo<Value>& args) {
375-
Environment* env = Environment::GetCurrent(args);
376-
377375
CHECK_GE(args.Length(), 1);
378-
Utf8Value label(env->isolate(), args[0]);
376+
Utf8Value label(args.GetIsolate(), args[0]);
379377

380378
UErrorCode status = U_ZERO_ERROR;
381379
ConverterPointer conv(ucnv_open(*label, &status));
@@ -645,13 +643,12 @@ static int GetColumnWidth(UChar32 codepoint,
645643

646644
// Returns the column width for the given String.
647645
static void GetStringWidth(const FunctionCallbackInfo<Value>& args) {
648-
Environment* env = Environment::GetCurrent(args);
649646
CHECK(args[0]->IsString());
650647

651648
bool ambiguous_as_full_width = args[1]->IsTrue();
652649
bool expand_emoji_sequence = !args[2]->IsBoolean() || args[2]->IsTrue();
653650

654-
TwoByteValue value(env->isolate(), args[0]);
651+
TwoByteValue value(args.GetIsolate(), args[0]);
655652
// reinterpret_cast is required by windows to compile
656653
UChar* str = reinterpret_cast<UChar*>(*value);
657654
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;

0 commit comments

Comments
 (0)