0
0
Fork 0
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:
Bert Belder 2019-12-21 04:00:17 +01:00
parent 52da1f3216
commit fab24e032e
No known key found for this signature in database
GPG key ID: 7A77887B2E2ED461
2 changed files with 8 additions and 8 deletions

View file

@ -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;

View file

@ -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<Isolate>) -> 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<Local<'tc, Message>>
where
Self: 'tc,
{
pub fn message(&self) -> Option<Local<'tc, Message>> {
unsafe { Local::from_raw(v8__TryCatch__Message(&self.0)) }
}