From fab24e032e1eb701e1188ff4ce7f5b5986c06f52 Mon Sep 17 00:00:00 2001 From: Bert Belder Date: Sat, 21 Dec 2019 04:00:17 +0100 Subject: [PATCH] Make TryCatchScope public, improve doc strings (#102) --- src/lib.rs | 2 +- src/try_catch.rs | 14 +++++++------- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 1d9c6d91..a677e0d4 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -60,5 +60,5 @@ pub use property::PropertyCallbackInfo; pub use script::{Script, ScriptOrigin}; pub use string::NewStringType; pub use string::String; -pub use try_catch::TryCatch; +pub use try_catch::{TryCatch, TryCatchScope}; pub use value::Value; diff --git a/src/try_catch.rs b/src/try_catch.rs index a1bf42de..2c8cef41 100644 --- a/src/try_catch.rs +++ b/src/try_catch.rs @@ -53,6 +53,7 @@ extern "C" { /// An external exception handler. pub struct TryCatch<'tc>(TryCatchState<'tc>); +/// An activated TryCatch handler that is active as long as it is in scope. #[repr(transparent)] pub struct TryCatchScope<'tc>(CxxTryCatch, PhantomData<&'tc ()>); @@ -66,15 +67,17 @@ enum TryCatchState<'tc> { } impl<'tc> TryCatch<'tc> { - /// Creates a new try/catch block and registers it with v8. Note that - /// all TryCatch blocks should be stack allocated because the memory - /// location itself is compared against JavaScript try/catch blocks. + /// Creates a new try/catch block. Note that all TryCatch blocks should be + /// stack allocated because the memory location itself is compared against + /// JavaScript try/catch blocks. pub fn new(scope: &mut impl AsMut) -> Self { Self(TryCatchState::New { 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 { use TryCatchState::*; let state = &mut self.0; @@ -156,10 +159,7 @@ impl<'tc> TryCatchScope<'tc> { /// /// The returned handle is valid until this TryCatch block has been /// destroyed. - pub fn message(&self) -> Option> - where - Self: 'tc, - { + pub fn message(&self) -> Option> { unsafe { Local::from_raw(v8__TryCatch__Message(&self.0)) } }