From e74ca1c6c8dec038b1d38474fb45a4561d94e508 Mon Sep 17 00:00:00 2001 From: Hans Larsen Date: Tue, 16 Jul 2024 12:08:06 -0700 Subject: [PATCH] Remove conversion of non-string literals and remove From for JsValue --- core/engine/src/error.rs | 11 ++++++++--- core/engine/src/value/conversions/mod.rs | 18 ------------------ 2 files changed, 8 insertions(+), 21 deletions(-) diff --git a/core/engine/src/error.rs b/core/engine/src/error.rs index 83c09998224..a22780bd858 100644 --- a/core/engine/src/error.rs +++ b/core/engine/src/error.rs @@ -14,8 +14,7 @@ use boa_gc::{custom_trace, Finalize, Trace}; use boa_macros::js_str; use thiserror::Error; -/// Create an opaque error object from a value. This can be a literal or any -/// value that can be converted to a `JsValue`. +/// Create an opaque error object from a value or string literal. /// /// Can be used with an expression that converts into `JsValue` or a format /// string with arguments. @@ -34,11 +33,17 @@ use thiserror::Error; /// let error = js_error!("error: {}", 5); /// assert_eq!(error.as_opaque().unwrap().to_string(context).unwrap(), "error: 5"); /// -/// let error = js_error!(true); +/// // Non-string literals must be used as an expression. +/// let error = js_error!({ true }); /// assert_eq!(error.as_opaque().unwrap(), &JsValue::from(true)); /// ``` #[macro_export] macro_rules! js_error { + ($value: literal) => { + $crate::JsError::from_opaque($crate::JsValue::from( + $crate::js_string!($value) + )) + }; ($value: expr) => { $crate::JsError::from_opaque( $crate::JsValue::from($value) diff --git a/core/engine/src/value/conversions/mod.rs b/core/engine/src/value/conversions/mod.rs index 352170e561d..b247db10f93 100644 --- a/core/engine/src/value/conversions/mod.rs +++ b/core/engine/src/value/conversions/mod.rs @@ -39,24 +39,6 @@ impl From for JsValue { } } -impl From<&str> for JsValue { - #[inline] - fn from(value: &str) -> Self { - let _timer = Profiler::global().start_event("From<&str>", "value"); - - Self::from(js_string!(value)) - } -} - -impl From for JsValue { - #[inline] - fn from(value: String) -> Self { - let _timer = Profiler::global().start_event("From<&str>", "value"); - - Self::from(JsString::from(value)) - } -} - impl From for JsValue { #[inline] fn from(value: JsSymbol) -> Self {