Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit a31a8ee

Browse filesBrowse files
jasnelladuh95
authored andcommitted
quic: reduce boilerplate and other minor cleanups
While I get that macros aren't the most loved thing in the world, they do help reduce boilerplate, and there's a lot of boilerplate in the QUIC code. This commit cleans up some of that boilerplate, particularly around the use of v8 APIs. PR-URL: #59342 Reviewed-By: Stephen Belanger <admin@stephenbelanger.com> Reviewed-By: Ethan Arrowood <ethan@arrowood.dev>
1 parent 3be70ff commit a31a8ee
Copy full SHA for a31a8ee

33 files changed

+291-418Lines changed: 291 additions & 418 deletions
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎doc/api/cli.md‎

Copy file name to clipboardExpand all lines: doc/api/cli.md
+1-10Lines changed: 1 addition & 10 deletions
  • Display the source diff
  • Display the rich diff
Original file line numberDiff line numberDiff line change
@@ -1822,16 +1822,6 @@ added: v21.2.0
18221822
18231823
Disable exposition of [Navigator API][] on the global scope.
18241824

1825-
### `--no-experimental-quic`
1826-
1827-
<!-- YAML
1828-
added: REPLACEME
1829-
-->
1830-
1831-
> Stability: 1.1 - Active Development
1832-
1833-
Use this flag to disable QUIC.
1834-
18351825
### `--no-experimental-repl-await`
18361826

18371827
<!-- YAML
@@ -3499,6 +3489,7 @@ one is included in the list below.
34993489
* `--experimental-loader`
35003490
* `--experimental-modules`
35013491
* `--experimental-print-required-tla`
3492+
* `--experimental-quic`
35023493
* `--experimental-require-module`
35033494
* `--experimental-shadow-realm`
35043495
* `--experimental-specifier-resolution`
Collapse file

‎doc/node.1‎

Copy file name to clipboardExpand all lines: doc/node.1
-3Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -229,9 +229,6 @@ flag is no longer required as WASI is enabled by default.
229229
.It Fl -experimental-quic
230230
Enable the experimental QUIC support.
231231
.
232-
.It Fl -no-experimental-quic
233-
Disable the experimental QUIC support.
234-
.
235232
.It Fl -experimental-inspector-network-resource
236233
Enable experimental support for inspector network resources.
237234
.
Collapse file

‎lib/internal/quic/quic.js‎

Copy file name to clipboardExpand all lines: lib/internal/quic/quic.js
+7-4Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,14 @@ const {
1515
Uint8Array,
1616
} = primordials;
1717

18-
// QUIC requires that Node.js be compiled with crypto support.
1918
const {
20-
assertCrypto,
21-
} = require('internal/util');
22-
assertCrypto();
19+
getOptionValue,
20+
} = require('internal/options');
21+
22+
// QUIC requires that Node.js be compiled with crypto support.
23+
if (!process.features.quic || !getOptionValue('--experimental-quic')) {
24+
return;
25+
}
2326

2427
const { inspect } = require('internal/util/inspect');
2528

Collapse file

‎lib/internal/quic/state.js‎

Copy file name to clipboardExpand all lines: lib/internal/quic/state.js
+8Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,14 @@ const {
1010
JSONStringify,
1111
} = primordials;
1212

