Skip to content

Commit b7fc072

Browse files
committed
cli: add --experimental flag
Signed-off-by: Paolo Insogna <paolo@cowtech.it>
1 parent 3f52482 commit b7fc072

File tree

9 files changed

+63
-12
lines changed

9 files changed

+63
-12
lines changed

doc/api/cli.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1033,6 +1033,16 @@ and `"` are usable.
10331033
It is possible to run code containing inline types unless the
10341034
[`--no-strip-types`][] flag is provided.
10351035

1036+
### `--experimental`
1037+
1038+
<!-- YAML
1039+
added:
1040+
- REPLACEME
1041+
-->
1042+
1043+
Enable all command-line experimental features that are otherwise gated behind
1044+
individual `--experimental-*` flags.
1045+
10361046
### `--experimental-addon-modules`
10371047

10381048
<!-- YAML
@@ -3700,6 +3710,7 @@ one is included in the list below.
37003710
* `--experimental-top-level-await`
37013711
* `--experimental-vm-modules`
37023712
* `--experimental-wasi-unstable-preview1`
3713+
* `--experimental`
37033714
* `--force-context-aware`
37043715
* `--force-fips`
37053716
* `--force-node-api-uncaught-exceptions-policy`

doc/node.1

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -620,6 +620,10 @@ and \fB"\fR are usable.
620620
It is possible to run code containing inline types unless the
621621
\fB--no-strip-types\fR flag is provided.
622622
.
623+
.It Fl -experimental
624+
Enable all command-line experimental features that are otherwise gated behind
625+
individual \fB--experimental-*\fR flags.
626+
.
623627
.It Fl -experimental-addon-modules
624628
Enable experimental import support for \fB.node\fR addons.
625629
.
@@ -1899,6 +1903,8 @@ one is included in the list below.
18991903
.It
19001904
\fB--entry-url\fR
19011905
.It
1906+
\fB--experimental\fR
1907+
.It
19021908
\fB--experimental-abortcontroller\fR
19031909
.It
19041910
\fB--experimental-addon-modules\fR

lib/internal/options.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ const {
77
ObjectFromEntries,
88
ObjectKeys,
99
StringPrototypeReplace,
10+
StringPrototypeStartsWith,
1011
} = primordials;
1112

