pub struct Context<'rt> { /* private fields */ }Expand description
An execution context: a global object plus the builtins installed on it.
Mirrors the role of JSContext in the QuickJS C API.
Implementations§
Source§impl<'rt> Context<'rt>
impl<'rt> Context<'rt>
Sourcepub fn set_module_loader(&mut self, loader: Box<dyn ModuleLoader>)
pub fn set_module_loader(&mut self, loader: Box<dyn ModuleLoader>)
Install how module specifiers are resolved and read.
Without one, importing is a clear error rather than a silent failure: the engine
cannot guess whether ./x.js means a file, and the host is what knows.
Sourcepub fn set_script_name(&mut self, name: impl Into<String>)
pub fn set_script_name(&mut self, name: impl Into<String>)
Name the scripts this context evaluates, for stack traces.
Mirrors what qjs passes to JS_Eval: -e code is <cmdline>, a script file
is its own path. Without a name, frames print <input>, which is what the
reference uses for code with no file behind it.
Sourcepub fn eval_module(&mut self, specifier: &str) -> Result<Value>
pub fn eval_module(&mut self, specifier: &str) -> Result<Value>
Evaluate specifier as the entry module, the way qjs -m does.
The microtask queue is drained afterwards, so a module whose top level launched an async task has finished it by the time this returns.
Sourcepub fn eval(&mut self, source: &str) -> Result<Value>
pub fn eval(&mut self, source: &str) -> Result<Value>
Evaluate source as a global script and return its completion value.
The value is reported the way qjs -e reports it: a string for anything the
script leaves on the stack, and nothing at all for undefined.
Sourcepub fn last_value(&self) -> &Value
pub fn last_value(&self) -> &Value
The value of the script that ran last.