Skip to content

Commit

Permalink
experimental-event-loop -> event-loop
Browse files Browse the repository at this point in the history
  • Loading branch information
jeffcharles committed Nov 26, 2024
1 parent c91eca7 commit 63e6d85
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 34 deletions.
9 changes: 3 additions & 6 deletions crates/cli/tests/integration_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -183,10 +183,7 @@ fn test_readme_script(builder: &mut Builder) -> Result<()> {

#[javy_cli_test(commands(not(Compile)))]
fn test_promises_with_event_loop(builder: &mut Builder) -> Result<()> {
let mut runner = builder
.input("promise.js")
.experimental_event_loop(true)
.build()?;
let mut runner = builder.input("promise.js").event_loop(true).build()?;

let (output, _, _) = run(&mut runner, &[]);
assert_eq!("\"foo\"\"bar\"".as_bytes(), output);
Expand All @@ -209,7 +206,7 @@ fn test_promises_without_event_loop(builder: &mut Builder) -> Result<()> {
fn test_promise_top_level_await(builder: &mut Builder) -> Result<()> {
let mut runner = builder
.input("top-level-await.js")
.experimental_event_loop(true)
.event_loop(true)
.build()?;
let (out, _, _) = run(&mut runner, &[]);

Expand Down Expand Up @@ -238,7 +235,7 @@ fn test_exported_promises(builder: &mut Builder) -> Result<()> {
.input("exported-promise-fn.js")
.wit("exported-promise-fn.wit")
.world("exported-promise-fn")
.experimental_event_loop(true)
.event_loop(true)
.build()?;
let (_, logs, _) = run_fn(&mut runner, "foo", &[]);
assert_eq!("Top-level\ninside foo\n", logs);
Expand Down
10 changes: 5 additions & 5 deletions crates/plugin-api/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@ use std::ops::{Deref, DerefMut};
pub struct Config {
/// The runtime config.
pub(crate) runtime_config: javy::Config,
/// Whether to enable the experimental event loop.
pub(crate) experimental_event_loop: bool,
/// Whether to enable the event loop.
pub(crate) event_loop: bool,
}

impl Config {
/// Whether to enable the experimental event loop.
pub fn experimental_event_loop(&mut self, enabled: bool) -> &mut Self {
self.experimental_event_loop = enabled;
/// Whether to enable the event loop.
pub fn event_loop(&mut self, enabled: bool) -> &mut Self {
self.event_loop = enabled;
self
}
}
Expand Down
6 changes: 3 additions & 3 deletions crates/plugin-api/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ static mut EVENT_LOOP_ENABLED: bool = false;
static EVENT_LOOP_ERR: &str = r#"
Pending jobs in the event queue.
Scheduling events is not supported when the
experimental_event_loop cargo feature is disabled.
event-loop runtime config is not enabled.
"#;

/// Initializes the Javy runtime.
Expand All @@ -74,7 +74,7 @@ where
// implement `Debug`.
.map_err(|_| anyhow!("Could not pre-initialize javy::Runtime"))
.unwrap();
EVENT_LOOP_ENABLED = config.experimental_event_loop;
EVENT_LOOP_ENABLED = config.event_loop;
};
Ok(())
}
Expand Down Expand Up @@ -185,7 +185,7 @@ fn handle_maybe_promise(this: Ctx, value: Value) -> quickjs::Result<()> {
match value.as_promise() {
Some(promise) => {
if unsafe { EVENT_LOOP_ENABLED } {
// If the experimental event loop is enabled, trigger it.
// If the event loop is enabled, trigger it.
let resolved = promise.finish::<Value>();
// `Promise::finish` returns Err(Wouldblock) when the all
// pending jobs have been handled.
Expand Down
8 changes: 4 additions & 4 deletions crates/plugin/src/shared_config/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ runtime_config! {
/// Whether to enable support for the `TextEncoder` and `TextDecoder`
/// APIs.
text_encoding: Option<bool>,
/// Whether to enable the experimental event loop.
experimental_event_loop: Option<bool>,
/// Whether to enable the event loop.
event_loop: Option<bool>,
}
}

Expand All @@ -52,8 +52,8 @@ impl SharedConfig {
if let Some(enable) = self.text_encoding {
config.text_encoding(enable);
}
if let Some(enable) = self.experimental_event_loop {
config.experimental_event_loop(enable);
if let Some(enable) = self.event_loop {
config.event_loop(enable);
}
}
}
Expand Down
27 changes: 12 additions & 15 deletions crates/runner/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,8 @@ pub struct Builder {
simd_json_builtins: Option<bool>,
/// Whether to enable the `TextEncoder` and `TextDecoder` APIs.
text_encoding: Option<bool>,
/// Whether to enable the experimental event loop.
experimental_event_loop: Option<bool>,
/// Whether to enable the event loop.
event_loop: Option<bool>,
built: bool,
/// Preload the module at path, using the given instance name.
preload: Option<(String, PathBuf)>,
Expand All @@ -111,7 +111,7 @@ impl Default for Builder {
javy_json: None,
simd_json_builtins: None,
text_encoding: None,
experimental_event_loop: None,
event_loop: None,
plugin: Plugin::Default,
}
}
Expand Down Expand Up @@ -173,8 +173,8 @@ impl Builder {
self
}

pub fn experimental_event_loop(&mut self, enabled: bool) -> &mut Self {
self.experimental_event_loop = Some(enabled);
pub fn event_loop(&mut self, enabled: bool) -> &mut Self {
self.event_loop = Some(enabled);
self
}

Expand Down Expand Up @@ -210,7 +210,7 @@ impl Builder {
javy_stream_io,
simd_json_builtins,
text_encoding,
experimental_event_loop,
event_loop,
built: _,
preload,
command,
Expand Down Expand Up @@ -238,7 +238,7 @@ impl Builder {
javy_stream_io,
simd_json_builtins,
text_encoding,
experimental_event_loop,
event_loop,
preload,
plugin,
),
Expand Down Expand Up @@ -315,7 +315,7 @@ impl Runner {
javy_stream_io: Option<bool>,
override_json_parse_and_stringify: Option<bool>,
text_encoding: Option<bool>,
experimental_event_loop: Option<bool>,
event_loop: Option<bool>,
preload: Option<(String, PathBuf)>,
plugin: Plugin,
) -> Result<Self> {
Expand All @@ -337,7 +337,7 @@ impl Runner {
&javy_stream_io,
&override_json_parse_and_stringify,
&text_encoding,
&experimental_event_loop,
&event_loop,
&plugin,
);

Expand Down Expand Up @@ -566,7 +566,7 @@ impl Runner {
javy_stream_io: &Option<bool>,
simd_json_builtins: &Option<bool>,
text_encoding: &Option<bool>,
experimental_event_loop: &Option<bool>,
event_loop: &Option<bool>,
plugin: &Plugin,
) -> Vec<String> {
let mut args = vec![
Expand Down Expand Up @@ -622,12 +622,9 @@ impl Runner {
args.push(format!("text-encoding={}", if enabled { "y" } else { "n" }));
}

if let Some(enabled) = *experimental_event_loop {
if let Some(enabled) = *event_loop {
args.push("-J".to_string());
args.push(format!(
"experimental-event-loop={}",
if enabled { "y" } else { "n" }
));
args.push(format!("event-loop={}", if enabled { "y" } else { "n" }));
}

if matches!(plugin, Plugin::User | Plugin::DefaultAsUser) {
Expand Down
2 changes: 1 addition & 1 deletion wpt/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"type": "module",
"scripts": {
"bundle": "rollup -c rollup.config.js runner.js",
"javy": "../target/release/javy build -J experimental-event-loop -o bundle.wasm bundle.js",
"javy": "../target/release/javy build -J event-loop -o bundle.wasm bundle.js",
"wasmtime": "wasmtime bundle.wasm",
"test": "npm run bundle && npm run javy && npm run wasmtime"
},
Expand Down

0 comments on commit 63e6d85

Please sign in to comment.