From 8e182e561f74ee12a109826d81f997ef26e7bfca Mon Sep 17 00:00:00 2001 From: Moonki Choi Date: Thu, 11 Sep 2025 15:45:38 +0900 Subject: [PATCH] src: remove unnecessary `Environment::GetCurrent()` calls MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit PR-URL: https://github.com/nodejs/node/pull/59814 Reviewed-By: Chengzhong Wu Reviewed-By: Gerhard Stöbich --- src/cares_wrap.cc | 4 +--- src/crypto/crypto_keys.cc | 3 +-- src/crypto/crypto_tls.cc | 11 +++-------- src/crypto/crypto_util.cc | 3 +-- src/histogram.cc | 17 +++++++---------- src/inspector_js_api.cc | 3 +-- src/node_blob.cc | 5 ++--- src/node_i18n.cc | 11 ++++------- src/node_os.cc | 3 +-- src/node_report_module.cc | 9 +++------ src/node_sqlite.cc | 5 ++--- src/node_task_queue.cc | 3 +-- src/node_util.cc | 4 +--- src/node_v8.cc | 6 ++---- src/node_wasm_web_api.cc | 2 +- src/uv.cc | 3 +-- 16 files changed, 32 insertions(+), 60 deletions(-) diff --git a/src/cares_wrap.cc b/src/cares_wrap.cc index 444b1f73f9e..31705cd1e02 100644 --- a/src/cares_wrap.cc +++ b/src/cares_wrap.cc @@ -1668,7 +1668,6 @@ Maybe ReverseTraits::Parse(QueryReverseWrap* wrap, namespace { template static void Query(const FunctionCallbackInfo& args) { - Environment* env = Environment::GetCurrent(args); ChannelWrap* channel; ASSIGN_OR_RETURN_UNWRAP(&channel, args.This()); @@ -1680,7 +1679,7 @@ static void Query(const FunctionCallbackInfo& args) { Local string = args[1].As(); auto wrap = std::make_unique(channel, req_wrap_obj); - node::Utf8Value utf8name(env->isolate(), string); + node::Utf8Value utf8name(args.GetIsolate(), string); auto plain_name = utf8name.ToStringView(); std::string name = ada::idna::to_ascii(plain_name); channel->ModifyActivityQueryCount(1); @@ -1695,7 +1694,6 @@ static void Query(const FunctionCallbackInfo& args) { args.GetReturnValue().Set(err); } - void AfterGetAddrInfo(uv_getaddrinfo_t* req, int status, struct addrinfo* res) { auto cleanup = OnScopeLeave([&]() { uv_freeaddrinfo(res); }); BaseObjectPtr req_wrap{ diff --git a/src/crypto/crypto_keys.cc b/src/crypto/crypto_keys.cc index 7238cda445f..fe852bdebac 100644 --- a/src/crypto/crypto_keys.cc +++ b/src/crypto/crypto_keys.cc @@ -799,12 +799,11 @@ int GetOKPCurveFromName(const char* name) { } void KeyObjectHandle::InitEDRaw(const FunctionCallbackInfo& args) { - Environment* env = Environment::GetCurrent(args); KeyObjectHandle* key; ASSIGN_OR_RETURN_UNWRAP(&key, args.This()); CHECK(args[0]->IsString()); - Utf8Value name(env->isolate(), args[0]); + Utf8Value name(args.GetIsolate(), args[0]); ArrayBufferOrViewContents key_data(args[1]); KeyType type = FromV8Value(args[2]); diff --git a/src/crypto/crypto_tls.cc b/src/crypto/crypto_tls.cc index d98411f0ccc..a80685790bd 100644 --- a/src/crypto/crypto_tls.cc +++ b/src/crypto/crypto_tls.cc @@ -1357,8 +1357,6 @@ void TLSWrap::EnableALPNCb(const FunctionCallbackInfo& args) { } void TLSWrap::GetServername(const FunctionCallbackInfo& args) { - Environment* env = Environment::GetCurrent(args); - TLSWrap* wrap; ASSIGN_OR_RETURN_UNWRAP(&wrap, args.This()); @@ -1368,15 +1366,13 @@ void TLSWrap::GetServername(const FunctionCallbackInfo& args) { if (servername.has_value()) { auto& sn = servername.value(); args.GetReturnValue().Set( - OneByteString(env->isolate(), sn.data(), sn.length())); + OneByteString(args.GetIsolate(), sn.data(), sn.length())); } else { args.GetReturnValue().Set(false); } } void TLSWrap::SetServername(const FunctionCallbackInfo& args) { - Environment* env = Environment::GetCurrent(args); - TLSWrap* wrap; ASSIGN_OR_RETURN_UNWRAP(&wrap, args.This()); @@ -1387,7 +1383,7 @@ void TLSWrap::SetServername(const FunctionCallbackInfo& args) { CHECK(wrap->ssl_); - Utf8Value servername(env->isolate(), args[0].As()); + Utf8Value servername(args.GetIsolate(), args[0].As()); SSL_set_tlsext_host_name(wrap->ssl_.get(), *servername); } @@ -2109,11 +2105,10 @@ void TLSWrap::GetEphemeralKeyInfo(const FunctionCallbackInfo& args) { } void TLSWrap::GetProtocol(const FunctionCallbackInfo& args) { - Environment* env = Environment::GetCurrent(args); TLSWrap* w; ASSIGN_OR_RETURN_UNWRAP(&w, args.This()); args.GetReturnValue().Set( - OneByteString(env->isolate(), SSL_get_version(w->ssl_.get()))); + OneByteString(args.GetIsolate(), SSL_get_version(w->ssl_.get()))); } void TLSWrap::GetALPNNegotiatedProto(const FunctionCallbackInfo& args) { diff --git a/src/crypto/crypto_util.cc b/src/crypto/crypto_util.cc index 7c548d32b40..9c2360df715 100644 --- a/src/crypto/crypto_util.cc +++ b/src/crypto/crypto_util.cc @@ -705,10 +705,9 @@ void SecureBuffer(const FunctionCallbackInfo& args) { } void SecureHeapUsed(const FunctionCallbackInfo& args) { - Environment* env = Environment::GetCurrent(args); if (CRYPTO_secure_malloc_initialized()) args.GetReturnValue().Set( - BigInt::New(env->isolate(), CRYPTO_secure_used())); + BigInt::New(args.GetIsolate(), CRYPTO_secure_used())); } } // namespace diff --git a/src/histogram.cc b/src/histogram.cc index b655808e43d..4a67b4a725f 100644 --- a/src/histogram.cc +++ b/src/histogram.cc @@ -453,10 +453,9 @@ void HistogramImpl::GetCount(const FunctionCallbackInfo& args) { } void HistogramImpl::GetCountBigInt(const FunctionCallbackInfo& args) { - Environment* env = Environment::GetCurrent(args); HistogramImpl* histogram = HistogramImpl::FromJSObject(args.This()); args.GetReturnValue().Set( - BigInt::NewFromUnsigned(env->isolate(), (*histogram)->Count())); + BigInt::NewFromUnsigned(args.GetIsolate(), (*histogram)->Count())); } void HistogramImpl::GetMin(const FunctionCallbackInfo& args) { @@ -466,9 +465,9 @@ void HistogramImpl::GetMin(const FunctionCallbackInfo& args) { } void HistogramImpl::GetMinBigInt(const FunctionCallbackInfo& args) { - Environment* env = Environment::GetCurrent(args); HistogramImpl* histogram = HistogramImpl::FromJSObject(args.This()); - args.GetReturnValue().Set(BigInt::New(env->isolate(), (*histogram)->Min())); + args.GetReturnValue().Set( + BigInt::New(args.GetIsolate(), (*histogram)->Min())); } void HistogramImpl::GetMax(const FunctionCallbackInfo& args) { @@ -478,9 +477,9 @@ void HistogramImpl::GetMax(const FunctionCallbackInfo& args) { } void HistogramImpl::GetMaxBigInt(const FunctionCallbackInfo& args) { - Environment* env = Environment::GetCurrent(args); HistogramImpl* histogram = HistogramImpl::FromJSObject(args.This()); - args.GetReturnValue().Set(BigInt::New(env->isolate(), (*histogram)->Max())); + args.GetReturnValue().Set( + BigInt::New(args.GetIsolate(), (*histogram)->Max())); } void HistogramImpl::GetMean(const FunctionCallbackInfo& args) { @@ -495,10 +494,9 @@ void HistogramImpl::GetExceeds(const FunctionCallbackInfo& args) { } void HistogramImpl::GetExceedsBigInt(const FunctionCallbackInfo& args) { - Environment* env = Environment::GetCurrent(args); HistogramImpl* histogram = HistogramImpl::FromJSObject(args.This()); args.GetReturnValue().Set( - BigInt::New(env->isolate(), (*histogram)->Exceeds())); + BigInt::New(args.GetIsolate(), (*histogram)->Exceeds())); } void HistogramImpl::GetStddev(const FunctionCallbackInfo& args) { @@ -516,12 +514,11 @@ void HistogramImpl::GetPercentile(const FunctionCallbackInfo& args) { void HistogramImpl::GetPercentileBigInt( const FunctionCallbackInfo& args) { - Environment* env = Environment::GetCurrent(args); HistogramImpl* histogram = HistogramImpl::FromJSObject(args.This()); CHECK(args[0]->IsNumber()); double percentile = args[0].As()->Value(); int64_t value = (*histogram)->Percentile(percentile); - args.GetReturnValue().Set(BigInt::New(env->isolate(), value)); + args.GetReturnValue().Set(BigInt::New(args.GetIsolate(), value)); } void HistogramImpl::GetPercentiles(const FunctionCallbackInfo& args) { diff --git a/src/inspector_js_api.cc b/src/inspector_js_api.cc index 64823c68b11..cbad4651f1d 100644 --- a/src/inspector_js_api.cc +++ b/src/inspector_js_api.cc @@ -128,14 +128,13 @@ class JSBindingsConnection : public BaseObject { } static void Dispatch(const FunctionCallbackInfo& info) { - Environment* env = Environment::GetCurrent(info); JSBindingsConnection* session; ASSIGN_OR_RETURN_UNWRAP(&session, info.This()); CHECK(info[0]->IsString()); if (session->session_) { session->session_->Dispatch( - ToInspectorString(env->isolate(), info[0])->string()); + ToInspectorString(info.GetIsolate(), info[0])->string()); } } diff --git a/src/node_blob.cc b/src/node_blob.cc index 9b9956f5ee3..eb0fbebc9df 100644 --- a/src/node_blob.cc +++ b/src/node_blob.cc @@ -46,7 +46,6 @@ namespace { void Concat(const FunctionCallbackInfo& args) { Isolate* isolate = args.GetIsolate(); Local context = isolate->GetCurrentContext(); - Environment* env = Environment::GetCurrent(context); CHECK(args[0]->IsArray()); Local array = args[0].As(); @@ -83,7 +82,7 @@ void Concat(const FunctionCallbackInfo& args) { } std::shared_ptr store = - ArrayBuffer::NewBackingStore(env->isolate(), total); + ArrayBuffer::NewBackingStore(isolate, total); uint8_t* ptr = static_cast(store->Data()); for (size_t n = 0; n < views.size(); n++) { uint8_t* from = @@ -92,7 +91,7 @@ void Concat(const FunctionCallbackInfo& args) { ptr += views[n].length; } - args.GetReturnValue().Set(ArrayBuffer::New(env->isolate(), std::move(store))); + args.GetReturnValue().Set(ArrayBuffer::New(isolate, std::move(store))); } void BlobFromFilePath(const FunctionCallbackInfo& args) { diff --git a/src/node_i18n.cc b/src/node_i18n.cc index 61b6ecd240c..6be3920632b 100644 --- a/src/node_i18n.cc +++ b/src/node_i18n.cc @@ -324,10 +324,10 @@ void Transcode(const FunctionCallbackInfo&args) { } void ICUErrorName(const FunctionCallbackInfo& args) { - Environment* env = Environment::GetCurrent(args); CHECK(args[0]->IsInt32()); UErrorCode status = static_cast(args[0].As()->Value()); - args.GetReturnValue().Set(OneByteString(env->isolate(), u_errorName(status))); + args.GetReturnValue().Set( + OneByteString(args.GetIsolate(), u_errorName(status))); } } // anonymous namespace @@ -369,10 +369,8 @@ size_t Converter::max_char_size() const { } void ConverterObject::Has(const FunctionCallbackInfo& args) { - Environment* env = Environment::GetCurrent(args); - CHECK_GE(args.Length(), 1); - Utf8Value label(env->isolate(), args[0]); + Utf8Value label(args.GetIsolate(), args[0]); UErrorCode status = U_ZERO_ERROR; ConverterPointer conv(ucnv_open(*label, &status)); @@ -639,13 +637,12 @@ static int GetColumnWidth(UChar32 codepoint, // Returns the column width for the given String. static void GetStringWidth(const FunctionCallbackInfo& args) { - Environment* env = Environment::GetCurrent(args); CHECK(args[0]->IsString()); bool ambiguous_as_full_width = args[1]->IsTrue(); bool expand_emoji_sequence = !args[2]->IsBoolean() || args[2]->IsTrue(); - TwoByteValue value(env->isolate(), args[0]); + TwoByteValue value(args.GetIsolate(), args[0]); // reinterpret_cast is required by windows to compile UChar* str = reinterpret_cast(*value); static_assert(sizeof(*str) == sizeof(**value), diff --git a/src/node_os.cc b/src/node_os.cc index 54ef253b0b7..3d5d465b46a 100644 --- a/src/node_os.cc +++ b/src/node_os.cc @@ -107,8 +107,7 @@ static void GetOSInformation(const FunctionCallbackInfo& args) { } static void GetCPUInfo(const FunctionCallbackInfo& args) { - Environment* env = Environment::GetCurrent(args); - Isolate* isolate = env->isolate(); + Isolate* isolate = args.GetIsolate(); uv_cpu_info_t* cpu_infos; int count; diff --git a/src/node_report_module.cc b/src/node_report_module.cc index 7a87a53203d..e788cd332e0 100644 --- a/src/node_report_module.cc +++ b/src/node_report_module.cc @@ -78,8 +78,7 @@ static void GetCompact(const FunctionCallbackInfo& info) { static void SetCompact(const FunctionCallbackInfo& info) { Mutex::ScopedLock lock(per_process::cli_options_mutex); - Environment* env = Environment::GetCurrent(info); - Isolate* isolate = env->isolate(); + Isolate* isolate = info.GetIsolate(); bool compact = info[0]->ToBoolean(isolate)->Value(); per_process::cli_options->report_compact = compact; } @@ -116,9 +115,8 @@ static void GetDirectory(const FunctionCallbackInfo& info) { static void SetDirectory(const FunctionCallbackInfo& info) { Mutex::ScopedLock lock(per_process::cli_options_mutex); - Environment* env = Environment::GetCurrent(info); CHECK(info[0]->IsString()); - Utf8Value dir(env->isolate(), info[0].As()); + Utf8Value dir(info.GetIsolate(), info[0].As()); per_process::cli_options->report_directory = *dir; } @@ -132,9 +130,8 @@ static void GetFilename(const FunctionCallbackInfo& info) { static void SetFilename(const FunctionCallbackInfo& info) { Mutex::ScopedLock lock(per_process::cli_options_mutex); - Environment* env = Environment::GetCurrent(info); CHECK(info[0]->IsString()); - Utf8Value name(env->isolate(), info[0].As()); + Utf8Value name(info.GetIsolate(), info[0].As()); per_process::cli_options->report_filename = *name; } diff --git a/src/node_sqlite.cc b/src/node_sqlite.cc index 13dde3c0d21..9716b17ece6 100644 --- a/src/node_sqlite.cc +++ b/src/node_sqlite.cc @@ -1757,15 +1757,14 @@ void DatabaseSync::EnableLoadExtension( const FunctionCallbackInfo& args) { DatabaseSync* db; ASSIGN_OR_RETURN_UNWRAP(&db, args.This()); - Environment* env = Environment::GetCurrent(args); + auto isolate = args.GetIsolate(); if (!args[0]->IsBoolean()) { - THROW_ERR_INVALID_ARG_TYPE(env->isolate(), + THROW_ERR_INVALID_ARG_TYPE(isolate, "The \"allow\" argument must be a boolean."); return; } const int enable = args[0].As()->Value(); - auto isolate = env->isolate(); if (db->allow_load_extension_ == false && enable == true) { THROW_ERR_INVALID_STATE( diff --git a/src/node_task_queue.cc b/src/node_task_queue.cc index c4257110d8b..d33ee3c26c1 100644 --- a/src/node_task_queue.cc +++ b/src/node_task_queue.cc @@ -129,8 +129,7 @@ void PromiseRejectCallback(PromiseRejectMessage message) { namespace task_queue { static void EnqueueMicrotask(const FunctionCallbackInfo& args) { - Environment* env = Environment::GetCurrent(args); - Isolate* isolate = env->isolate(); + Isolate* isolate = args.GetIsolate(); CHECK(args[0]->IsFunction()); diff --git a/src/node_util.cc b/src/node_util.cc index 1972d30b9b3..1280c4b7f62 100644 --- a/src/node_util.cc +++ b/src/node_util.cc @@ -399,9 +399,7 @@ static void DefineLazyProperties(const FunctionCallbackInfo& args) { // enumerable: Whether the property should be enumerable. CHECK(args.Length() == 3 || args[3]->IsBoolean()); - Environment* env = Environment::GetCurrent(args); - Isolate* isolate = env->isolate(); - auto context = isolate->GetCurrentContext(); + auto context = args.GetIsolate()->GetCurrentContext(); auto target = args[0].As(); Local id = args[1]; diff --git a/src/node_v8.cc b/src/node_v8.cc index 430d5dd4f80..dd2284a56c0 100644 --- a/src/node_v8.cc +++ b/src/node_v8.cc @@ -182,10 +182,8 @@ void BindingData::MemoryInfo(MemoryTracker* tracker) const { } void CachedDataVersionTag(const FunctionCallbackInfo& args) { - Environment* env = Environment::GetCurrent(args); - Local result = - Integer::NewFromUnsigned(env->isolate(), - ScriptCompiler::CachedDataVersionTag()); + Local result = Integer::NewFromUnsigned( + args.GetIsolate(), ScriptCompiler::CachedDataVersionTag()); args.GetReturnValue().Set(result); } diff --git a/src/node_wasm_web_api.cc b/src/node_wasm_web_api.cc index 6e66b3d5fbf..365edbe3c2e 100644 --- a/src/node_wasm_web_api.cc +++ b/src/node_wasm_web_api.cc @@ -86,7 +86,7 @@ void WasmStreamingObject::SetURL(const FunctionCallbackInfo& args) { CHECK_EQ(args.Length(), 1); CHECK(args[0]->IsString()); - Utf8Value url(Environment::GetCurrent(args)->isolate(), args[0]); + Utf8Value url(args.GetIsolate(), args[0]); obj->streaming_->SetUrl(url.out(), url.length()); } diff --git a/src/uv.cc b/src/uv.cc index 168e7be408c..d4fadfc24e9 100644 --- a/src/uv.cc +++ b/src/uv.cc @@ -60,12 +60,11 @@ using v8::String; using v8::Value; void GetErrMessage(const FunctionCallbackInfo& args) { - Environment* env = Environment::GetCurrent(args); int err = args[0].As()->Value(); CHECK_LT(err, 0); char message[50]; uv_strerror_r(err, message, sizeof(message)); - args.GetReturnValue().Set(OneByteString(env->isolate(), message)); + args.GetReturnValue().Set(OneByteString(args.GetIsolate(), message)); } void ErrName(const FunctionCallbackInfo& args) {