| Crates.io | rusty_jsc |
| lib.rs | rusty_jsc |
| version | 0.1.0 |
| created_at | 2022-08-27 05:41:02.763439+00 |
| updated_at | 2023-04-28 03:01:54.670441+00 |
| description | Rust bindings for the JavaScriptCore engine |
| homepage | |
| repository | https://github.com/wasmerio/rusty_jsc |
| max_upload_size | |
| id | 653289 |
| size | 32,344 |
This library provides a Rust API for the JavaScriptCore engine with the following goals:
jsc to avoid the dependency to GTK.Please check out PunJS for an example of how to implement a JavaScript runtime with rusty_jsc.
use rusty_jsc::JSContext;
let mut context = JSContext::default();
let value = context.evaluate_script("'hello, world'", 1);
if let Some(value) = value {
println!("{}", value.to_string(&context));
// Prints:
// hello, world
}
use rusty_jsc::{JSContext, JSValue};
use rusty_jsc_macros::callback;
// The JavaScript code calls this Rust function.
#[callback]
fn foo(_context: JSContext) {
println!("hello from Rust land!");
}
fn main() {
let mut context = JSContext::default();
let callback = JSValue::callback(&context, Some(foo));
let mut global = context.get_global_object();
global.set_property(&context, "foo".to_string(), callback);
context.evaluate_script("foo()", 1);
// Prints:
// hello from Rust land!
}
The wrappers in rusty_jsc are built against <JavaScriptCore/JavaScript.h> header rather than the jsc variant that requires GTK.
rusty_v8?Bun has shown that JavaScriptCore is a worthy contender to V8 on the server-side, so let's bring it over to the Rust ecosystem as well.
I first used bindgen to do the rough conversion of JavaScript/JavaScript.h header and then cleaned it up by hand.
The plan is to maintain the low-level bindings by hand.