diff options
author | Nayeem Rahman <nayeemrmn99@gmail.com> | 2022-04-26 14:28:42 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-04-26 15:28:42 +0200 |
commit | 74175c039ae0f1c75ca6a006262c1541f770b090 (patch) | |
tree | e0ffc6f8a34e44f13c1cb6c31dd92597674ad116 /core/error.rs | |
parent | 3c7c5865778360aeb2b1285a414d1f8d878d7a22 (diff) |
refactor(core): Remove ErrWithV8Handle (#14394)
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::*; |