#[repr(C)]pub struct Context(_);
Expand description
A sandboxed execution context with its own set of built-in objects and functions.
Implementations§
source§impl Context
impl Context
sourcepub fn new_from_template<'s>(
scope: &mut HandleScope<'s, ()>,
templ: Local<'_, ObjectTemplate>
) -> Local<'s, Context>
pub fn new_from_template<'s>(
scope: &mut HandleScope<'s, ()>,
templ: Local<'_, ObjectTemplate>
) -> Local<'s, Context>
Creates a new context using the object template as the template for the global object.
pub fn get_extras_binding_object<'s>(
&self,
scope: &mut HandleScope<'s, ()>
) -> Local<'s, Object>
sourcepub fn global<'s>(&self, scope: &mut HandleScope<'s, ()>) -> Local<'s, Object>
pub fn global<'s>(&self, scope: &mut HandleScope<'s, ()>) -> Local<'s, Object>
Returns the global proxy object.
Global proxy object is a thin wrapper whose prototype points to actual context’s global object with the properties like Object, etc. This is done that way for security reasons (for more details see https://wiki.mozilla.org/Gecko:SplitWindow).
Please note that changes to global proxy object prototype most probably would break VM—v8 expects only global object as a prototype of global proxy object.
pub fn set_promise_hooks(
&self,
init_hook: Local<'_, Function>,
before_hook: Local<'_, Function>,
after_hook: Local<'_, Function>,
resolve_hook: Local<'_, Function>
)
sourcepub fn get_slot<'a, T: 'static>(
&'a self,
isolate: &'a mut Isolate
) -> Option<&'a T>
pub fn get_slot<'a, T: 'static>(
&'a self,
isolate: &'a mut Isolate
) -> Option<&'a T>
Get a reference to embedder data added with Self::set_slot()
.
sourcepub fn get_slot_mut<'a, T: 'static>(
&'a self,
isolate: &'a mut Isolate
) -> Option<&'a mut T>
pub fn get_slot_mut<'a, T: 'static>(
&'a self,
isolate: &'a mut Isolate
) -> Option<&'a mut T>
Get a mutable reference to embedder data added with Self::set_slot()
.
sourcepub fn set_slot<'a, T: 'static>(
&'a self,
isolate: &'a mut Isolate,
value: T
) -> bool
pub fn set_slot<'a, T: 'static>(
&'a self,
isolate: &'a mut Isolate,
value: T
) -> bool
Use with Context::get_slot
and Context::get_slot_mut
to associate
state with a Context.
This method gives ownership of value to the Context. Exactly one object of each type can be associated with a Context. If called more than once with an object of the same type, the earlier version will be dropped and replaced.
Returns true if value was set without replacing an existing value.
The value will be dropped when the context is garbage collected.
sourcepub fn remove_slot<'a, T: 'static>(
&'a self,
isolate: &'a mut Isolate
) -> Option<T>
pub fn remove_slot<'a, T: 'static>(
&'a self,
isolate: &'a mut Isolate
) -> Option<T>
Removes the embedder data added with Self::set_slot()
and returns it
if it exists.
sourcepub fn clear_all_slots<'a>(&'a self, isolate: &'a mut Isolate)
pub fn clear_all_slots<'a>(&'a self, isolate: &'a mut Isolate)
Removes all embedder data added with Self::set_slot()
, and
deletes any internal state needed to keep track of such slots.
This is needed to make a snapshot with
SnapshotCreator
, since the internal embedder
state uses Weak
handles, which cannot be alive at the time of
snapshotting.
sourcepub fn from_snapshot<'s>(
scope: &mut HandleScope<'s, ()>,
context_snapshot_index: usize
) -> Option<Local<'s, Context>>
pub fn from_snapshot<'s>(
scope: &mut HandleScope<'s, ()>,
context_snapshot_index: usize
) -> Option<Local<'s, Context>>
Create a new context from a (non-default) context snapshot. There is no way to provide a global object template since we do not create a new global object from template, but we can reuse a global object.
Methods from Deref<Target = Data>§
sourcepub fn is_big_int(&self) -> bool
pub fn is_big_int(&self) -> bool
Returns true if this data is a BigInt
.
sourcepub fn is_boolean(&self) -> bool
pub fn is_boolean(&self) -> bool
Returns true if this data is a Boolean
.
sourcepub fn is_context(&self) -> bool
pub fn is_context(&self) -> bool
Returns true if this data is a Context
.
sourcepub fn is_fixed_array(&self) -> bool
pub fn is_fixed_array(&self) -> bool
Returns true if this data is a FixedArray
.
sourcepub fn is_function_template(&self) -> bool
pub fn is_function_template(&self) -> bool
Returns true if this data is a FunctionTemplate
.
sourcepub fn is_module_request(&self) -> bool
pub fn is_module_request(&self) -> bool
Returns true if this data is a ModuleRequest
.
sourcepub fn is_object_template(&self) -> bool
pub fn is_object_template(&self) -> bool
Returns true if this data is a ObjectTemplate
.
sourcepub fn is_primitive(&self) -> bool
pub fn is_primitive(&self) -> bool
Returns true if this data is a Primitive
.
sourcepub fn is_private(&self) -> bool
pub fn is_private(&self) -> bool
Returns true if this data is a Private
.