quic: fixup some v8:: qualifiers · nodejs/node@f8a1fda · GitHub
Skip to content

Commit f8a1fda

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

6 files changed

Lines changed: 57 additions & 35 deletions

File tree

src/quic/bindingdata.cc

Lines changed: 2 additions & 1 deletion

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(
@@ -1726,7 +1729,7 @@ Session::Session(Endpoint* endpoint,
17261729
Debug(this, "Session created.");
17271730

17281731
{
1729-
const v8::HandleScope handle_scope(env()->isolate());
1732+
const HandleScope handle_scope(env()->isolate());
17301733
JS_DEFINE_READONLY_PROPERTY(
17311734
env(),
17321735
object,
@@ -1736,7 +1739,7 @@ Session::Session(Endpoint* endpoint,
17361739
env(),
17371740
object,
17381741
FIXED_ONE_BYTE_STRING(env()->isolate(), "stateByteOffset"),
1739-
v8::Integer::NewFromUnsigned(
1742+
Integer::NewFromUnsigned(
17401743
env()->isolate(),
17411744
static_cast<uint32_t>(impl_->state_slot_.GetByteOffset())));
17421745
JS_DEFINE_READONLY_PROPERTY(
@@ -1748,7 +1751,7 @@ Session::Session(Endpoint* endpoint,
17481751
env(),
17491752
object,
17501753
FIXED_ONE_BYTE_STRING(env()->isolate(), "statsByteOffset"),
1751-
v8::Integer::NewFromUnsigned(
1754+
Integer::NewFromUnsigned(
17521755
env()->isolate(),
17531756
static_cast<uint32_t>(impl_->stats_slot_.GetByteOffset())));
17541757
}
@@ -2135,8 +2138,8 @@ void Session::EmitQlog(uint32_t flags, std::string_view data) {
21352138
// ngtcp2_conn is mid-destruction. Defer the final chunk via SetImmediate.
21362139
if (is_destroyed()) {
21372140
auto isolate = env()->isolate();
2138-
v8::Global<v8::Object> recv(isolate, object());
2139-
v8::Global<v8::Function> cb(
2141+
Global<Object> recv(isolate, object());
2142+
Global<Function> cb(
21402143
isolate, BindingData::Get(env()).session_qlog_callback());
21412144
std::string buf(data);
21422145
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

0 commit comments

Comments
 (0)