Struct v8::CallbackScope
source · pub struct CallbackScope<'s, C = Context> { /* private fields */ }
Expand description
A CallbackScope
can be used to bootstrap a HandleScope
and
ContextScope
inside a callback function that gets called by V8.
Bootstrapping a scope inside a callback is the only valid use case of this
type; using it in other places leads to undefined behavior, which is also
the reason CallbackScope::new()
is marked as being an unsafe function.
For some callback types, rusty_v8 internally creates a scope and passes it as an argument to to embedder callback. Eventually we intend to wrap all callbacks in this fashion, so the embedder would never needs to construct a CallbackScope.
A CallbackScope<()>
, without context, can be created from:
&mut Isolate
&mut OwnedIsolate
A CallbackScope
, with context, can be created from:
Local<Context>
Local<Message>
Local<Object>
Local<Promise>
Local<SharedArrayBuffer>
&FunctionCallbackInfo
&PropertyCallbackInfo
&PromiseRejectMessage
Implementations§
source§impl<'s> CallbackScope<'s>
impl<'s> CallbackScope<'s>
Methods from Deref<Target = HandleScope<'s>>§
sourcepub fn get_current_context(&self) -> Local<'s, Context>
pub fn get_current_context(&self) -> Local<'s, Context>
Returns the context of the currently running JavaScript, or the context on the top of the stack if no JavaScript is running.
sourcepub fn get_entered_or_microtask_context(&self) -> Local<'s, Context>
pub fn get_entered_or_microtask_context(&self) -> Local<'s, Context>
Returns either the last context entered through V8’s C++ API, or the context of the currently running microtask while processing microtasks. If a context is entered while executing a microtask, that context is returned.
sourcepub fn throw_exception(
&mut self,
exception: Local<'_, Value>
) -> Local<'s, Value>
pub fn throw_exception( &mut self, exception: Local<'_, Value> ) -> Local<'s, Value>
Schedules an exception to be thrown when returning to JavaScript. When an exception has been scheduled it is illegal to invoke any JavaScript operation; the caller must return immediately and only after the exception has been handled does it become legal to invoke JavaScript operations.
This function always returns the undefined
value.
sourcepub fn get_isolate_data_from_snapshot_once<T>(
&mut self,
index: usize
) -> Result<Local<'s, T>, DataError>where
T: 'static,
for<'l> Local<'l, Data>: TryInto<Local<'l, T>, Error = DataError>,
pub fn get_isolate_data_from_snapshot_once<T>( &mut self, index: usize ) -> Result<Local<'s, T>, DataError>where T: 'static, for<'l> Local<'l, Data>: TryInto<Local<'l, T>, Error = DataError>,
Return data that was previously attached to the isolate snapshot via
SnapshotCreator, and removes the reference to it. If called again with
same index
argument, this function returns DataError::NoData
.
The value that was stored in the snapshot must either match or be
convertible to type parameter T
, otherwise DataError::BadType
is
returned.
sourcepub fn get_context_data_from_snapshot_once<T>(
&mut self,
index: usize
) -> Result<Local<'s, T>, DataError>where
T: 'static,
for<'l> Local<'l, Data>: TryInto<Local<'l, T>, Error = DataError>,
pub fn get_context_data_from_snapshot_once<T>( &mut self, index: usize ) -> Result<Local<'s, T>, DataError>where T: 'static, for<'l> Local<'l, Data>: TryInto<Local<'l, T>, Error = DataError>,
Return data that was previously attached to the context snapshot via
SnapshotCreator, and removes the reference to it. If called again with
same index
argument, this function returns DataError::NoData
.
The value that was stored in the snapshot must either match or be
convertible to type parameter T
, otherwise DataError::BadType
is
returned.