pub struct JSContext { /* private fields */ }Expand description
A JavaScript execution context.
Holds the global object and other execution state.
Implementations§
Source§impl JSContext
impl JSContext
Sourcepub const unsafe fn from_raw(raw: JSGlobalContextRef) -> Self
pub const unsafe fn from_raw(raw: JSGlobalContextRef) -> Self
Sourcepub fn new() -> Self
pub fn new() -> Self
Creates a global JavaScript execution context and populates it
with all the built-in JavaScript objects, such as Object,
Function, String, and Array.
In WebKit version 4.0 and later, the context is created in a unique context group. Therefore, scripts may execute in it concurrently with scripts executing in other contexts. However, you may not use values created in the context in other contexts.
Sourcepub fn new_with_class(global_object_class: &JSClass) -> Self
pub fn new_with_class(global_object_class: &JSClass) -> Self
Creates a global JavaScript execution context and populates it
with all the built-in JavaScript objects, such as Object,
Function, String, and Array.
In WebKit version 4.0 and later, the context is created in a unique context group. Therefore, scripts may execute in it concurrently with scripts executing in other contexts. However, you may not use values created in the context in other contexts.
global_object_class: The class to use when creating the global object.
Sourcepub fn group(&self) -> JSContextGroup
pub fn group(&self) -> JSContextGroup
Gets the context group to which a JavaScript execution context belongs.
Sourcepub fn name(&self) -> Option<JSString>
pub fn name(&self) -> Option<JSString>
Gets a copy of the name of a context.
A JSContext’s name is exposed for remote debugging
to make it easier to identify the context you would like to
attach to.
Returns the name for this context, if there is one.
let ctx = JSContext::new();
// By default, a context has no name.
assert!(ctx.name().is_none());Sourcepub fn set_name<S: Into<JSString>>(&self, name: S)
pub fn set_name<S: Into<JSString>>(&self, name: S)
Sets the remote debugging name for a context.
name: The remote debugging name to set.
let ctx = JSContext::new();
ctx.set_name("test thread");
assert_eq!(ctx.name().unwrap(), "test thread");Sourcepub fn global_object(&self) -> Result<JSObject, JSException>
pub fn global_object(&self) -> Result<JSObject, JSException>
Get the global object of this context.
let ctx = JSContext::new();
assert!(ctx.global_object().is_ok());Trait Implementations§
Source§impl Default for JSContext
impl Default for JSContext
Source§fn default() -> Self
fn default() -> Self
Creates a global JavaScript execution context and populates it
with all the built-in JavaScript objects, such as Object,
Function, String, and Array.
In WebKit version 4.0 and later, the context is created in a unique context group. Therefore, scripts may execute in it concurrently with scripts executing in other contexts. However, you may not use values created in the context in other contexts.