Struct JSContext

Source
pub struct JSContext { /* private fields */ }
Expand description

A JavaScript execution context.

Holds the global object and other execution state.

Implementations§

Source§

impl JSContext

Source

pub const unsafe fn from_raw(raw: JSGlobalContextRef) -> Self

Create a new Self from its raw pointer directly.

§Safety

Ensure raw is valid.

Source

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.

Source

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.
Source

pub fn group(&self) -> JSContextGroup

Gets the context group to which a JavaScript execution context belongs.

Source

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());
Source

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");
Source

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

Source§

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.

Source§

impl Drop for JSContext

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.