diff options
Diffstat (limited to 'core/error.rs')
-rw-r--r-- | core/error.rs | 57 |
1 files changed, 9 insertions, 48 deletions
diff --git a/core/error.rs b/core/error.rs index 8014dceab..587581e82 100644 --- a/core/error.rs +++ b/core/error.rs @@ -389,12 +389,16 @@ impl Display for JsError { } } -pub(crate) fn attach_handle_to_error( - scope: &mut v8::Isolate, +// TODO(piscisaureus): rusty_v8 should implement the Error trait on +// values of type v8::Global<T>. +pub(crate) fn to_v8_type_error( + scope: &mut v8::HandleScope, err: Error, - handle: v8::Local<v8::Value>, -) -> Error { - ErrWithV8Handle::new(scope, err, handle).into() +) -> v8::Global<v8::Value> { + let message = err.to_string(); + let message = v8::String::new(scope, &message).unwrap(); + let exception = v8::Exception::type_error(scope, message); + v8::Global::new(scope, exception) } /// Implements `value instanceof primordials.Error` in JS. Similar to @@ -431,49 +435,6 @@ pub(crate) fn is_instance_of_error<'s>( false } -// TODO(piscisaureus): rusty_v8 should implement the Error trait on -// values of type v8::Global<T>. -pub(crate) struct ErrWithV8Handle { - err: Error, - handle: v8::Global<v8::Value>, -} - -impl ErrWithV8Handle { - pub fn new( - scope: &mut v8::Isolate, - err: Error, - handle: v8::Local<v8::Value>, - ) -> Self { - let handle = v8::Global::new(scope, handle); - Self { err, handle } - } - - pub fn get_handle<'s>( - &self, - scope: &mut v8::HandleScope<'s>, - ) -> v8::Local<'s, v8::Value> { - v8::Local::new(scope, &self.handle) - } -} - -#[allow(clippy::non_send_fields_in_send_ty)] -unsafe impl Send for ErrWithV8Handle {} -unsafe impl Sync for ErrWithV8Handle {} - -impl std::error::Error for ErrWithV8Handle {} - -impl Display for ErrWithV8Handle { - fn fmt(&self, f: &mut Formatter) -> fmt::Result { - <Error as Display>::fmt(&self.err, f) - } -} - -impl Debug for ErrWithV8Handle { - fn fmt(&self, f: &mut Formatter) -> fmt::Result { - <Self as Display>::fmt(self, f) - } -} - #[cfg(test)] mod tests { use super::*; |