Created
July 17, 2023 17:43
-
-
Save JSila/0ee28a8ad017592dea937e15e198aac1 to your computer and use it in GitHub Desktop.
deno_core example in rust
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use deno_core::v8::{self}; | |
use deno_core::{JsRuntime, RuntimeOptions}; | |
fn main() { | |
let script1 = std::fs::read_to_string("script1.js").unwrap(); | |
let script2 = std::fs::read_to_string("script2.js").unwrap(); | |
let mut runtime = JsRuntime::new(RuntimeOptions::default()); | |
let _ = runtime.execute_script("script1", script1.into()).unwrap(); | |
let res = runtime.execute_script("script2", script2.into()).unwrap(); | |
let scope = &mut runtime.handle_scope(); | |
let local = v8::Local::new(scope, res); | |
let deserialized_value = serde_v8::from_v8::<serde_json::Value>(scope, local); | |
dbg!(deserialized_value); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function increment(n) { | |
return n + 1; | |
} | |
let a = 7; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
a = a * 2; | |
increment(a); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment