Skip to content

Get JsRuntime execution output #12635

Answered by lucacasonato
gufoe asked this question in Q&A
Discussion options

You must be logged in to vote

There are two things you can do:

  1. You can return a Global<Value> into a string using the v8 API:
     let value = isolate.execute_script("<anon>", "'hello' + ' world!'").unwrap();
     let mut scope = isolate.handle_scope();
     let value = value.get(&mut scope);
     let result = value.to_rust_string_lossy(&mut scope);
     println!("{}", result);
  2. You can use serde_v8 to deserialize a V8 value into any Rust value that implements serde::Deserialize:
     let value = isolate.execute_script("<anon>", "'hello' + ' world!'").unwrap();
     let mut scope = isolate.handle_scope();
     let value = value.get(&mut scope);
     let result: String =  serde_v8::from_v8(value, &mut scope);
     println!("{}", result);

Replies: 1 comment 3 replies

Comment options

You must be logged in to vote
3 replies
@gufoe
Comment options

@bartlomieju
Comment options

@gufoe
Comment options

Answer selected by gufoe
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants
Converted from issue

This discussion was converted from issue #12630 on November 03, 2021 10:53.