From 6505b41f8a761a33dcbd9235f8f7ef10441033a7 Mon Sep 17 00:00:00 2001 From: Jeff Charles Date: Tue, 7 Jan 2025 11:49:45 -0500 Subject: [PATCH] Remove support for Javy.JSON --- Cargo.lock | 4 +- Cargo.toml | 2 +- crates/cli/src/commands.rs | 24 -------- .../dynamic-linking-scripts/javy-json-id.js | 1 - crates/cli/tests/dynamic_linking_test.rs | 19 ------- crates/cli/tests/integration_test.rs | 30 +--------- crates/javy/CHANGELOG.md | 5 ++ crates/javy/Cargo.toml | 2 +- crates/javy/src/apis/json.rs | 57 +------------------ crates/javy/src/config.rs | 10 ---- crates/javy/src/runtime.rs | 6 -- crates/plugin-api/CHANGELOG.md | 6 ++ crates/plugin-api/Cargo.toml | 2 +- crates/plugin/src/lib.rs | 3 +- crates/plugin/src/shared_config/mod.rs | 5 -- crates/runner/src/lib.rs | 18 ------ fuzz/fuzz_targets/json_differential.rs | 2 +- 17 files changed, 22 insertions(+), 174 deletions(-) delete mode 100644 crates/cli/tests/dynamic-linking-scripts/javy-json-id.js diff --git a/Cargo.lock b/Cargo.lock index 5d34fb9f..e97a2aaa 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1549,7 +1549,7 @@ dependencies = [ [[package]] name = "javy" -version = "3.1.1-alpha.1" +version = "4.0.0-alpha.1" dependencies = [ "anyhow", "bitflags", @@ -1618,7 +1618,7 @@ dependencies = [ [[package]] name = "javy-plugin-api" -version = "2.0.1-alpha.1" +version = "3.0.0-alpha.1" dependencies = [ "anyhow", "javy", diff --git a/Cargo.toml b/Cargo.toml index 600b8548..525f15e8 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -23,7 +23,7 @@ wasmtime = "23" wasmtime-wasi = "23" wasi-common = "23" anyhow = "1.0" -javy = { path = "crates/javy", version = "3.1.1-alpha.1" } +javy = { path = "crates/javy", version = "4.0.0-alpha.1" } tempfile = "3.15.0" uuid = { version = "1.11", features = ["v4"] } serde = { version = "1.0", default-features = false } diff --git a/crates/cli/src/commands.rs b/crates/cli/src/commands.rs index 882802bf..5765bf7a 100644 --- a/crates/cli/src/commands.rs +++ b/crates/cli/src/commands.rs @@ -375,7 +375,6 @@ mod tests { fn js_config_from_config_values() -> Result<()> { let group = JsConfig::from_group_values(&Plugin::Default, vec![])?; assert_eq!(group.get("redirect-stdout-to-stderr"), None); - assert_eq!(group.get("javy-json"), None); assert_eq!(group.get("javy-stream-io"), None); assert_eq!(group.get("simd-json-builtins"), None); assert_eq!(group.get("text-encoding"), None); @@ -398,24 +397,6 @@ mod tests { )?; assert_eq!(group.get("redirect-stdout-to-stderr"), Some(true)); - let group = JsConfig::from_group_values( - &Plugin::Default, - vec![JsGroupValue::Option(JsGroupOption { - name: "javy-json".to_string(), - enabled: false, - })], - )?; - assert_eq!(group.get("javy-json"), Some(false)); - - let group = JsConfig::from_group_values( - &Plugin::Default, - vec![JsGroupValue::Option(JsGroupOption { - name: "javy-json".to_string(), - enabled: true, - })], - )?; - assert_eq!(group.get("javy-json"), Some(true)); - let group = JsConfig::from_group_values( &Plugin::Default, vec![JsGroupValue::Option(JsGroupOption { @@ -477,10 +458,6 @@ mod tests { name: "redirect-stdout-to-stderr".to_string(), enabled: false, }), - JsGroupValue::Option(JsGroupOption { - name: "javy-json".to_string(), - enabled: false, - }), JsGroupValue::Option(JsGroupOption { name: "javy-stream-io".to_string(), enabled: false, @@ -496,7 +473,6 @@ mod tests { ], )?; assert_eq!(group.get("redirect-stdout-to-stderr"), Some(false)); - assert_eq!(group.get("javy-json"), Some(false)); assert_eq!(group.get("javy-stream-io"), Some(false)); assert_eq!(group.get("simd-json-builtins"), Some(false)); assert_eq!(group.get("text-encoding"), Some(false)); diff --git a/crates/cli/tests/dynamic-linking-scripts/javy-json-id.js b/crates/cli/tests/dynamic-linking-scripts/javy-json-id.js deleted file mode 100644 index a253ac64..00000000 --- a/crates/cli/tests/dynamic-linking-scripts/javy-json-id.js +++ /dev/null @@ -1 +0,0 @@ -console.log(Javy.JSON.toStdout(Javy.JSON.fromStdin())); diff --git a/crates/cli/tests/dynamic_linking_test.rs b/crates/cli/tests/dynamic_linking_test.rs index b4dee4f9..2df6ba5e 100644 --- a/crates/cli/tests/dynamic_linking_test.rs +++ b/crates/cli/tests/dynamic_linking_test.rs @@ -114,25 +114,6 @@ fn test_using_runtime_flag_with_dynamic_triggers_error(builder: &mut Builder) -> Ok(()) } -#[javy_cli_test( - dyn = true, - root = "tests/dynamic-linking-scripts", - commands(not(Compile)) -)] -fn javy_json_identity(builder: &mut Builder) -> Result<()> { - let mut runner = builder.input("javy-json-id.js").build()?; - - let input = "{\"x\":5}"; - - let bytes = String::from(input).into_bytes(); - let (out, logs, _) = runner.exec(&bytes)?; - - assert_eq!(String::from_utf8(out)?, input); - assert_eq!(String::from_utf8(logs)?, "undefined\n"); - - Ok(()) -} - #[javy_cli_test(dyn = true, commands(not(Compile)))] fn test_using_plugin_with_dynamic_works(builder: &mut Builder) -> Result<()> { let plugin = Plugin::User; diff --git a/crates/cli/tests/integration_test.rs b/crates/cli/tests/integration_test.rs index 5dcddac4..7b9356ed 100644 --- a/crates/cli/tests/integration_test.rs +++ b/crates/cli/tests/integration_test.rs @@ -84,7 +84,7 @@ fn test_logging_with_compile(builder: &mut Builder) -> Result<()> { "hello world from console.log\nhello world from console.error\n", logs.as_str(), ); - assert_fuel_consumed_within_threshold(36_071, fuel_consumed); + assert_fuel_consumed_within_threshold(35_042, fuel_consumed); Ok(()) } @@ -98,7 +98,7 @@ fn test_logging_without_redirect(builder: &mut Builder) -> Result<()> { let (output, logs, fuel_consumed) = run(&mut runner, &[]); assert_eq!(b"hello world from console.log\n".to_vec(), output); assert_eq!("hello world from console.error\n", logs.as_str()); - assert_fuel_consumed_within_threshold(36_641, fuel_consumed); + assert_fuel_consumed_within_threshold(35_860, fuel_consumed); Ok(()) } @@ -119,32 +119,6 @@ fn test_logging_with_redirect(builder: &mut Builder) -> Result<()> { Ok(()) } -#[javy_cli_test(commands(not(Compile)), root = "tests/dynamic-linking-scripts")] -fn test_javy_json_enabled(builder: &mut Builder) -> Result<()> { - let mut runner = builder.input("javy-json-id.js").build()?; - - let input = "{\"x\":5}"; - let (output, logs, _) = run(&mut runner, input.as_bytes()); - - assert_eq!(logs, "undefined\n"); - assert_eq!(String::from_utf8(output)?, input); - - Ok(()) -} - -#[javy_cli_test(commands(not(Compile)), root = "tests/dynamic-linking-scripts")] -fn test_javy_json_disabled(builder: &mut Builder) -> Result<()> { - let mut runner = builder - .input("javy-json-id.js") - .simd_json_builtins(false) - .build()?; - - let result = runner.exec(&[]); - assert!(result.is_err()); - - Ok(()) -} - #[javy_cli_test(commands(not(Compile)))] fn test_using_plugin_with_static_build(builder: &mut Builder) -> Result<()> { let mut runner = builder.plugin(Plugin::User).input("plugin.js").build()?; diff --git a/crates/javy/CHANGELOG.md b/crates/javy/CHANGELOG.md index b13c4863..2790ad77 100644 --- a/crates/javy/CHANGELOG.md +++ b/crates/javy/CHANGELOG.md @@ -8,6 +8,11 @@ Versioning](https://semver.org/spec/v2.0.0.html). ## [Unreleased] +### Removed + +- `Javy.JSON.fromStdin` and `Javy.JSON.toStdout` APIs and `javy_json` method on + `javy::Config`. + ## [3.1.0] - 2024-11-27 ### Added diff --git a/crates/javy/Cargo.toml b/crates/javy/Cargo.toml index 5ead4681..e5b89d65 100644 --- a/crates/javy/Cargo.toml +++ b/crates/javy/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "javy" -version = "3.1.1-alpha.1" +version = "4.0.0-alpha.1" authors.workspace = true edition.workspace = true license.workspace = true diff --git a/crates/javy/src/apis/json.rs b/crates/javy/src/apis/json.rs index c9f2ed04..087c64b6 100644 --- a/crates/javy/src/apis/json.rs +++ b/crates/javy/src/apis/json.rs @@ -18,7 +18,7 @@ //! hotpath and doing any sort of inline processing of the parsed or stringified //! values is likely to void any performance benefits. use crate::{ - hold, hold_and_release, json, + hold, json, quickjs::{ function::This, prelude::{MutFn, Rest}, @@ -32,11 +32,7 @@ use crate::serde::de::get_to_json; use simd_json::Error as SError; use anyhow::{anyhow, bail, Result}; -use std::{ - io::{Read, Write}, - sync::OnceLock, - time::SystemTime, -}; +use std::{sync::OnceLock, time::SystemTime}; static DEFAULT_PARSE_KEY: OnceLock = OnceLock::new(); @@ -173,52 +169,3 @@ fn call_json_stringify(args: Args<'_>) -> Result> { )), } } - -/// Register `Javy.JSON.fromStdin` and `Javy.JSON.toStdout` functions on the -/// global object. -pub(crate) fn register_javy_json(this: Ctx<'_>) -> Result<()> { - let globals = this.globals(); - let javy = if globals.get::<_, Object>("Javy").is_err() { - Object::new(this.clone())? - } else { - globals.get::<_, Object>("Javy").unwrap() - }; - - let from_stdin = Function::new(this.clone(), |cx, args| { - let (cx, args) = hold_and_release!(cx, args); - from_stdin(hold!(cx.clone(), args)).map_err(|e| to_js_error(cx, e)) - }); - - let to_stdout = Function::new(this.clone(), |cx, args| { - let (cx, args) = hold_and_release!(cx, args); - to_stdout(hold!(cx.clone(), args)).map_err(|e| to_js_error(cx, e)) - }); - - let json = Object::new(this)?; - json.set("fromStdin", from_stdin)?; - json.set("toStdout", to_stdout)?; - - javy.set("JSON", json)?; - globals.set("Javy", javy).map_err(Into::into) -} - -/// Definition for Javy.JSON.fromStdin -fn from_stdin(args: Args<'_>) -> Result { - // Light experimentation shows that 1k bytes is enough to avoid paying the - // high relocation costs. We can modify as we see fit or even make this - // configurable if needed. - let mut buffer = Vec::with_capacity(1000); - let mut fd = std::io::stdin(); - fd.read_to_end(&mut buffer)?; - let (ctx, _) = args.release(); - json::parse(ctx, &mut buffer) -} - -/// Definition for Javy.JSON.toStdout -fn to_stdout(args: Args<'_>) -> Result<()> { - let (_, args) = args.release(); - let mut fd = std::io::stdout(); - let buffer = json::stringify(args[0].clone())?; - fd.write_all(&buffer)?; - fd.flush().map_err(Into::into) -} diff --git a/crates/javy/src/config.rs b/crates/javy/src/config.rs index a3efbb29..eeb613e5 100644 --- a/crates/javy/src/config.rs +++ b/crates/javy/src/config.rs @@ -37,7 +37,6 @@ bitflags! { /// moved out. pub(crate) struct JavyIntrinsics: u32 { const STREAM_IO = 1; - const JSON = 1 << 1; } } @@ -181,15 +180,6 @@ impl Config { self } - /// Whether the `Javy.JSON` intrinsic will be available. - /// Disabled by default. - /// This setting requires the `json` crate feature to be enabled. - #[cfg(feature = "json")] - pub fn javy_json(&mut self, enable: bool) -> &mut Self { - self.javy_intrinsics.set(JavyIntrinsics::JSON, enable); - self - } - /// Enables whether the output of console.log will be redirected to /// `stderr`. pub fn redirect_stdout_to_stderr(&mut self, enable: bool) -> &mut Self { diff --git a/crates/javy/src/runtime.rs b/crates/javy/src/runtime.rs index 08a68214..f4c54612 100644 --- a/crates/javy/src/runtime.rs +++ b/crates/javy/src/runtime.rs @@ -148,12 +148,6 @@ impl Runtime { stream_io::register(ctx.clone()) .expect("registering StreamIO functions to succeed"); } - - #[cfg(feature = "json")] - if javy_intrinsics.contains(JavyIntrinsics::JSON) { - json::register_javy_json(ctx.clone()) - .expect("registering Javy.JSON builtins to succeed"); - } }); Ok(ManuallyDrop::new(context)) diff --git a/crates/plugin-api/CHANGELOG.md b/crates/plugin-api/CHANGELOG.md index ca5da8da..a86a8f49 100644 --- a/crates/plugin-api/CHANGELOG.md +++ b/crates/plugin-api/CHANGELOG.md @@ -8,6 +8,12 @@ Versioning](https://semver.org/spec/v2.0.0.html). ## [Unreleased] +### Removed + +- `javy` dependency updated to 4.0.0 which removes `javy_json` method on + `javy_plugin_api::Config` and removes support for `Javy.JSON.fromStdin` and + `Javy.JSON.toStdout`. + ## [2.0.0] - 2024-11-27 ### Changed diff --git a/crates/plugin-api/Cargo.toml b/crates/plugin-api/Cargo.toml index 5fa65278..76ab2417 100644 --- a/crates/plugin-api/Cargo.toml +++ b/crates/plugin-api/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "javy-plugin-api" -version = "2.0.1-alpha.1" +version = "3.0.0-alpha.1" authors.workspace = true edition.workspace = true license.workspace = true diff --git a/crates/plugin/src/lib.rs b/crates/plugin/src/lib.rs index 2cc6c463..41e9101e 100644 --- a/crates/plugin/src/lib.rs +++ b/crates/plugin/src/lib.rs @@ -22,8 +22,7 @@ pub extern "C" fn initialize_runtime() { .text_encoding(true) .redirect_stdout_to_stderr(true) .javy_stream_io(true) - .simd_json_builtins(true) - .javy_json(true); + .simd_json_builtins(true); let mut config_bytes = vec![]; let shared_config = match io::stdin().read_to_end(&mut config_bytes) { diff --git a/crates/plugin/src/shared_config/mod.rs b/crates/plugin/src/shared_config/mod.rs index 3c06d76a..ac337cf8 100644 --- a/crates/plugin/src/shared_config/mod.rs +++ b/crates/plugin/src/shared_config/mod.rs @@ -15,8 +15,6 @@ runtime_config! { pub struct SharedConfig { /// Whether to redirect the output of console.log to standard error. redirect_stdout_to_stderr: Option, - /// Whether to enable the `Javy.JSON` builtins. - javy_json: Option, /// Whether to enable the `Javy.readSync` and `Javy.writeSync` builtins. javy_stream_io: Option, /// Whether to override the `JSON.parse` and `JSON.stringify` @@ -40,9 +38,6 @@ impl SharedConfig { if let Some(enable) = self.redirect_stdout_to_stderr { config.redirect_stdout_to_stderr(enable); } - if let Some(enable) = self.javy_json { - config.javy_json(enable); - } if let Some(enable) = self.javy_stream_io { config.javy_stream_io(enable); } diff --git a/crates/runner/src/lib.rs b/crates/runner/src/lib.rs index 3175a165..59e6850f 100644 --- a/crates/runner/src/lib.rs +++ b/crates/runner/src/lib.rs @@ -74,8 +74,6 @@ pub struct Builder { world: Option, /// Whether console.log should write to stderr. redirect_stdout_to_stderr: Option, - /// Whether to enable the `Javy.JSON` builtins. - javy_json: Option, /// Whether to enable the `Javy.IO` builtins. javy_stream_io: Option, /// Whether to override JSON.parse and JSON.stringify with a SIMD based @@ -108,7 +106,6 @@ impl Default for Builder { command: JavyCommand::Build, redirect_stdout_to_stderr: None, javy_stream_io: None, - javy_json: None, simd_json_builtins: None, text_encoding: None, event_loop: None, @@ -153,11 +150,6 @@ impl Builder { self } - pub fn javy_json(&mut self, enabled: bool) -> &mut Self { - self.javy_json = Some(enabled); - self - } - pub fn javy_stream_io(&mut self, enabled: bool) -> &mut Self { self.javy_stream_io = Some(enabled); self @@ -206,7 +198,6 @@ impl Builder { world, root, redirect_stdout_to_stderr, - javy_json, javy_stream_io, simd_json_builtins, text_encoding, @@ -234,7 +225,6 @@ impl Builder { wit, world, redirect_stdout_to_stderr, - javy_json, javy_stream_io, simd_json_builtins, text_encoding, @@ -311,7 +301,6 @@ impl Runner { wit: Option, world: Option, redirect_stdout_to_stderr: Option, - javy_json: Option, javy_stream_io: Option, override_json_parse_and_stringify: Option, text_encoding: Option, @@ -333,7 +322,6 @@ impl Runner { &world, preload.is_some(), &redirect_stdout_to_stderr, - &javy_json, &javy_stream_io, &override_json_parse_and_stringify, &text_encoding, @@ -562,7 +550,6 @@ impl Runner { world: &Option, dynamic: bool, redirect_stdout_to_stderr: &Option, - javy_json: &Option, javy_stream_io: &Option, simd_json_builtins: &Option, text_encoding: &Option, @@ -596,11 +583,6 @@ impl Runner { )); } - if let Some(enabled) = *javy_json { - args.push("-J".to_string()); - args.push(format!("javy-json={}", if enabled { "y" } else { "n" })); - } - if let Some(enabled) = *javy_stream_io { args.push("-J".to_string()); args.push(format!( diff --git a/fuzz/fuzz_targets/json_differential.rs b/fuzz/fuzz_targets/json_differential.rs index b30e93df..9efd2476 100644 --- a/fuzz/fuzz_targets/json_differential.rs +++ b/fuzz/fuzz_targets/json_differential.rs @@ -22,7 +22,7 @@ fuzz_target!(|data: ArbitraryValue| { let mut config = Config::default(); setup_config(&mut config); - config.simd_json_builtins(true).javy_json(true); + config.simd_json_builtins(true); unsafe { RT = Some(Runtime::new(std::mem::take(&mut config)).expect("Runtime to be created"));