Module chakracore::script
[−]
[src]
Functionality for executing and parsing JavaScript.
The simple eval
function should cover most needs. It evalutes the supplied
code directly and returns the script's value.
let result = js::script::eval(&guard, "10 + 10").unwrap(); assert_eq!(result.to_integer(&guard), 20);
Another option is to parse the source code and execute it at a later time
with a function. This is done using the parse
function:
let add = js::script::parse(&guard, "10 + 10").unwrap(); let result = add.call(&guard, &[]).unwrap(); assert_eq!(result.to_integer(&guard), 20);
Functions
eval |
Evaluates code directly. |
eval_with_name |
Evaluates code and associates it with a name. |
parse |
Parses code and returns it as a function. |
parse_with_name |
Parses code and associates it with a name, returns it as a function. |