Skip to content

Instantly share code, notes, and snippets.

@JSila
Created July 17, 2023 17:43
Show Gist options
  • Save JSila/0ee28a8ad017592dea937e15e198aac1 to your computer and use it in GitHub Desktop.
Save JSila/0ee28a8ad017592dea937e15e198aac1 to your computer and use it in GitHub Desktop.
deno_core example in rust
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);
}
function increment(n) {
return n + 1;
}
let a = 7;
a = a * 2;
increment(a);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment