Skip to content

Commit 1e684ca

Browse files
committed
quic: Move dataqueue feeder to queue
1 parent 6642fb5 commit 1e684ca

File tree

8 files changed

+92
-63
lines changed

8 files changed

+92
-63
lines changed

lib/internal/quic/quic.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@ const {
3434
Endpoint: Endpoint_,
3535
Http3Application: Http3,
3636
setCallbacks,
37-
DataQueueFeeder,
3837

3938
// The constants to be exposed to end users for various options.
4039
CC_ALGO_RENO_STR: CC_ALGO_RENO,
@@ -58,6 +57,10 @@ const {
5857
CLOSECONTEXT_START_FAILURE: kCloseContextStartFailure,
5958
} = internalBinding('quic');
6059

60+
const {
61+
DataQueueFeeder,
62+
} = internalBinding('dataqueuefeeder');
63+
6164
const {
6265
isArrayBuffer,
6366
isArrayBufferView,

src/dataqueue/queue.cc

Lines changed: 59 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,14 @@
1818
#include <memory>
1919
#include <vector>
2020

21-
#include "../quic/streams.h"
22-
2321
namespace node {
2422

25-
using quic::BindingData;
2623
using v8::ArrayBuffer;
2724
using v8::ArrayBufferView;
2825
using v8::BackingStore;
26+
using v8::FunctionCallbackInfo;
27+
using v8::FunctionTemplate;
28+
using v8::Isolate;
2929
using v8::Local;
3030
using v8::Object;
3131
using v8::ObjectTemplate;
@@ -1303,13 +1303,13 @@ void DataQueueFeeder::DrainAndClose() {
13031303
}
13041304
}
13051305

1306-
JS_METHOD_IMPL(DataQueueFeeder::New) {
1306+
void DataQueueFeeder::New(const FunctionCallbackInfo<Value>& args) {
13071307
DCHECK(args.IsConstructCall());
13081308
auto env = Environment::GetCurrent(args);
13091309
new DataQueueFeeder(env, args.This());
13101310
}
13111311

1312-
JS_METHOD_IMPL(DataQueueFeeder::Ready) {
1312+
void DataQueueFeeder::Ready(const FunctionCallbackInfo<Value>& args) {
13131313
Environment* env = Environment::GetCurrent(args);
13141314
DataQueueFeeder* feeder;
13151315
ASSIGN_OR_RETURN_UNWRAP(&feeder, args.This());
@@ -1325,7 +1325,7 @@ JS_METHOD_IMPL(DataQueueFeeder::Ready) {
13251325
}
13261326
}
13271327

1328-
JS_METHOD_IMPL(DataQueueFeeder::Submit) {
1328+
void DataQueueFeeder::Submit(const FunctionCallbackInfo<Value>& args) {
13291329
Environment* env = Environment::GetCurrent(args);
13301330
DataQueueFeeder* feeder;
13311331
ASSIGN_OR_RETURN_UNWRAP(&feeder, args.This());
@@ -1356,7 +1356,15 @@ JS_METHOD_IMPL(DataQueueFeeder::Submit) {
13561356
// there may be also troubles, if multiple Uint8Array
13571357
// are derived in a parser from a single ArrayBuffer
13581358
size_t nread = typedArray->ByteLength();
1359-
JS_TRY_ALLOCATE_BACKING(env, backingUniq, nread);
1359+
auto backingUniq = v8::ArrayBuffer::NewBackingStore(
1360+
env->isolate(),
1361+
nread,
1362+
v8::BackingStoreInitializationMode::kUninitialized,
1363+
v8::BackingStoreOnFailureMode::kReturnNull);
1364+
if (!backingUniq) {
1365+
THROW_ERR_MEMORY_ALLOCATION_FAILED(env);
1366+
return;
1367+
}
13601368
std::shared_ptr<BackingStore> backing = std::move(backingUniq);
13611369

13621370
auto originalStore = typedArray->Buffer()->GetBackingStore();
@@ -1392,15 +1400,15 @@ JS_METHOD_IMPL(DataQueueFeeder::Submit) {
13921400
}
13931401
}
13941402

1395-
JS_METHOD_IMPL(DataQueueFeeder::Error) {
1403+
void DataQueueFeeder::Error(const FunctionCallbackInfo<Value>& args) {
13961404
DataQueueFeeder* feeder;
13971405
ASSIGN_OR_RETURN_UNWRAP(&feeder, args.This());
13981406
// FIXME, how should I pass on the error
13991407
// ResetStream must be send also
14001408
feeder->DrainAndClose();
14011409
}
14021410

1403-
JS_METHOD_IMPL(DataQueueFeeder::AddFakePull) {
1411+
void DataQueueFeeder::AddFakePull(const FunctionCallbackInfo<Value>& args) {
14041412
DataQueueFeeder* feeder;
14051413
ASSIGN_OR_RETURN_UNWRAP(&feeder, args.This());
14061414
// this adds a fake pull for testing code, not to be used anywhere else
@@ -1411,36 +1419,56 @@ JS_METHOD_IMPL(DataQueueFeeder::AddFakePull) {
14111419
feeder->tryWakePulls();
14121420
}
14131421

1414-
JS_CONSTRUCTOR_IMPL(DataQueueFeeder, dataqueuefeeder_constructor_template, {
1415-
auto isolate = env->isolate();
1416-
JS_NEW_CONSTRUCTOR();
1417-
JS_INHERIT(AsyncWrap);
1418-
JS_CLASS(dataqueuefeeder);
1419-
SetProtoMethod(isolate, tmpl, "error", Error);
1420-
SetProtoMethod(isolate, tmpl, "submit", Submit);
1421-
SetProtoMethod(isolate, tmpl, "ready", Ready);
1422-
SetProtoMethod(isolate, tmpl, "addFakePull", AddFakePull);
1423-
})
1424-
1425-
void DataQueueFeeder::InitPerIsolate(IsolateData* data,
1426-
Local<ObjectTemplate> target) {
1427-
// TODO(@jasnell): Implement the per-isolate state
1422+
bool DataQueueFeeder::HasInstance(Environment* env, Local<Value> object) {
1423+
return GetConstructorTemplate(env)->HasInstance(object);
14281424
}
14291425

1430-
void DataQueueFeeder::InitPerContext(Realm* realm, Local<Object> target) {
1431-
SetConstructorFunction(realm->context(),
1426+
Local<FunctionTemplate> DataQueueFeeder::GetConstructorTemplate(Environment* env) {
1427+
Local<FunctionTemplate> tmpl = env->data_queue_feeder_constructor_template();
1428+
if (tmpl.IsEmpty()) {
1429+
Isolate* isolate = env->isolate();
1430+
tmpl = NewFunctionTemplate(isolate, DataQueueFeeder::New); // second argument was nullptr
1431+
tmpl->InstanceTemplate()->SetInternalFieldCount(
1432+
BaseObject::kInternalFieldCount);
1433+
tmpl->SetClassName(FIXED_ONE_BYTE_STRING(env->isolate(), "DataQueueFeeder"));
1434+
tmpl->Inherit(AsyncWrap::GetConstructorTemplate(env));
1435+
env->set_data_queue_feeder_constructor_template(tmpl);
1436+
SetProtoMethod(isolate, tmpl, "error", Error);
1437+
SetProtoMethod(isolate, tmpl, "submit", Submit);
1438+
SetProtoMethod(isolate, tmpl, "ready", Ready);
1439+
SetProtoMethod(isolate, tmpl, "addFakePull", AddFakePull);
1440+
}
1441+
return tmpl;
1442+
}
1443+
1444+
void DataQueueFeeder::CreatePerIsolateProperties(IsolateData* isolate_data,
1445+
v8::Local<v8::ObjectTemplate> target) {
1446+
}
1447+
1448+
void DataQueueFeeder::CreatePerContextProperties(v8::Local<v8::Object> target,
1449+
v8::Local<v8::Value> unused,
1450+
v8::Local<v8::Context> context,
1451+
void* priv) {
1452+
Environment* env = Environment::GetCurrent(context);
1453+
SetConstructorFunction(context,
14321454
target,
14331455
"DataQueueFeeder",
1434-
GetConstructorTemplate(realm->env()));
1456+
GetConstructorTemplate(env),
1457+
SetConstructorFunctionFlag::NONE);
14351458
}
14361459

14371460
void DataQueueFeeder::RegisterExternalReferences(
14381461
ExternalReferenceRegistry* registry) {
1439-
registry->Register(New);
1440-
registry->Register(Submit);
1441-
registry->Register(Error);
1442-
registry->Register(Ready);
1443-
registry->Register(AddFakePull);
1462+
registry->Register(DataQueueFeeder::New);
1463+
registry->Register(DataQueueFeeder::Submit);
1464+
registry->Register(DataQueueFeeder::Error);
1465+
registry->Register(DataQueueFeeder::Ready);
1466+
registry->Register(DataQueueFeeder::AddFakePull);
14441467
}
14451468

14461469
} // namespace node
1470+
1471+
NODE_BINDING_CONTEXT_AWARE_INTERNAL(dataqueuefeeder,
1472+
node::DataQueueFeeder::CreatePerContextProperties)
1473+
NODE_BINDING_PER_ISOLATE_INIT(dataqueuefeeder, node::DataQueueFeeder::CreatePerIsolateProperties)
1474+
NODE_BINDING_EXTERNAL_REFERENCE(dataqueuefeeder, node::DataQueueFeeder::RegisterExternalReferences)

src/dataqueue/queue.h

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,6 @@
1717
#include <optional>
1818
#include <vector>
1919

20-
#include "../quic/defs.h"
21-
2220
namespace node {
2321
using v8::Local;
2422
using v8::Value;
@@ -325,8 +323,8 @@ class DataQueueFeeder final : public AsyncWrap {
325323

326324
DataQueueFeeder(Environment* env, v8::Local<v8::Object> object);
327325

328-
JS_CONSTRUCTOR(DataQueueFeeder);
329-
JS_BINDING_INIT_BOILERPLATE();
326+
static void RegisterExternalReferences(
327+
ExternalReferenceRegistry* registry);
330328

331329
static BaseObjectPtr<DataQueueFeeder> Create();
332330

@@ -352,11 +350,25 @@ class DataQueueFeeder final : public AsyncWrap {
352350
SET_MEMORY_INFO_NAME(DataQueueFeeder)
353351
SET_SELF_SIZE(DataQueueFeeder)
354352

355-
JS_METHOD(New);
356-
JS_METHOD(Submit);
357-
JS_METHOD(Error);
358-
JS_METHOD(Ready);
359-
JS_METHOD(AddFakePull);
353+
static void New(const v8::FunctionCallbackInfo<v8::Value>& args);
354+
static void Submit(const v8::FunctionCallbackInfo<v8::Value>& args);
355+
static void Error(const v8::FunctionCallbackInfo<v8::Value>& args);
356+
static void Ready(const v8::FunctionCallbackInfo<v8::Value>& args);
357+
static void AddFakePull(const v8::FunctionCallbackInfo<v8::Value>& args);
358+
359+
static v8::Local<v8::FunctionTemplate> GetConstructorTemplate(
360+
Environment* env);
361+
362+
static void CreatePerIsolateProperties(IsolateData* isolate_data,
363+
v8::Local<v8::ObjectTemplate> target);
364+
static void CreatePerContextProperties(v8::Local<v8::Object> target,
365+
v8::Local<v8::Value> unused,
366+
v8::Local<v8::Context> context,
367+
void* priv);
368+
369+
static BaseObjectPtr<DataQueueFeeder> Create(Environment* env);
370+
371+
static bool HasInstance(Environment* env, v8::Local<v8::Value> object);
360372

361373
private:
362374
std::shared_ptr<DataQueue> dataQueue_;

src/env_properties.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -394,6 +394,7 @@
394394
V(contextify_wrapper_template, v8::ObjectTemplate) \
395395
V(cpu_usage_template, v8::DictionaryTemplate) \
396396
V(crypto_key_object_handle_constructor, v8::FunctionTemplate) \
397+
V(data_queue_feeder_constructor_template, v8::FunctionTemplate) \
397398
V(env_proxy_template, v8::ObjectTemplate) \
398399
V(env_proxy_ctor_template, v8::FunctionTemplate) \
399400
V(ephemeral_key_template, v8::DictionaryTemplate) \

src/node_binding.cc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@
4747
V(constants) \
4848
V(contextify) \
4949
V(credentials) \
50+
V(dataqueuefeeder) \
5051
V(encoding_binding) \
5152
V(errors) \
5253
V(fs) \

src/quic/bindingdata.h

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,7 @@
1515
#include <unordered_map>
1616
#include "defs.h"
1717

18-
namespace node {
19-
class DataQueueFeeder;
20-
namespace quic {
18+
namespace node::quic {
2119

2220
class Endpoint;
2321
class Packet;
@@ -26,7 +24,6 @@ class Packet;
2624

2725
// The FunctionTemplates the BindingData will store for us.
2826
#define QUIC_CONSTRUCTORS(V) \
29-
V(dataqueuefeeder) \
3027
V(endpoint) \
3128
V(http3application) \
3229
V(logstream) \
@@ -71,7 +68,6 @@ class Packet;
7168
V(ciphers, "ciphers") \
7269
V(crl, "crl") \
7370
V(cubic, "cubic") \
74-
V(dataqueuefeeder, "DataQueueFeeder") \
7571
V(disable_stateless_reset, "disableStatelessReset") \
7672
V(enable_connect_protocol, "enableConnectProtocol") \
7773
V(enable_datagrams, "enableDatagrams") \
@@ -268,7 +264,6 @@ struct CallbackScope final : public CallbackScopeBase {
268264
explicit CallbackScope(T* ptr) : CallbackScopeBase(ptr->env()), ref(ptr) {}
269265
};
270266

271-
} // namespace quic
272-
} // namespace node
267+
} // namespace node::quic
273268

274269
#endif // defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS

src/quic/quic.cc

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,22 +12,19 @@
1212
#include "endpoint.h"
1313
#include "node_external_reference.h"
1414

15-
namespace node {
15+
namespace node::quic {
1616

1717
using v8::Context;
1818
using v8::Local;
1919
using v8::Object;
2020
using v8::ObjectTemplate;
2121
using v8::Value;
2222

23-
namespace quic {
24-
2523
void CreatePerIsolateProperties(IsolateData* isolate_data,
2624
Local<ObjectTemplate> target) {
2725
Endpoint::InitPerIsolate(isolate_data, target);
2826
Session::InitPerIsolate(isolate_data, target);
2927
Stream::InitPerIsolate(isolate_data, target);
30-
DataQueueFeeder::InitPerIsolate(isolate_data, target);
3128
}
3229

3330
void CreatePerContextProperties(Local<Object> target,
@@ -39,19 +36,16 @@ void CreatePerContextProperties(Local<Object> target,
3936
Endpoint::InitPerContext(realm, target);
4037
Session::InitPerContext(realm, target);
4138
Stream::InitPerContext(realm, target);
42-
DataQueueFeeder::InitPerContext(realm, target);
4339
}
4440

4541
void RegisterExternalReferences(ExternalReferenceRegistry* registry) {
4642
BindingData::RegisterExternalReferences(registry);
4743
Endpoint::RegisterExternalReferences(registry);
4844
Session::RegisterExternalReferences(registry);
4945
Stream::RegisterExternalReferences(registry);
50-
DataQueueFeeder::RegisterExternalReferences(registry);
5146
}
5247

53-
} // namespace quic
54-
} // namespace node
48+
} // namespace node::quic
5549

5650
NODE_BINDING_CONTEXT_AWARE_INTERNAL(quic,
5751
node::quic::CreatePerContextProperties)

test/parallel/test-quic-internal-dataqueuefeeder.mjs renamed to test/parallel/test-dataqueuefeeder.mjs

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,13 @@
1-
// Flags: --expose-internals --experimental-quic --no-warnings
2-
import { hasQuic, skip } from '../common/index.mjs';
1+
// Flags: --expose-internals --no-warnings
32
import {
43
rejects,
54
} from 'node:assert';
65

7-
if (!hasQuic) {
8-
skip('QUIC is not enabled');
9-
}
10-
116
const { internalBinding } = (await import('internal/test/binding')).default;
127

138
const {
149
DataQueueFeeder,
15-
} = internalBinding('quic');
10+
} = internalBinding('dataqueuefeeder');
1611

1712

1813
const feeder = new DataQueueFeeder();

0 commit comments

Comments
 (0)