mirror of
https://github.com/denoland/rusty_v8.git
synced 2025-01-12 17:09:28 -05:00
Make TryCatchScope public, improve doc strings (#102)
This commit is contained in:
parent
52da1f3216
commit
fab24e032e
2 changed files with 8 additions and 8 deletions
|
@ -60,5 +60,5 @@ pub use property::PropertyCallbackInfo;
|
||||||
pub use script::{Script, ScriptOrigin};
|
pub use script::{Script, ScriptOrigin};
|
||||||
pub use string::NewStringType;
|
pub use string::NewStringType;
|
||||||
pub use string::String;
|
pub use string::String;
|
||||||
pub use try_catch::TryCatch;
|
pub use try_catch::{TryCatch, TryCatchScope};
|
||||||
pub use value::Value;
|
pub use value::Value;
|
||||||
|
|
|
@ -53,6 +53,7 @@ extern "C" {
|
||||||
/// An external exception handler.
|
/// An external exception handler.
|
||||||
pub struct TryCatch<'tc>(TryCatchState<'tc>);
|
pub struct TryCatch<'tc>(TryCatchState<'tc>);
|
||||||
|
|
||||||
|
/// An activated TryCatch handler that is active as long as it is in scope.
|
||||||
#[repr(transparent)]
|
#[repr(transparent)]
|
||||||
pub struct TryCatchScope<'tc>(CxxTryCatch, PhantomData<&'tc ()>);
|
pub struct TryCatchScope<'tc>(CxxTryCatch, PhantomData<&'tc ()>);
|
||||||
|
|
||||||
|
@ -66,15 +67,17 @@ enum TryCatchState<'tc> {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'tc> TryCatch<'tc> {
|
impl<'tc> TryCatch<'tc> {
|
||||||
/// Creates a new try/catch block and registers it with v8. Note that
|
/// Creates a new try/catch block. Note that all TryCatch blocks should be
|
||||||
/// all TryCatch blocks should be stack allocated because the memory
|
/// stack allocated because the memory location itself is compared against
|
||||||
/// location itself is compared against JavaScript try/catch blocks.
|
/// JavaScript try/catch blocks.
|
||||||
pub fn new(scope: &mut impl AsMut<Isolate>) -> Self {
|
pub fn new(scope: &mut impl AsMut<Isolate>) -> Self {
|
||||||
Self(TryCatchState::New {
|
Self(TryCatchState::New {
|
||||||
isolate: scope.as_mut(),
|
isolate: scope.as_mut(),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Enters the TryCatch block. Exceptions are caught as long as the returned
|
||||||
|
/// TryCatchScope remains in scope.
|
||||||
pub fn enter(&'tc mut self) -> &'tc mut TryCatchScope {
|
pub fn enter(&'tc mut self) -> &'tc mut TryCatchScope {
|
||||||
use TryCatchState::*;
|
use TryCatchState::*;
|
||||||
let state = &mut self.0;
|
let state = &mut self.0;
|
||||||
|
@ -156,10 +159,7 @@ impl<'tc> TryCatchScope<'tc> {
|
||||||
///
|
///
|
||||||
/// The returned handle is valid until this TryCatch block has been
|
/// The returned handle is valid until this TryCatch block has been
|
||||||
/// destroyed.
|
/// destroyed.
|
||||||
pub fn message(&self) -> Option<Local<'tc, Message>>
|
pub fn message(&self) -> Option<Local<'tc, Message>> {
|
||||||
where
|
|
||||||
Self: 'tc,
|
|
||||||
{
|
|
||||||
unsafe { Local::from_raw(v8__TryCatch__Message(&self.0)) }
|
unsafe { Local::from_raw(v8__TryCatch__Message(&self.0)) }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue