{"id":21933114,"url":"https://github.com/wasmerio/rusty_jsc","last_synced_at":"2025-04-06T02:08:03.591Z","repository":{"id":57981292,"uuid":"529259582","full_name":"wasmerio/rusty_jsc","owner":"wasmerio","description":"Rust bindings for the JavaScriptCore engine.","archived":false,"fork":false,"pushed_at":"2023-08-10T03:12:53.000Z","size":78,"stargazers_count":106,"open_issues_count":10,"forks_count":10,"subscribers_count":4,"default_branch":"main","last_synced_at":"2025-03-30T01:12:43.788Z","etag":null,"topics":["javascriptcore","rust"],"latest_commit_sha":null,"homepage":"","language":"Rust","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/wasmerio.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2022-08-26T13:02:07.000Z","updated_at":"2025-03-12T15:18:39.000Z","dependencies_parsed_at":"2025-01-16T14:15:37.840Z","dependency_job_id":"51529487-6fa5-4866-8f4c-e063072a1193","html_url":"https://github.com/wasmerio/rusty_jsc","commit_stats":{"total_commits":52,"total_committers":4,"mean_commits":13.0,"dds":0.4807692307692307,"last_synced_commit":"1a6f72bf4f3c423f8cd3e7d91e121a0c0ad50af7"},"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wasmerio%2Frusty_jsc","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wasmerio%2Frusty_jsc/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wasmerio%2Frusty_jsc/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wasmerio%2Frusty_jsc/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/wasmerio","download_url":"https://codeload.github.com/wasmerio/rusty_jsc/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247423513,"owners_count":20936626,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["javascriptcore","rust"],"created_at":"2024-11-29T00:07:51.587Z","updated_at":"2025-04-06T02:08:03.571Z","avatar_url":"https://github.com/wasmerio.png","language":"Rust","funding_links":[],"categories":[],"sub_categories":[],"readme":"# JavaScriptCore API for Rust\n\n[![crates](https://img.shields.io/crates/v/rusty_jsc.svg)](https://crates.io/crates/rusty_jsc)\n[![docs](https://docs.rs/rusty_jsc/badge.svg)](https://docs.rs/rusty_jsc)\n\nThis library provides a Rust API for the JavaScriptCore engine with the following goals:\n\n* High-level API like the JavaScriptCore API for Swift\n* Wrap the low-level C++ API instead of `jsc` to avoid the dependency to GTK.\n\n## Getting Started\n\n### Implementing a JavaScript runtime\n\nPlease check out [PunJS](examples/punjs) for an example of how to implement a JavaScript runtime with `rusty_jsc`.\n\n### Evaluating a JavaScript script\n```rust\nuse rusty_jsc::{JSContext};\n\nfn main() {\n    let mut context = JSContext::default();\n    match context.evaluate_script(\"'Hello World!'\", 1) {\n        Ok(value) =\u003e {\n            println!(\"{}\", value.to_string(\u0026context).unwrap());\n        }\n        Err(e) =\u003e {\n            println!(\"Uncaught: {}\", e.to_string(\u0026context).unwrap())\n        }\n    }\n}\n```\n\n### Callbacks from JavaScript to Rust\n\n```rust\nuse rusty_jsc::{JSContext, JSValue};\nuse rusty_jsc_macros::callback;\n\n#[callback]\nfn greet(\n    ctx: JSContext,\n    function: JSObject,\n    this: JSObject,\n    args: \u0026[JSValue],\n) -\u003e Result\u003cJSValue, JSValue\u003e {\n    Ok(JSValue::string(\u0026ctx, format!(\"Hello, {}\", args[0].to_string(\u0026ctx).unwrap())))\n}\n\nfn main() {\n    let mut context = JSContext::default();\n    let callback = JSValue::callback(\u0026context, Some(greet));\n    let global = context.get_global_object();\n    global.set_property(\u0026context, \"greet\", callback).unwrap();\n\n    match context.evaluate_script(\"greet('Tom')\", 1) {\n        Ok(value) =\u003e {\n            println!(\"{}\", value.to_string(\u0026context).unwrap());\n        }\n        Err(e) =\u003e {\n            println!(\"Uncaught: {}\", e.to_string(\u0026context).unwrap())\n        }\n    }\n}\n```\n\n#### Passing functions to a callback\n\n```rust\nuse rusty_jsc::{JSContext, JSObject, JSValue, JSString};\nuse rusty_jsc_macros::callback;\n\n#[callback]\nfn greet(\n    ctx: JSContext,\n    function: JSObject,\n    this: JSObject,\n    args: \u0026[JSValue],\n) -\u003e Result\u003cJSValue, JSValue\u003e {\n    // Parse the argument as a function and call it with an argument\n    let callback_function = args[0].to_object(\u0026ctx).unwrap().call(\u0026ctx, None, \u0026[JSValue::string(\u0026ctx, \"Tom\")]).unwrap();\n    Ok(callback_function)\n}\n\nfn main() {\n    let mut context = JSContext::default();\n    let callback = JSValue::callback(\u0026context, Some(greet));\n    let global = context.get_global_object();\n    global.set_property(\u0026context, \"greet\", callback).unwrap();\n\n    match context.evaluate_script(\"greet((name) =\u003e 'Hello, ' + name)\", 1) {\n        Ok(value) =\u003e {\n            println!(\"{}\", value.to_string(\u0026context).unwrap());\n        }\n        Err(e) =\u003e {\n            println!(\"Uncaught: {}\", e.to_string(\u0026context).unwrap())\n        }\n    }\n}\n```\n\n## FAQ\n\n### What about the other JavaScriptCore bindings for Rust?\n\nThe wrappers in `rusty_jsc` are built against `\u003cJavaScriptCore/JavaScript.h\u003e` header rather than the `jsc` variant that requires GTK.\n\n### Why JavaScriptCore when there's already `rusty_v8`?\n\n[Bun](https://bun.sh) 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.\n\n### How were the C++ low-level bindings generated?\n\nI first used `bindgen` to do the rough conversion of `JavaScript/JavaScript.h` header and then cleaned it up by hand.\nThe plan is to maintain the low-level bindings by hand.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwasmerio%2Frusty_jsc","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fwasmerio%2Frusty_jsc","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwasmerio%2Frusty_jsc/lists"}