Struct chakracore::context::Context
[−]
[src]
pub struct Context(_);
A sandboxed execution context with its own set of built-in objects and functions.
The majority of APIs require an active context.
In a browser or Node.JS environment, the task of executing promises is
handled by the runtime. This is not the case with ChakraCore. To run
promise chains, execute_tasks
must be called at a regular interval. This
is done using the ContextGuard
.
Methods
impl Context
[src]
fn new(runtime: &Runtime) -> Result<Context>
Creates a new context and returns a handle to it.
fn make_current<'a>(&'a self) -> Result<ContextGuard<'a>>
Binds the context to the current scope.
unsafe fn get_current<'a>() -> Option<ContextGuard<'a>>
Returns the active context in the current thread.
This is unsafe because there should be little reason to use it in idiomatic code.
Usage patterns should utilize ContextGuard
or
exec_with_current
instead.
This ContextGuard
does not reset the current context upon destruction,
in contrast to a normally allocated ContextGuard
. This is merely a
hollow reference.
fn exec_with<Ret, T: FnOnce(&ContextGuard) -> Ret>(
&self,
callback: T
) -> Result<Ret>
&self,
callback: T
) -> Result<Ret>
Binds the context to the closure's scope.
let result = context.exec_with(|guard| script::eval(guard, "1 + 1")).unwrap();
fn exec_with_current<Ret, T: FnOnce(&ContextGuard) -> Ret>(
callback: T
) -> Option<Ret>
callback: T
) -> Option<Ret>
Executes a closure with the thread's active context.
This is a safe alternative to get_current
. It will either return the
closures result wrapped in Some
, or None
, if no context is currently
active.
fn insert_user_data<T>(&self, value: T) -> Option<T> where
T: Send + 'static,
T: Send + 'static,
Set user data associated with the context.
- Only one value per type.
- The internal implementation uses
AnyMap
. - Returns a previous value if applicable.
- The data will live as long as the runtime keeps the context.
fn remove_user_data<T>(&self) -> Option<T> where
T: Send + 'static,
T: Send + 'static,
Remove user data associated with the context.
fn get_user_data<T>(&self) -> Option<&T> where
T: Send + 'static,
T: Send + 'static,
Get user data associated with the context.
fn get_user_data_mut<T>(&self) -> Option<&mut T> where
T: Send + 'static,
T: Send + 'static,
Get mutable user data associated with the context.
impl Context
[src]
unsafe fn from_raw(value: JsRef) -> Context
Creates an instance from a raw pointer.
This is used for managing the lifetime of JSRT objects. They are
tracked using reference counting; incrementing with from_raw
,
and decrementing with drop
.
This is required to support items stored on the heap, since the JSRT runtime only observes the stack.
If used in conjunction with a Property
or any Value
, it is
assumed a Context
is active.
fn as_raw(&self) -> JsRef
Returns the underlying raw pointer.
Trait Implementations
impl Debug for Context
[src]
impl PartialEq for Context
[src]
fn eq(&self, __arg_0: &Context) -> bool
This method tests for self
and other
values to be equal, and is used by ==
. Read more
fn ne(&self, __arg_0: &Context) -> bool
This method tests for !=
.
impl Clone for Context
[src]
fn clone(&self) -> Context
Duplicates a reference counted type.
The underlying pointer will be copied, and its reference count will be incremented, returned wrapped as the type.
fn clone_from(&mut self, source: &Self)
1.0.0
Performs copy-assignment from source
. Read more
impl Drop for Context
[src]
fn drop(&mut self)
Decrements the reference counter.