13+
const {
14+
getOptionValue,
15+
} = require('internal/options');
16+
17+
if (!process.features.quic || !getOptionValue('--experimental-quic')) {
18+
return;
19+
}
20+
1321
const {
1422
codes: {
1523
ERR_ILLEGAL_CONSTRUCTOR,
Collapse file

‎lib/internal/quic/stats.js‎

Copy file name to clipboardExpand all lines: lib/internal/quic/stats.js
+8Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,14 @@ const {
55
JSONStringify,
66
} = primordials;
77

8+
const {
9+
getOptionValue,
10+
} = require('internal/options');
11+
12+
if (!process.features.quic || !getOptionValue('--experimental-quic')) {
13+
return;
14+
}
15+
816
const {
917
isArrayBuffer,
1018
} = require('util/types');
Collapse file

‎lib/internal/quic/symbols.js‎

Copy file name to clipboardExpand all lines: lib/internal/quic/symbols.js
+8Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,14 @@ const {
44
Symbol,
55
} = primordials;
66

7+
const {
8+
getOptionValue,
9+
} = require('internal/options');
10+
11+
if (!process.features.quic || !getOptionValue('--experimental-quic')) {
12+
return;
13+
}
14+
715
const {
816
customInspectSymbol: kInspect,
917
} = require('internal/util');
Collapse file

‎src/node_metadata.h‎

Copy file name to clipboardExpand all lines: src/node_metadata.h
+2-9Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,8 @@ namespace node {
6060
V(simdutf) \
6161
V(ada) \
6262
V(nbytes) \
63+
V(ngtcp2) \
64+
V(nghttp3) \
6365
NODE_VERSIONS_KEY_AMARO(V) \
6466
NODE_VERSIONS_KEY_UNDICI(V) \
6567
V(merve)
@@ -80,14 +82,6 @@ namespace node {
8082
#define NODE_VERSIONS_KEY_INTL(V)
8183
#endif // NODE_HAVE_I18N_SUPPORT
8284

83-
#ifndef OPENSSL_NO_QUIC
84-
#define NODE_VERSIONS_KEY_QUIC(V) \
85-
V(ngtcp2) \
86-
V(nghttp3)
87-
#else
88-
#define NODE_VERSIONS_KEY_QUIC(V)
89-
#endif
90-
9185
#if HAVE_SQLITE
9286
#define NODE_VERSIONS_KEY_SQLITE(V) V(sqlite)
9387
#else
@@ -98,7 +92,6 @@ namespace node {
9892
NODE_VERSIONS_KEYS_BASE(V) \
9993
NODE_VERSIONS_KEY_CRYPTO(V) \
10094
NODE_VERSIONS_KEY_INTL(V) \
101-
NODE_VERSIONS_KEY_QUIC(V) \
10295
NODE_VERSIONS_KEY_SQLITE(V)
10396

10497
#define V(key) +1
Collapse file

‎src/node_options.cc‎

Copy file name to clipboardExpand all lines: src/node_options.cc
+2-1Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -565,10 +565,11 @@ EnvironmentOptionsParser::EnvironmentOptionsParser() {
565565
kAllowedInEnvvar,
566566
true);
567567
AddOption("--experimental-quic",
568-
"" /* undocumented until its development */,
569568
#ifndef OPENSSL_NO_QUIC
569+
"experimental QUIC support",
570570
&EnvironmentOptions::experimental_quic,
571571
#else
572+
"" /* undocumented when no-op */,
572573
NoOp{},
573574
#endif
574575
kAllowedInEnvvar);
Collapse file

‎src/quic/bindingdata.cc‎

Copy file name to clipboardExpand all lines: src/quic/bindingdata.cc
+3-4Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
namespace node {
1818

1919
using v8::Function;
20-
using v8::FunctionCallbackInfo;
2120
using v8::FunctionTemplate;
2221
using v8::Local;
2322
using v8::Object;
@@ -144,7 +143,7 @@ QUIC_JS_CALLBACKS(V)
144143

145144
#undef V
146145

147-
void BindingData::SetCallbacks(const FunctionCallbackInfo<Value>& args) {
146+
JS_METHOD_IMPL(BindingData::SetCallbacks) {
148147
auto env = Environment::GetCurrent(args);
149148
auto isolate = env->isolate();
150149
auto& state = Get(env);
@@ -166,7 +165,7 @@ void BindingData::SetCallbacks(const FunctionCallbackInfo<Value>& args) {
166165
#undef V
167166
}
168167

169-
void BindingData::FlushPacketFreelist(const FunctionCallbackInfo<Value>& args) {
168+
JS_METHOD_IMPL(BindingData::FlushPacketFreelist) {
170169
auto env = Environment::GetCurrent(args);
171170
auto& state = Get(env);
172171
state.packet_freelist.clear();
@@ -217,7 +216,7 @@ CallbackScopeBase::~CallbackScopeBase() {
217216
}
218217
}
219218

220-
void IllegalConstructor(const FunctionCallbackInfo<Value>& args) {
219+
JS_METHOD_IMPL(IllegalConstructor) {
221220
THROW_ERR_ILLEGAL_CONSTRUCTOR(Environment::GetCurrent(args));
222221
}
223222

Collapse file

‎src/quic/bindingdata.h‎

Copy file name to clipboardExpand all lines: src/quic/bindingdata.h
+5-6Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -167,16 +167,15 @@ class BindingData final
167167

168168
// Installs the set of JavaScript callback functions that are used to
169169
// bridge out to the JS API.
170-
static void SetCallbacks(const v8::FunctionCallbackInfo<v8::Value>& args);
170+
JS_METHOD(SetCallbacks);
171+
172+
// Purge the packet free list to free up memory.
173+
JS_METHOD(FlushPacketFreelist);
171174

172175
std::vector<BaseObjectPtr<BaseObject>> packet_freelist;
173176

174177
std::unordered_map<Endpoint*, BaseObjectPtr<BaseObject>> listening_endpoints;
175178

176-
// Purge the packet free list to free up memory.
177-
static void FlushPacketFreelist(
178-
const v8::FunctionCallbackInfo<v8::Value>& args);
179-
180179
bool in_ngtcp2_callback_scope = false;
181180
bool in_nghttp3_callback_scope = false;
182181
size_t current_ngtcp2_memory_ = 0;
@@ -223,7 +222,7 @@ class BindingData final
223222
#undef V
224223
};
225224

226-
void IllegalConstructor(const v8::FunctionCallbackInfo<v8::Value>& args);
225+
JS_METHOD_IMPL(IllegalConstructor);
227226

228227
// The ngtcp2 and nghttp3 callbacks have certain restrictions
229228
// that forbid re-entry. We provide the following scopes for

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.