pub struct Runtime {
pub heap: Heap,
/* private fields */
}
Expand description
The sljs JavaScript runtime.
It should be given a Parser
implementation, e.g. NodejsParser
or
EsprimaParser
:
use sljs::JSON;
use sljs::runtime::{Runtime, NodejsParser};
let parser = NodejsParser::new();
let mut sljs = Runtime::load(parser)
.expect("Runtime::load");
The Runtime
evaluates JavaScript source code and creates/stores crate::JSObject
s.
sljs.evaluate("var x = 12")
.expect("eval: var x");
let x = sljs.evaluate("x")
.expect("eval: x");
assert_eq!(sljs.json_from(x), JSON::from(12.0));
Fields
heap: Heap
Implementations
sourceimpl Runtime
impl Runtime
sourcepub fn load(parser: Box<dyn Parser>) -> EvalResult<Self>
pub fn load(parser: Box<dyn Parser>) -> EvalResult<Self>
Creates a sljs runtime.
sourcepub fn parse(&mut self, input: &str) -> EvalResult<Program>
pub fn parse(&mut self, input: &str) -> EvalResult<Program>
Exposes the configured parser.
sourcepub fn evaluate(&mut self, input: &str) -> EvalResult<JSValue>
pub fn evaluate(&mut self, input: &str) -> EvalResult<JSValue>
Takes an input
and evaluates it.
sourcepub fn string_from(&mut self, value: JSValue) -> JSString
pub fn string_from(&mut self, value: JSValue) -> JSString
Turn a JSValue
into a human-readable string.
pub fn dbg(&mut self, refstr: &str)
Auto Trait Implementations
impl !RefUnwindSafe for Runtime
impl !Send for Runtime
impl !Sync for Runtime
impl Unpin for Runtime
impl !UnwindSafe for Runtime
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more