Skip to content

Commit 6cffc93

Browse files
jasnelladuh95
authored andcommitted
quic: fixup some v8:: qualifiers
Signed-off-by: James M Snell <jasnell@gmail.com> PR-URL: #63267 Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
1 parent 9bc875e commit 6cffc93

6 files changed

Lines changed: 57 additions & 35 deletions

File tree

src/quic/bindingdata.cc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ using mem::kReserveSizeAndAlign;
2323
using v8::Function;
2424
using v8::FunctionTemplate;
2525
using v8::HandleScope;
26+
using v8::Isolate;
2627
using v8::Local;
2728
using v8::Object;
2829
using v8::String;
@@ -274,7 +275,7 @@ void BindingData::DecreaseAllocatedSize(size_t size) {
274275
// Forwards detailed(verbose) debugging information from nghttp3. Enabled using
275276
// the NODE_DEBUG_NATIVE=NGHTTP3 category.
276277
void nghttp3_debug_log(const char* fmt, va_list args) {
277-
auto isolate = v8::Isolate::GetCurrent();
278+
auto isolate = Isolate::GetCurrent();
278279
if (isolate == nullptr) return;
279280
auto env = Environment::GetCurrent(isolate);
280281
if (env->enabled_debug_list()->enabled(DebugCategory::NGHTTP3)) {

src/quic/data.cc

Lines changed: 23 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,10 @@ using v8::Array;
1717
using v8::ArrayBuffer;
1818
using v8::ArrayBufferView;
1919
using v8::BackingStore;
20+
using v8::BackingStoreInitializationMode;
21+
using v8::BackingStoreOnFailureMode;
2022
using v8::BigInt;
23+
using v8::Isolate;
2124
using v8::Just;
2225
using v8::Local;
2326
using v8::Maybe;
@@ -89,14 +92,14 @@ Store::Store(std::unique_ptr<BackingStore> store, size_t length, size_t offset)
8992
}
9093

9194
Maybe<Store> Store::From(Local<ArrayBuffer> buffer) {
92-
v8::Isolate* isolate = v8::Isolate::GetCurrent();
95+
Isolate* isolate = Isolate::GetCurrent();
9396
Environment* env = Environment::GetCurrent(isolate->GetCurrentContext());
9497
auto length = buffer->ByteLength();
9598
auto dest = ArrayBuffer::NewBackingStore(
9699
isolate,
97100
length,
98-
v8::BackingStoreInitializationMode::kUninitialized,
99-
v8::BackingStoreOnFailureMode::kReturnNull);
101+
BackingStoreInitializationMode::kUninitialized,
102+
BackingStoreOnFailureMode::kReturnNull);
100103
if (!dest) {
101104
THROW_ERR_MEMORY_ALLOCATION_FAILED(env);
102105
return Nothing<Store>();
@@ -108,15 +111,15 @@ Maybe<Store> Store::From(Local<ArrayBuffer> buffer) {
108111
}
109112

110113
Maybe<Store> Store::From(Local<ArrayBufferView> view) {
111-
v8::Isolate* isolate = v8::Isolate::GetCurrent();
114+
Isolate* isolate = Isolate::GetCurrent();
112115
Environment* env = Environment::GetCurrent(isolate->GetCurrentContext());
113116
auto length = view->ByteLength();
114117
auto offset = view->ByteOffset();
115118
auto dest = ArrayBuffer::NewBackingStore(
116119
isolate,
117120
length,
118-
v8::BackingStoreInitializationMode::kUninitialized,
119-
v8::BackingStoreOnFailureMode::kReturnNull);
121+
BackingStoreInitializationMode::kUninitialized,
122+
BackingStoreOnFailureMode::kReturnNull);
120123
if (!dest) {
121124
THROW_ERR_MEMORY_ALLOCATION_FAILED(env);
122125
return Nothing<Store>();
@@ -130,24 +133,34 @@ Maybe<Store> Store::From(Local<ArrayBufferView> view) {
130133
}
131134

132135
Store Store::CopyFrom(Local<ArrayBuffer> buffer) {
133-
v8::Isolate* isolate = v8::Isolate::GetCurrent();
136+
Isolate* isolate = Isolate::GetCurrent();
134137
auto backing = buffer->GetBackingStore();
135138
auto length = buffer->ByteLength();
136139
auto dest = ArrayBuffer::NewBackingStore(
137-
isolate, length, v8::BackingStoreInitializationMode::kUninitialized);
140+
isolate, length, BackingStoreInitializationMode::kUninitialized,
141+
BackingStoreOnFailureMode::kReturnNull);
142+
if (!dest) {
143+
THROW_ERR_MEMORY_ALLOCATION_FAILED(Environment::GetCurrent(isolate));
144+
return Store();
145+
}
138146
// copy content
139147
memcpy(dest->Data(), backing->Data(), length);
140148
return Store(std::move(dest), length, 0);
141149
}
142150

143151
Store Store::CopyFrom(Local<ArrayBufferView> view) {
144-
v8::Isolate* isolate = v8::Isolate::GetCurrent();
152+
Isolate* isolate = Isolate::GetCurrent();
145153
auto backing = view->Buffer()->GetBackingStore();
146154
auto length = view->ByteLength();
147155
auto offset = view->ByteOffset();
148156
auto dest = ArrayBuffer::NewBackingStore(
149-
isolate, length, v8::BackingStoreInitializationMode::kUninitialized);
157+
isolate, length, BackingStoreInitializationMode::kUninitialized,
158+
BackingStoreOnFailureMode::kReturnNull);
150159
// copy content
160+
if (!dest) {
161+
THROW_ERR_MEMORY_ALLOCATION_FAILED(Environment::GetCurrent(isolate));
162+
return Store();
163+
}
151164
memcpy(dest->Data(), static_cast<char*>(backing->Data()) + offset, length);
152165
return Store(std::move(dest), length, 0);
153166
}

src/quic/preferredaddress.cc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ namespace node {
1717
using v8::Just;
1818
using v8::Local;
1919
using v8::Maybe;
20+
using v8::Object;
2021
using v8::Value;
2122

2223
namespace quic {
@@ -131,7 +132,7 @@ Maybe<PreferredAddress::Policy> PreferredAddress::tryGetPolicy(
131132
: Just(FromV8Value<Policy>(value));
132133
}
133134

134-
void PreferredAddress::Initialize(Environment* env, Local<v8::Object> target) {
135+
void PreferredAddress::Initialize(Environment* env, Local<Object> target) {
135136
// The QUIC_* constants are expected to be exported out to be used on
136137
// the JavaScript side of the API.
137138
static constexpr auto PREFERRED_ADDRESS_USE =

src/quic/session.cc

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,9 @@ using v8::Array;
4040
using v8::ArrayBufferView;
4141
using v8::BigInt;
4242
using v8::Boolean;
43+
using v8::Function;
4344
using v8::FunctionCallbackInfo;
45+
using v8::Global;
4446
using v8::HandleScope;
4547
using v8::Int32;
4648
using v8::Integer;
@@ -54,6 +56,7 @@ using v8::Number;
5456
using v8::Object;
5557
using v8::ObjectTemplate;
5658
using v8::String;
59+
using v8::Uint32;
5760
using v8::Undefined;
5861
using v8::Value;
5962

@@ -420,9 +423,9 @@ bool SetOption(Environment* env,
420423
template <typename Opt, uint8_t Opt::*member>
421424
bool SetOption(Environment* env,
422425
Opt* options,
423-
const v8::Local<v8::Object>& object,
424-
const v8::Local<v8::String>& name) {
425-
v8::Local<v8::Value> value;
426+
const Local<Object>& object,
427+
const Local<String>& name) {
428+
Local<Value> value;
426429
if (!object->Get(env->context(), name).ToLocal(&value)) return false;
427430
if (!value->IsUndefined()) {
428431
if (!value->IsUint32()) {
@@ -431,7 +434,7 @@ bool SetOption(Environment* env,
431434
env, "The %s option must be an uint8", *nameStr);
432435
return false;
433436
}
434-
uint32_t val = value.As<v8::Uint32>()->Value();
437+
uint32_t val = value.As<Uint32>()->Value();
435438
if (val > 255) {
436439
Utf8Value nameStr(env->isolate(), name);
437440
THROW_ERR_INVALID_ARG_VALUE(
@@ -1718,7 +1721,7 @@ Session::Session(Endpoint* endpoint,
17181721
Debug(this, "Session created.");
17191722

17201723
{
1721-
const v8::HandleScope handle_scope(env()->isolate());
1724+
const HandleScope handle_scope(env()->isolate());
17221725
JS_DEFINE_READONLY_PROPERTY(
17231726
env(),
17241727
object,
@@ -1728,7 +1731,7 @@ Session::Session(Endpoint* endpoint,
17281731
env(),
17291732
object,
17301733
FIXED_ONE_BYTE_STRING(env()->isolate(), "stateByteOffset"),
1731-
v8::Integer::NewFromUnsigned(
1734+
Integer::NewFromUnsigned(
17321735
env()->isolate(),
17331736
static_cast<uint32_t>(impl_->state_slot_.GetByteOffset())));
17341737
JS_DEFINE_READONLY_PROPERTY(
@@ -1740,7 +1743,7 @@ Session::Session(Endpoint* endpoint,
17401743
env(),
17411744
object,
17421745
FIXED_ONE_BYTE_STRING(env()->isolate(), "statsByteOffset"),
1743-
v8::Integer::NewFromUnsigned(
1746+
Integer::NewFromUnsigned(
17441747
env()->isolate(),
17451748
static_cast<uint32_t>(impl_->stats_slot_.GetByteOffset())));
17461749
}
@@ -2127,8 +2130,8 @@ void Session::EmitQlog(uint32_t flags, std::string_view data) {
21272130
// ngtcp2_conn is mid-destruction. Defer the final chunk via SetImmediate.
21282131
if (is_destroyed()) {
21292132
auto isolate = env()->isolate();
2130-
v8::Global<v8::Object> recv(isolate, object());
2131-
v8::Global<v8::Function> cb(
2133+
Global<Object> recv(isolate, object());
2134+
Global<Function> cb(
21322135
isolate, BindingData::Get(env()).session_qlog_callback());
21332136
std::string buf(data);
21342137
env()->SetImmediate([recv = std::move(recv),

src/quic/streams.cc

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ using v8::BackingStore;
2626
using v8::BigInt;
2727
using v8::FunctionCallbackInfo;
2828
using v8::Global;
29+
using v8::HandleScope;
2930
using v8::Integer;
3031
using v8::Just;
3132
using v8::Local;
@@ -34,6 +35,7 @@ using v8::Nothing;
3435
using v8::Object;
3536
using v8::ObjectTemplate;
3637
using v8::SharedArrayBuffer;
38+
using v8::String;
3739
using v8::Uint32;
3840
using v8::Uint8Array;
3941
using v8::Value;
@@ -277,7 +279,7 @@ Maybe<std::shared_ptr<DataQueue>> Stream::GetDataQueueFromSource(
277279
// object's constructor name is "FileHandle".
278280
if (value->IsObject()) {
279281
auto obj = value.As<Object>();
280-
Local<v8::String> ctor_name;
282+
Local<String> ctor_name;
281283
auto maybe_name = obj->GetConstructorName();
282284
if (!maybe_name.IsEmpty()) {
283285
ctor_name = maybe_name;
@@ -287,9 +289,8 @@ Maybe<std::shared_ptr<DataQueue>> Stream::GetDataQueueFromSource(
287289
ASSIGN_OR_RETURN_UNWRAP(
288290
&file_handle, value, Nothing<std::shared_ptr<DataQueue>>());
289291
Local<Value> path;
290-
if (!v8::String::NewFromUtf8(env->isolate(),
291-
file_handle->original_name().c_str())
292-
.ToLocal(&path)) {
292+
if (!ToV8Value(env->context(), file_handle->original_name())
293+
.ToLocal(&path)) {
293294
return Nothing<std::shared_ptr<DataQueue>>();
294295
}
295296
auto entry = DataQueue::CreateFdEntry(env, path);
@@ -1048,7 +1049,7 @@ Stream::Stream(BaseObjectWeakPtr<Session> session,
10481049
inbound_->addBackpressureListener(this);
10491050

10501051
{
1051-
const v8::HandleScope handle_scope(env()->isolate());
1052+
const HandleScope handle_scope(env()->isolate());
10521053
// Pass the page's shared views and this slot's byte offset. JS uses
10531054
// the offset to index into the shared view — no per-stream V8 object
10541055
// creation.
@@ -1060,7 +1061,7 @@ Stream::Stream(BaseObjectWeakPtr<Session> session,
10601061
env(),
10611062
object,
10621063
FIXED_ONE_BYTE_STRING(env()->isolate(), "stateByteOffset"),
1063-
v8::Integer::NewFromUnsigned(
1064+
Integer::NewFromUnsigned(
10641065
env()->isolate(),
10651066
static_cast<uint32_t>(state_slot_.GetByteOffset())));
10661067
JS_DEFINE_READONLY_PROPERTY(
@@ -1072,7 +1073,7 @@ Stream::Stream(BaseObjectWeakPtr<Session> session,
10721073
env(),
10731074
object,
10741075
FIXED_ONE_BYTE_STRING(env()->isolate(), "statsByteOffset"),
1075-
v8::Integer::NewFromUnsigned(
1076+
Integer::NewFromUnsigned(
10761077
env()->isolate(),
10771078
static_cast<uint32_t>(stats_slot_.GetByteOffset())));
10781079
}
@@ -1107,7 +1108,7 @@ Stream::Stream(BaseObjectWeakPtr<Session> session,
11071108
inbound_->addBackpressureListener(this);
11081109

11091110
{
1110-
const v8::HandleScope handle_scope(env()->isolate());
1111+
const HandleScope handle_scope(env()->isolate());
11111112
JS_DEFINE_READONLY_PROPERTY(env(),
11121113
object,
11131114
env()->state_string(),
@@ -1116,7 +1117,7 @@ Stream::Stream(BaseObjectWeakPtr<Session> session,
11161117
env(),
11171118
object,
11181119
FIXED_ONE_BYTE_STRING(env()->isolate(), "stateByteOffset"),
1119-
v8::Integer::NewFromUnsigned(
1120+
Integer::NewFromUnsigned(
11201121
env()->isolate(),
11211122
static_cast<uint32_t>(state_slot_.GetByteOffset())));
11221123
JS_DEFINE_READONLY_PROPERTY(
@@ -1128,7 +1129,7 @@ Stream::Stream(BaseObjectWeakPtr<Session> session,
11281129
env(),
11291130
object,
11301131
FIXED_ONE_BYTE_STRING(env()->isolate(), "statsByteOffset"),
1131-
v8::Integer::NewFromUnsigned(
1132+
Integer::NewFromUnsigned(
11321133
env()->isolate(),
11331134
static_cast<uint32_t>(stats_slot_.GetByteOffset())));
11341135
}

src/quic/tlscontext.cc

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,13 +30,16 @@ using ncrypto::SSLCtxPointer;
3030
using ncrypto::SSLPointer;
3131
using ncrypto::SSLSessionPointer;
3232
using ncrypto::X509Pointer;
33+
using v8::Array;
3334
using v8::ArrayBuffer;
35+
using v8::ArrayBufferView;
3436
using v8::Just;
3537
using v8::Local;
3638
using v8::Maybe;
3739
using v8::MaybeLocal;
3840
using v8::Nothing;
3941
using v8::Object;
42+
using v8::String;
4043
using v8::Undefined;
4144
using v8::Value;
4245

@@ -95,7 +98,7 @@ template <typename T, typename Opt, std::vector<T> Opt::*member>
9598
bool SetOption(Environment* env,
9699
Opt* options,
97100
const Local<Object>& object,
98-
const Local<v8::String>& name) {
101+
const Local<String>& name) {
99102
Local<Value> value;
100103
if (!object->Get(env->context(), name).ToLocal(&value)) return false;
101104

@@ -105,7 +108,7 @@ bool SetOption(Environment* env,
105108

106109
if (value->IsArray()) {
107110
auto context = env->context();
108-
auto values = value.As<v8::Array>();
111+
auto values = value.As<Array>();
109112
uint32_t count = values->Length();
110113
for (uint32_t n = 0; n < count; n++) {
111114
Local<Value> item;
@@ -125,7 +128,7 @@ bool SetOption(Environment* env,
125128
}
126129
} else if constexpr (std::is_same<T, Store>::value) {
127130
if (item->IsArrayBufferView()) {
128-
Store store = Store::CopyFrom(item.As<v8::ArrayBufferView>());
131+
Store store = Store::CopyFrom(item.As<ArrayBufferView>());
129132
(options->*member).push_back(std::move(store));
130133
} else if (item->IsArrayBuffer()) {
131134
Store store = Store::CopyFrom(item.As<ArrayBuffer>());
@@ -154,7 +157,7 @@ bool SetOption(Environment* env,
154157
}
155158
} else if constexpr (std::is_same<T, Store>::value) {
156159
if (value->IsArrayBufferView()) {
157-
Store store = Store::CopyFrom(value.As<v8::ArrayBufferView>());
160+
Store store = Store::CopyFrom(value.As<ArrayBufferView>());
158161
(options->*member).push_back(std::move(store));
159162
} else if (value->IsArrayBuffer()) {
160163
Store store = Store::CopyFrom(value.As<ArrayBuffer>());

0 commit comments

Comments
 (0)