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

chore: update deno core and Cargo.lock #3

Merged
merged 2 commits into from
Nov 26, 2024
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
18 changes: 0 additions & 18 deletions .github/workflows/publish.yaml

This file was deleted.

62 changes: 32 additions & 30 deletions ReadMe.md → README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<!-- DO NOT EDIT -- ReadMe is generated from lib.rs -->
<!-- DO NOT EDIT -- README is generated from lib.rs -->

# js-sandbox-ios

Expand All @@ -24,7 +24,7 @@ This library is in early development, with a basic but powerful API. The API may
The _Hello World_ example -- print something using JavaScript -- is one line, as it should be:
```rust
fn main() {
js_sandbox_ios::eval_json("console.log('Hello Rust from JS')").expect("JS runs");
js_sandbox_ios::eval_json("console.log('Hello Rust from JS')").expect("JS runs");
}
```

Expand Down Expand Up @@ -64,13 +64,13 @@ fn main() -> Result<(), AnyError> {
return "A person named " + person.name + " of age " + person.age;
}"#;

let mut script = Script::from_string(src)?;
let mut script = Script::from_string(src)?;

let person = Person { name: "Roger".to_string(), age: 42 };
let result: String = script.call("toString", (person,))?;
let person = Person { name: "Roger".to_string(), age: 42 };
let result: String = script.call("toString", (person,))?;

assert_eq!(result, "A person named Roger of age 42");
Ok(())
assert_eq!(result, "A person named Roger of age 42");
Ok(())
}
```

Expand All @@ -85,14 +85,14 @@ If you want to statically embed UTF-8 encoded files in the Rust binary, you can
use js_sandbox_ios::Script;

fn main() {
// (1) at runtime:
let mut script = Script::from_file("script.js").expect("load + init succeeds");
// (1) at runtime:
let mut script = Script::from_file("script.js").expect("load + init succeeds");

// (2) at compile time:
let code: &'static str = include_str!("script.js");
let mut script = Script::from_string(code).expect("init succeeds");
// (2) at compile time:
let code: &'static str = include_str!("script.js");
let mut script = Script::from_string(code).expect("init succeeds");

// use script as usual
// use script as usual
}
```

Expand All @@ -105,19 +105,19 @@ This example appends a string in two calls, and then gets the result in a third
use js_sandbox_ios::{Script, AnyError};

fn main() -> Result<(), AnyError> {
let src = r#"
let src = r#"
var total = '';
function append(str) { total += str; }
function get() { return total; }"#;

let mut script = Script::from_string(src)?;
let mut script = Script::from_string(src)?;

let _: () = script.call("append", ("hello",))?;
let _: () = script.call("append", (" world",))?;
let result: String = script.call("get", ())?;
let _: () = script.call("append", ("hello",))?;
let _: () = script.call("append", (" world",))?;
let result: String = script.call("get", ())?;

assert_eq!(result, "hello world");
Ok(())
assert_eq!(result, "hello world");
Ok(())
}
```

Expand All @@ -130,21 +130,23 @@ a timeout, after which JavaScript execution is aborted.
use js_sandbox_ios::{Script, JsError};

fn main() -> Result<(), JsError> {
use std::time::Duration;
let js_code = "function run_forever() { for(;;) {} }";
let mut script = Script::from_string(js_code)?
.with_timeout(Duration::from_millis(1000));
use std::time::Duration;
let js_code = "function run_forever() { for(;;) {} }";
let mut script = Script::from_string(js_code)?
.with_timeout(Duration::from_millis(1000));

let result: Result<String, JsError> = script.call("run_forever", ());
let result: Result<String, JsError> = script.call("run_forever", ());

assert_eq!(
result.unwrap_err().to_string(),
"Uncaught Error: execution terminated".to_string()
);
assert_eq!(
result.unwrap_err().to_string(),
"Uncaught Error: execution terminated".to_string()
);

Ok(())
Ok(())
}
```

[Deno]: https://deno.land
[serde_json]: https://docs.serde.rs/serde_json

License: Zlib
4 changes: 3 additions & 1 deletion cfg/ReadMe.in → cfg/README.in
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
<!-- DO NOT EDIT -- ReadMe is generated from lib.rs -->
<!-- DO NOT EDIT -- README is generated from lib.rs -->

# {{crate}}

