Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove support for Javy.JSON #872

Merged
merged 1 commit into from
Jan 7, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
Expand Down
24 changes: 0 additions & 24 deletions crates/cli/src/commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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 {
Expand Down Expand Up @@ -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,
Expand All @@ -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));
Expand Down
1 change: 0 additions & 1 deletion crates/cli/tests/dynamic-linking-scripts/javy-json-id.js

This file was deleted.

19 changes: 0 additions & 19 deletions crates/cli/tests/dynamic_linking_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
30 changes: 2 additions & 28 deletions crates/cli/tests/integration_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(())
}

Expand All @@ -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(())
}

Expand All @@ -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()?;
Expand Down
5 changes: 5 additions & 0 deletions crates/javy/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion crates/javy/Cargo.toml
Original file line number Diff line number Diff line change
@@ -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
Expand Down
57 changes: 2 additions & 55 deletions crates/javy/src/apis/json.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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},
Expand All @@ -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<String> = OnceLock::new();

Expand Down Expand Up @@ -173,52 +169,3 @@ fn call_json_stringify(args: Args<'_>) -> Result<Value<'_>> {
)),
}
}

/// 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<Value> {
// 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)
}
10 changes: 0 additions & 10 deletions crates/javy/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ bitflags! {
/// moved out.
pub(crate) struct JavyIntrinsics: u32 {
const STREAM_IO = 1;
const JSON = 1 << 1;
}
}

Expand Down Expand Up @@ -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 {
Expand Down
6 changes: 0 additions & 6 deletions crates/javy/src/runtime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
6 changes: 6 additions & 0 deletions crates/plugin-api/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion crates/plugin-api/Cargo.toml
Original file line number Diff line number Diff line change
@@ -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
Expand Down
3 changes: 1 addition & 2 deletions crates/plugin/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
5 changes: 0 additions & 5 deletions crates/plugin/src/shared_config/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<bool>,
/// Whether to enable the `Javy.JSON` builtins.
javy_json: Option<bool>,
/// Whether to enable the `Javy.readSync` and `Javy.writeSync` builtins.
javy_stream_io: Option<bool>,
/// Whether to override the `JSON.parse` and `JSON.stringify`
Expand All @@ -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);
}
Expand Down
Loading
Loading