pub struct JSContext { /* private fields */ }
Expand description
JavaScript execution context.
This struct represents a JavaScript execution context. It is the top-level object for evaluating JavaScript code.
Can be obtained initially from View::lock_js_context
.
Implementations§
Source§impl JSContext
impl JSContext
Sourcepub fn global_object(&self) -> JSObject<'_>
pub fn global_object(&self) -> JSObject<'_>
Get the global object for this context.
Sourcepub fn global_context(&self) -> JSContext
pub fn global_context(&self) -> JSContext
Get the global context for this context.
Sourcepub fn name(&self) -> Option<JSString>
pub fn name(&self) -> Option<JSString>
Get the name of this context.
A JSGlobalContext’s name is exposed when inspecting the context to make it easier to identify the context you would like to inspect.
The context may not have a name, in which case this method will return None
.
Sourcepub fn is_inspectable(&self) -> bool
pub fn is_inspectable(&self) -> bool
Gets whether the context is inspectable in Web Inspector.
Sourcepub fn check_script_syntax(&self, script: &str) -> Result<bool, JSValue<'_>>
pub fn check_script_syntax(&self, script: &str) -> Result<bool, JSValue<'_>>
Checks for syntax errors in a string of JavaScript.
true
if the script is syntactically correct, otherwise false
.
Sourcepub fn garbage_collect(&self)
pub fn garbage_collect(&self)
Performs a JavaScript garbage collection.
JavaScript values that are on the machine stack, in a register,
protected by JSValueProtect
, set as the global object of an execution context,
or reachable from any such value will not be collected.
During JavaScript execution, you are not required to call this function; the JavaScript engine will garbage collect as needed. JavaScript values created within a context group are automatically destroyed when the last reference to the context group is released.