Struct v8::Context

source ·
#[repr(C)]
pub struct Context(/* private fields */);
Expand description

A sandboxed execution context with its own set of built-in objects and functions.

Implementations§

source§

impl Context

source

pub fn new<'s>(scope: &mut HandleScope<'s, ()>) -> Local<'s, Context>

Creates a new context.

source

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.

source

pub fn get_extras_binding_object<'s>( &self, scope: &mut HandleScope<'s, ()> ) -> Local<'s, Object>

source

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.

source

pub fn get_microtask_queue(&self) -> &MicrotaskQueue

source

pub fn set_microtask_queue(&self, microtask_queue: &MicrotaskQueue)

source

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().

source

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().

source

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.

source

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.

source

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.

source

pub unsafe fn set_aligned_pointer_in_embedder_data( &self, slot: i32, data: *mut c_void )

source

pub fn get_aligned_pointer_from_embedder_data(&self, slot: i32) -> *mut c_void

source

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.

source

pub fn get_security_token<'s>( &self, scope: &mut HandleScope<'s, ()> ) -> Local<'s, Value>

source

pub fn set_security_token(&self, token: Local<'_, Value>)

source

pub fn use_default_security_token(&self)

source

pub fn set_allow_generation_from_strings(&self, allow: bool)

source

pub fn is_code_generation_from_strings_allowed(&self) -> bool

Methods from Deref<Target = Data>§

source

pub fn is_big_int(&self) -> bool

Returns true if this data is a BigInt.

source

pub fn is_boolean(&self) -> bool

Returns true if this data is a Boolean.

source

pub fn is_context(&self) -> bool

Returns true if this data is a Context.

source

pub fn is_fixed_array(&self) -> bool

Returns true if this data is a FixedArray.

source

pub fn is_function_template(&self) -> bool

Returns true if this data is a FunctionTemplate.

source

pub fn is_module(&self) -> bool

Returns true if this data is a Module.

source

pub fn is_module_request(&self) -> bool

Returns true if this data is a ModuleRequest.

source

pub fn is_name(&self) -> bool

Returns true if this data is a Name.

source

pub fn is_number(&self) -> bool

Returns true if this data is a Number.

source

pub fn is_object_template(&self) -> bool

Returns true if this data is a ObjectTemplate.

source

pub fn is_primitive(&self) -> bool

Returns true if this data is a Primitive.

source

pub fn is_private(&self) -> bool

Returns true if this data is a Private.

source

pub fn is_string(&self) -> bool

Returns true if this data is a String.

source

pub fn is_symbol(&self) -> bool

Returns true if this data is a Symbol.

source

pub fn is_value(&self) -> bool

Returns true if this data is a Value.

Trait Implementations§

source§

impl Debug for Context

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl Deref for Context

§

type Target = Data

The resulting type after dereferencing.
source§

fn deref(&self) -> &Self::Target

Dereferences the value.
source§

impl<'s> PartialEq<Context> for Data

source§

fn eq(&self, other: &Context) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl<'s> PartialEq<Data> for Context

source§

fn eq(&self, other: &Data) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl<'s> PartialEq for Context

source§

fn eq(&self, other: &Context) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl Eq for Context

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>,

§

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>,

§

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.