1213
const {
@@ -148,7 +149,14 @@ function refreshOptions() {
148149
}
149150

150151
function getOptionValue(optionName) {
151-
return getCLIOptionsFromBinding()[optionName];
152+
const options = getCLIOptionsFromBinding();
153+
let value = options[optionName];
154+
155+
if (!value && StringPrototypeStartsWith(optionName, '--experimental-') && options['--experimental']) {
156+
value = options['--experimental'];
157+
}
158+
159+
return value;
152160
}
153161

154162
function getAllowUnauthorized() {

src/api/environment.cc

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -268,14 +268,16 @@ void SetIsolateMiscHandlers(v8::Isolate* isolate, const IsolateSettings& s) {
268268
modify_code_generation_from_strings_callback);
269269

270270
Mutex::ScopedLock lock(node::per_process::cli_options_mutex);
271-
if (per_process::cli_options->get_per_isolate_options()
272-
->get_per_env_options()
273-
->experimental_fetch) {
271+
EnvironmentOptions* options =
272+
per_process::cli_options->get_per_isolate_options()
273+
->get_per_env_options();
274+
if (options->experimental_fetch || options->experimental) {
274275
isolate->SetWasmStreamingCallback(wasm_web_api::StartStreamingCompilation);
275276
}
276277

277278
if (per_process::cli_options->get_per_isolate_options()
278-
->experimental_shadow_realm) {
279+
->experimental_shadow_realm ||
280+
options->experimental) {
279281
isolate->SetHostCreateShadowRealmContextCallback(
280282
shadow_realm::HostCreateShadowRealmContextCallback);
281283
}

src/inspector/network_agent.cc

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -404,11 +404,12 @@ protocol::DispatchResponse NetworkAgent::loadNetworkResource(
404404
const protocol::String& in_url,
405405
std::unique_ptr<protocol::Network::LoadNetworkResourcePageResult>*
406406
out_resource) {
407-
if (!env_->options()->experimental_inspector_network_resource) {
407+
if (!env_->options()->experimental_inspector_network_resource &&
408+
!env_->options()->experimental) {
408409
return protocol::DispatchResponse::ServerError(
409410
"Network resource loading is not enabled. This feature is "
410411
"experimental and requires --experimental-inspector-network-resource "
411-
"flag to be set.");
412+
"or --experimental flag to be set.");
412413
}
413414
CHECK_NOT_NULL(network_resource_manager_);
414415
std::string data = network_resource_manager_->Get(in_url);

src/inspector_agent.cc

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,8 @@ class ChannelImpl final : public v8_inspector::V8Inspector::Channel,
247247
}
248248
runtime_agent_ = std::make_unique<protocol::RuntimeAgent>();
249249
runtime_agent_->Wire(node_dispatcher_.get());
250-
if (env->options()->experimental_inspector_network_resource) {
250+
if (env->options()->experimental_inspector_network_resource ||
251+
env->options()->experimental) {
251252
io_agent_ = std::make_unique<protocol::IoAgent>(
252253
env->inspector_agent()->GetNetworkResourceManager());
253254
io_agent_->Wire(node_dispatcher_.get());
@@ -260,12 +261,14 @@ class ChannelImpl final : public v8_inspector::V8Inspector::Channel,
260261
std::make_unique<NetworkInspector>(env, inspector.get(), nullptr);
261262
}
262263
network_inspector_->Wire(node_dispatcher_.get());
263-
if (env->options()->experimental_worker_inspection) {
264+
if (env->options()->experimental_worker_inspection ||
265+
env->options()->experimental) {
264266
target_agent_ = std::make_shared<protocol::TargetAgent>();
265267
target_agent_->Wire(node_dispatcher_.get());
266268
target_agent_->listenWorker(worker_manager);
267269
}
268-
if (env->options()->experimental_storage_inspection) {
270+
if (env->options()->experimental_storage_inspection ||
271+
env->options()->experimental) {
269272
dom_storage_agent_ = std::make_unique<DOMStorageAgent>(env);
270273
dom_storage_agent_->Wire(node_dispatcher_.get());
271274
storage_agent_ = std::make_unique<protocol::StorageAgent>(env_);
@@ -304,11 +307,13 @@ class ChannelImpl final : public v8_inspector::V8Inspector::Channel,
304307
std::string domain_name = raw_event.substr(0, raw_event.find('.'));
305308
std::string event_name = raw_event.substr(raw_event.find('.') + 1);
306309
if (network_inspector_->canEmit(domain_name) &&
307-
env_->options()->experimental_network_inspection) {
310+
(env_->options()->experimental_network_inspection ||
311+
env_->options()->experimental)) {
308312
network_inspector_->emitNotification(
309313
context, domain_name, event_name, params);
310314
} else if (dom_storage_agent_ && dom_storage_agent_->canEmit(domain_name) &&
311-
env_->options()->experimental_storage_inspection) {
315+
(env_->options()->experimental_storage_inspection ||
316+
env_->options()->experimental)) {
312317
dom_storage_agent_->emitNotification(context, event_name, params);
313318
}
314319
}

src/node_options.cc

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -581,6 +581,10 @@ EnvironmentOptionsParser::EnvironmentOptionsParser() {
581581
"experimental import support for addons",
582582
&EnvironmentOptions::experimental_addon_modules,
583583
kAllowedInEnvvar);
584+
AddOption("--experimental",
585+
"",
586+
&EnvironmentOptions::experimental,
587+
kAllowedInEnvvar);
584588
AddOption("--experimental-abortcontroller", "", NoOp{}, kAllowedInEnvvar);
585589
AddOption("--experimental-eventsource",
586590
"experimental EventSource API",

src/node_options.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,7 @@ class EnvironmentOptions : public Options {
122122
bool require_module = true;
123123
std::string dns_result_order;
124124
bool enable_source_maps = false;
125+
bool experimental = false;
125126
bool experimental_addon_modules = false;
126127
bool experimental_eventsource = false;
127128
bool experimental_fetch = true;
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// Flags: --experimental
2+
'use strict';
3+
4+
// This test replicates the test in test/parallel/test-eventsource.js,
5+
// but with the --experimental flag enabled instead of --experimental-eventsource.
6+
// This tests that the experimental flag implicitly enables the eventsource experimental feature.
7+
// When eventsource is no longer experimental, this test should be updated to pick a
8+
// different experimental feature to test against.
9+
10+
require('../common');
11+
const assert = require('assert');
12+
13+
assert.strictEqual(typeof EventSource, 'function');

0 commit comments

Comments
 (0)