[<img alt="crates.io" src="https://img.shields.io/crates/v/js-sandbox?logo=rust&color=A6854D" />](https://crates.io/crates/js-sandbox)
[<img alt="docs.rs" src="https://img.shields.io/badge/docs.rs-js--sandbox-4D8AA6?&logo=data:image/svg+xml;base64,PHN2ZyByb2xlPSJpbWciIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIgdmlld0JveD0iMCAwIDUxMiA1MTIiPjxwYXRoIGZpbGw9IiNmNWY1ZjUiIGQ9Ik00ODguNiAyNTAuMkwzOTIgMjE0VjEwNS41YzAtMTUtOS4zLTI4LjQtMjMuNC0zMy43bC0xMDAtMzcuNWMtOC4xLTMuMS0xNy4xLTMuMS0yNS4zIDBsLTEwMCAzNy41Yy0xNC4xIDUuMy0yMy40IDE4LjctMjMuNCAzMy43VjIxNGwtOTYuNiAzNi4yQzkuMyAyNTUuNSAwIDI2OC45IDAgMjgzLjlWMzk0YzAgMTMuNiA3LjcgMjYuMSAxOS45IDMyLjJsMTAwIDUwYzEwLjEgNS4xIDIyLjEgNS4xIDMyLjIgMGwxMDMuOS01MiAxMDMuOSA1MmMxMC4xIDUuMSAyMi4xIDUuMSAzMi4yIDBsMTAwLTUwYzEyLjItNi4xIDE5LjktMTguNiAxOS45LTMyLjJWMjgzLjljMC0xNS05LjMtMjguNC0yMy40LTMzLjd6TTM1OCAyMTQuOGwtODUgMzEuOXYtNjguMmw4NS0zN3Y3My4zek0xNTQgMTA0LjFsMTAyLTM4LjIgMTAyIDM4LjJ2LjZsLTEwMiA0MS40LTEwMi00MS40di0uNnptODQgMjkxLjFsLTg1IDQyLjV2LTc5LjFsODUtMzguOHY3NS40em0wLTExMmwtMTAyIDQxLjQtMTAyLTQxLjR2LS42bDEwMi0zOC4yIDEwMiAzOC4ydi42em0yNDAgMTEybC04NSA0Mi41di03OS4xbDg1LTM4Ljh2NzUuNHptMC0xMTJsLTEwMiA0MS40LTEwMi00MS40di0uNmwxMDItMzguMiAxMDIgMzguMnYuNnoiPjwvcGF0aD48L3N2Zz4K" />](https://docs.rs/js-sandbox)

{{readme}}

License: {{license}}
8 changes: 4 additions & 4 deletions js-sandbox-macros/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

[package]
name = "js-sandbox-macros"
version = "0.2.0-rc.1"
version = "0.2.0"
description = "Procedural macros for js-sandbox"
repository = "https://github.com/Bromeon/js-sandbox"
documentation = "https://docs.rs/js-sandbox-macros/0.2.0-rc.1"
Expand All @@ -14,6 +14,6 @@ edition = "2021"
proc-macro = true

[dependencies]
syn = { version = "2.0.32", features = ["full"] }
quote = "1.0.33"
proc-macro2 = "1.0.66"
syn = { version = "2.0.89", features = ["full"] }
quote = "1.0.37"
proc-macro2 = "1.0.92"
12 changes: 6 additions & 6 deletions js-sandbox/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,18 @@

[package]
name = "js-sandbox-ios"
version = "0.1.1"
version = "0.2.0"
description = "Execute JavaScript code from Rust in a secure sandbox, and transport data to/from JS plug-ins."
repository = "https://github.com/Bromeon/js-sandbox"
documentation = "https://docs.rs/js-sandbox/0.2.0-rc.1"
authors = ["Jan Haller <[email protected]>"]
license = "Zlib"
edition = "2021"
readme = "../ReadMe.md"
readme = "../Readme.md"

[dependencies]
js-sandbox-macros = { path = "../js-sandbox-macros", version = "=0.2.0-rc.1" }
deno_core = "0.238.0"
serde_json = "1.0.106"
serde = { version = "1.0.188", features = ["derive"] }
js-sandbox-macros = { path = "../js-sandbox-macros", version = "=0.2.0" }
deno_core = "0.322.0"
serde_json = "1.0.133"
serde = { version = "1.0.215", features = ["derive"] }
tracing = "0.1.40"
32 changes: 16 additions & 16 deletions js-sandbox/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
// Copyright (c) 2020-2023 js-sandbox contributors. Zlib license.

// Note: the crate documentation is copied to ReadMe.md using cargo-readme (see CI)
// Note: the crate documentation is copied to README.md using cargo-readme (see CI)
// Alternatives:
// * once stable: #![feature(external_doc)] #![doc(include = "../ReadMe.md")]
// * doc_comment crate + doctest!("../ReadMe.md"); -- works for running doc-tests, but not for doc on crate level
// * once stable: #![feature(external_doc)] #![doc(include = "../README.md")]
// * doc_comment crate + doctest!("../README.md"); -- works for running doc-tests, but not for doc on crate level

//! `js-sandbox` is a Rust library for executing JavaScript code from Rust in a secure sandbox. It is based on the [Deno] project and uses [serde_json]
//! for serialization.
Expand Down Expand Up @@ -37,13 +37,13 @@
//! use js_sandbox_ios::{Script, AnyError};
//!
//! fn main() -> Result<(), AnyError> {
//! let js_code = "function sub(a, b) { return a - b; }";
//! let mut script = Script::from_string(js_code)?;
//! let js_code = "function sub(a, b) { return a - b; }";
//! let mut script = Script::from_string(js_code)?;
//!
//! let result: i32 = script.call("sub", (7, 5))?;
//! let result: i32 = script.call("sub", (7, 5))?;
//!
//! assert_eq!(result, 2);
//! Ok(())
//! assert_eq!(result, 2);
//! Ok(())
//! }
//! ```
//!
Expand All @@ -55,23 +55,23 @@
//!
//! #[derive(Serialize)]
//! struct Person {
//! name: String,
//! age: u8,
//! name: String,
//! age: u8,
//! }
//!
//! fn main() -> Result<(), AnyError> {
//! let src = r#"
//! let src = r#"
//! function toString(person) {
//! return "A person named " + person.name + " of age " + person.age;
//! }"#;
//!
//! let mut script = Script::from_string(src)?;
//! let mut script = Script::from_string(src)?;
//!
//! let person = Person { name: "Roger".to_string(), age: 42 };
//! let result: String = script.call("toString", (person,))?;
//! let person = Person { name: "Roger".to_string(), age: 42 };
//! let result: String = script.call("toString", (person,))?;
//!
//! assert_eq!(result, "A person named Roger of age 42");
//! Ok(())
//! assert_eq!(result, "A person named Roger of age 42");
//! Ok(())
//! }
//! ```
//!
Expand Down
12 changes: 6 additions & 6 deletions js-sandbox/src/script.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use std::{thread, time::Duration};

use deno_core::anyhow::Context;
use deno_core::v8::{Global, Value};
use deno_core::{op2, serde_v8, v8, Extension, FastString, JsBuffer, JsRuntime, Op, OpState};
use deno_core::{op2, serde_v8, v8, Extension, FastString, JsBuffer, JsRuntime, OpDecl, OpState};
use serde::de::DeserializeOwned;
use serde::{Deserialize, Serialize};

Expand Down Expand Up @@ -82,8 +82,9 @@ impl Script {
}

pub fn new() -> Self {
const DECL: OpDecl = op_return();
let ext = Extension {
ops: Cow::Owned(vec![op_return::DECL]),
ops: Cow::Owned(vec![DECL]),
..Default::default()
};

Expand Down Expand Up @@ -133,7 +134,7 @@ impl Script {
// We cannot provide a dynamic filename because execute_script() requires a &'static str
let global = self
.runtime
.execute_script(Self::DEFAULT_FILENAME, js_code.into())?;
.execute_script(Self::DEFAULT_FILENAME, js_code)?;

self.added_namespaces.insert(namespace.to_string(), global);

Expand Down Expand Up @@ -296,7 +297,7 @@ impl Script {
};

// 'undefined' will cause JSON serialization error, so it needs to be treated as null
let js_code = format!(
let js_code: String = format!(
"(async () => {{
let __rust_result = {fn_name}.constructor.name === 'AsyncFunction'
? await {fn_name}({json_args})
Expand All @@ -307,8 +308,7 @@ impl Script {

Deno.core.ops.op_return(__rust_result);
}})()"
)
.into();
);

if let Some(timeout) = self.timeout {
let handle = self.runtime.v8_isolate().thread_safe_handle();
Expand Down
2 changes: 0 additions & 2 deletions publish.sh

This file was deleted.

Loading