From f1fdf91560022a00d273e87002fe39accba3eaa6 Mon Sep 17 00:00:00 2001 From: James M Snell Date: Thu, 14 May 2026 14:45:16 -0700 Subject: [PATCH] quic: fixup some v8:: qualifiers Signed-off-by: James M Snell PR-URL: https://github.com/nodejs/node/pull/63267 Reviewed-By: Matteo Collina --- src/quic/bindingdata.cc | 3 ++- src/quic/data.cc | 33 +++++++++++++++++++++++---------- src/quic/preferredaddress.cc | 3 ++- src/quic/session.cc | 21 ++++++++++++--------- src/quic/streams.cc | 21 +++++++++++---------- src/quic/tlscontext.cc | 11 +++++++---- 6 files changed, 57 insertions(+), 35 deletions(-) diff --git a/src/quic/bindingdata.cc b/src/quic/bindingdata.cc index 402e0a25af6..d6ceb2d2c6d 100644 --- a/src/quic/bindingdata.cc +++ b/src/quic/bindingdata.cc @@ -23,6 +23,7 @@ using mem::kReserveSizeAndAlign; using v8::Function; using v8::FunctionTemplate; using v8::HandleScope; +using v8::Isolate; using v8::Local; using v8::Object; using v8::String; @@ -274,7 +275,7 @@ void BindingData::DecreaseAllocatedSize(size_t size) { // Forwards detailed(verbose) debugging information from nghttp3. Enabled using // the NODE_DEBUG_NATIVE=NGHTTP3 category. void nghttp3_debug_log(const char* fmt, va_list args) { - auto isolate = v8::Isolate::GetCurrent(); + auto isolate = Isolate::GetCurrent(); if (isolate == nullptr) return; auto env = Environment::GetCurrent(isolate); if (env->enabled_debug_list()->enabled(DebugCategory::NGHTTP3)) { diff --git a/src/quic/data.cc b/src/quic/data.cc index be2bf458d28..d56420feae1 100644 --- a/src/quic/data.cc +++ b/src/quic/data.cc @@ -17,7 +17,10 @@ using v8::Array; using v8::ArrayBuffer; using v8::ArrayBufferView; using v8::BackingStore; +using v8::BackingStoreInitializationMode; +using v8::BackingStoreOnFailureMode; using v8::BigInt; +using v8::Isolate; using v8::Just; using v8::Local; using v8::Maybe; @@ -89,14 +92,14 @@ Store::Store(std::unique_ptr store, size_t length, size_t offset) } Maybe Store::From(Local buffer) { - v8::Isolate* isolate = v8::Isolate::GetCurrent(); + Isolate* isolate = Isolate::GetCurrent(); Environment* env = Environment::GetCurrent(isolate->GetCurrentContext()); auto length = buffer->ByteLength(); auto dest = ArrayBuffer::NewBackingStore( isolate, length, - v8::BackingStoreInitializationMode::kUninitialized, - v8::BackingStoreOnFailureMode::kReturnNull); + BackingStoreInitializationMode::kUninitialized, + BackingStoreOnFailureMode::kReturnNull); if (!dest) { THROW_ERR_MEMORY_ALLOCATION_FAILED(env); return Nothing(); @@ -108,15 +111,15 @@ Maybe Store::From(Local buffer) { } Maybe Store::From(Local view) { - v8::Isolate* isolate = v8::Isolate::GetCurrent(); + Isolate* isolate = Isolate::GetCurrent(); Environment* env = Environment::GetCurrent(isolate->GetCurrentContext()); auto length = view->ByteLength(); auto offset = view->ByteOffset(); auto dest = ArrayBuffer::NewBackingStore( isolate, length, - v8::BackingStoreInitializationMode::kUninitialized, - v8::BackingStoreOnFailureMode::kReturnNull); + BackingStoreInitializationMode::kUninitialized, + BackingStoreOnFailureMode::kReturnNull); if (!dest) { THROW_ERR_MEMORY_ALLOCATION_FAILED(env); return Nothing(); @@ -130,24 +133,34 @@ Maybe Store::From(Local view) { } Store Store::CopyFrom(Local buffer) { - v8::Isolate* isolate = v8::Isolate::GetCurrent(); + Isolate* isolate = Isolate::GetCurrent(); auto backing = buffer->GetBackingStore(); auto length = buffer->ByteLength(); auto dest = ArrayBuffer::NewBackingStore( - isolate, length, v8::BackingStoreInitializationMode::kUninitialized); + isolate, length, BackingStoreInitializationMode::kUninitialized, + BackingStoreOnFailureMode::kReturnNull); + if (!dest) { + THROW_ERR_MEMORY_ALLOCATION_FAILED(Environment::GetCurrent(isolate)); + return Store(); + } // copy content memcpy(dest->Data(), backing->Data(), length); return Store(std::move(dest), length, 0); } Store Store::CopyFrom(Local view) { - v8::Isolate* isolate = v8::Isolate::GetCurrent(); + Isolate* isolate = Isolate::GetCurrent(); auto backing = view->Buffer()->GetBackingStore(); auto length = view->ByteLength(); auto offset = view->ByteOffset(); auto dest = ArrayBuffer::NewBackingStore( - isolate, length, v8::BackingStoreInitializationMode::kUninitialized); + isolate, length, BackingStoreInitializationMode::kUninitialized, + BackingStoreOnFailureMode::kReturnNull); // copy content + if (!dest) { + THROW_ERR_MEMORY_ALLOCATION_FAILED(Environment::GetCurrent(isolate)); + return Store(); + } memcpy(dest->Data(), static_cast(backing->Data()) + offset, length); return Store(std::move(dest), length, 0); } diff --git a/src/quic/preferredaddress.cc b/src/quic/preferredaddress.cc index 3d584be2d74..ca7908dda35 100644 --- a/src/quic/preferredaddress.cc +++ b/src/quic/preferredaddress.cc @@ -17,6 +17,7 @@ namespace node { using v8::Just; using v8::Local; using v8::Maybe; +using v8::Object; using v8::Value; namespace quic { @@ -131,7 +132,7 @@ Maybe PreferredAddress::tryGetPolicy( : Just(FromV8Value(value)); } -void PreferredAddress::Initialize(Environment* env, Local target) { +void PreferredAddress::Initialize(Environment* env, Local target) { // The QUIC_* constants are expected to be exported out to be used on // the JavaScript side of the API. static constexpr auto PREFERRED_ADDRESS_USE = diff --git a/src/quic/session.cc b/src/quic/session.cc index 8489350ebe7..7737f97e98a 100644 --- a/src/quic/session.cc +++ b/src/quic/session.cc @@ -40,7 +40,9 @@ using v8::Array; using v8::ArrayBufferView; using v8::BigInt; using v8::Boolean; +using v8::Function; using v8::FunctionCallbackInfo; +using v8::Global; using v8::HandleScope; using v8::Int32; using v8::Integer; @@ -54,6 +56,7 @@ using v8::Number; using v8::Object; using v8::ObjectTemplate; using v8::String; +using v8::Uint32; using v8::Undefined; using v8::Value; @@ -420,9 +423,9 @@ bool SetOption(Environment* env, template bool SetOption(Environment* env, Opt* options, - const v8::Local& object, - const v8::Local& name) { - v8::Local value; + const Local& object, + const Local& name) { + Local value; if (!object->Get(env->context(), name).ToLocal(&value)) return false; if (!value->IsUndefined()) { if (!value->IsUint32()) { @@ -431,7 +434,7 @@ bool SetOption(Environment* env, env, "The %s option must be an uint8", *nameStr); return false; } - uint32_t val = value.As()->Value(); + uint32_t val = value.As()->Value(); if (val > 255) { Utf8Value nameStr(env->isolate(), name); THROW_ERR_INVALID_ARG_VALUE( @@ -1718,7 +1721,7 @@ Session::Session(Endpoint* endpoint, Debug(this, "Session created."); { - const v8::HandleScope handle_scope(env()->isolate()); + const HandleScope handle_scope(env()->isolate()); JS_DEFINE_READONLY_PROPERTY( env(), object, @@ -1728,7 +1731,7 @@ Session::Session(Endpoint* endpoint, env(), object, FIXED_ONE_BYTE_STRING(env()->isolate(), "stateByteOffset"), - v8::Integer::NewFromUnsigned( + Integer::NewFromUnsigned( env()->isolate(), static_cast(impl_->state_slot_.GetByteOffset()))); JS_DEFINE_READONLY_PROPERTY( @@ -1740,7 +1743,7 @@ Session::Session(Endpoint* endpoint, env(), object, FIXED_ONE_BYTE_STRING(env()->isolate(), "statsByteOffset"), - v8::Integer::NewFromUnsigned( + Integer::NewFromUnsigned( env()->isolate(), static_cast(impl_->stats_slot_.GetByteOffset()))); } @@ -2127,8 +2130,8 @@ void Session::EmitQlog(uint32_t flags, std::string_view data) { // ngtcp2_conn is mid-destruction. Defer the final chunk via SetImmediate. if (is_destroyed()) { auto isolate = env()->isolate(); - v8::Global recv(isolate, object()); - v8::Global cb( + Global recv(isolate, object()); + Global cb( isolate, BindingData::Get(env()).session_qlog_callback()); std::string buf(data); env()->SetImmediate([recv = std::move(recv), diff --git a/src/quic/streams.cc b/src/quic/streams.cc index 60ce8085663..3bcfd544abf 100644 --- a/src/quic/streams.cc +++ b/src/quic/streams.cc @@ -26,6 +26,7 @@ using v8::BackingStore; using v8::BigInt; using v8::FunctionCallbackInfo; using v8::Global; +using v8::HandleScope; using v8::Integer; using v8::Just; using v8::Local; @@ -34,6 +35,7 @@ using v8::Nothing; using v8::Object; using v8::ObjectTemplate; using v8::SharedArrayBuffer; +using v8::String; using v8::Uint32; using v8::Uint8Array; using v8::Value; @@ -277,7 +279,7 @@ Maybe> Stream::GetDataQueueFromSource( // object's constructor name is "FileHandle". if (value->IsObject()) { auto obj = value.As(); - Local ctor_name; + Local ctor_name; auto maybe_name = obj->GetConstructorName(); if (!maybe_name.IsEmpty()) { ctor_name = maybe_name; @@ -287,9 +289,8 @@ Maybe> Stream::GetDataQueueFromSource( ASSIGN_OR_RETURN_UNWRAP( &file_handle, value, Nothing>()); Local path; - if (!v8::String::NewFromUtf8(env->isolate(), - file_handle->original_name().c_str()) - .ToLocal(&path)) { + if (!ToV8Value(env->context(), file_handle->original_name()) + .ToLocal(&path)) { return Nothing>(); } auto entry = DataQueue::CreateFdEntry(env, path); @@ -1048,7 +1049,7 @@ Stream::Stream(BaseObjectWeakPtr session, inbound_->addBackpressureListener(this); { - const v8::HandleScope handle_scope(env()->isolate()); + const HandleScope handle_scope(env()->isolate()); // Pass the page's shared views and this slot's byte offset. JS uses // the offset to index into the shared view — no per-stream V8 object // creation. @@ -1060,7 +1061,7 @@ Stream::Stream(BaseObjectWeakPtr session, env(), object, FIXED_ONE_BYTE_STRING(env()->isolate(), "stateByteOffset"), - v8::Integer::NewFromUnsigned( + Integer::NewFromUnsigned( env()->isolate(), static_cast(state_slot_.GetByteOffset()))); JS_DEFINE_READONLY_PROPERTY( @@ -1072,7 +1073,7 @@ Stream::Stream(BaseObjectWeakPtr session, env(), object, FIXED_ONE_BYTE_STRING(env()->isolate(), "statsByteOffset"), - v8::Integer::NewFromUnsigned( + Integer::NewFromUnsigned( env()->isolate(), static_cast(stats_slot_.GetByteOffset()))); } @@ -1107,7 +1108,7 @@ Stream::Stream(BaseObjectWeakPtr session, inbound_->addBackpressureListener(this); { - const v8::HandleScope handle_scope(env()->isolate()); + const HandleScope handle_scope(env()->isolate()); JS_DEFINE_READONLY_PROPERTY(env(), object, env()->state_string(), @@ -1116,7 +1117,7 @@ Stream::Stream(BaseObjectWeakPtr session, env(), object, FIXED_ONE_BYTE_STRING(env()->isolate(), "stateByteOffset"), - v8::Integer::NewFromUnsigned( + Integer::NewFromUnsigned( env()->isolate(), static_cast(state_slot_.GetByteOffset()))); JS_DEFINE_READONLY_PROPERTY( @@ -1128,7 +1129,7 @@ Stream::Stream(BaseObjectWeakPtr session, env(), object, FIXED_ONE_BYTE_STRING(env()->isolate(), "statsByteOffset"), - v8::Integer::NewFromUnsigned( + Integer::NewFromUnsigned( env()->isolate(), static_cast(stats_slot_.GetByteOffset()))); } diff --git a/src/quic/tlscontext.cc b/src/quic/tlscontext.cc index 08ce7f9acd1..6b708315c97 100644 --- a/src/quic/tlscontext.cc +++ b/src/quic/tlscontext.cc @@ -30,13 +30,16 @@ using ncrypto::SSLCtxPointer; using ncrypto::SSLPointer; using ncrypto::SSLSessionPointer; using ncrypto::X509Pointer; +using v8::Array; using v8::ArrayBuffer; +using v8::ArrayBufferView; using v8::Just; using v8::Local; using v8::Maybe; using v8::MaybeLocal; using v8::Nothing; using v8::Object; +using v8::String; using v8::Undefined; using v8::Value; @@ -95,7 +98,7 @@ template Opt::*member> bool SetOption(Environment* env, Opt* options, const Local& object, - const Local& name) { + const Local& name) { Local value; if (!object->Get(env->context(), name).ToLocal(&value)) return false; @@ -105,7 +108,7 @@ bool SetOption(Environment* env, if (value->IsArray()) { auto context = env->context(); - auto values = value.As(); + auto values = value.As(); uint32_t count = values->Length(); for (uint32_t n = 0; n < count; n++) { Local item; @@ -125,7 +128,7 @@ bool SetOption(Environment* env, } } else if constexpr (std::is_same::value) { if (item->IsArrayBufferView()) { - Store store = Store::CopyFrom(item.As()); + Store store = Store::CopyFrom(item.As()); (options->*member).push_back(std::move(store)); } else if (item->IsArrayBuffer()) { Store store = Store::CopyFrom(item.As()); @@ -154,7 +157,7 @@ bool SetOption(Environment* env, } } else if constexpr (std::is_same::value) { if (value->IsArrayBufferView()) { - Store store = Store::CopyFrom(value.As()); + Store store = Store::CopyFrom(value.As()); (options->*member).push_back(std::move(store)); } else if (value->IsArrayBuffer()) { Store store = Store::CopyFrom(value.As());