Skip to content

Commit

Permalink
Remove conversion of non-string literals and remove From<String> for …
Browse files Browse the repository at this point in the history
…JsValue
  • Loading branch information
hansl committed Jul 16, 2024
1 parent b15b66d commit e74ca1c
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 21 deletions.
11 changes: 8 additions & 3 deletions core/engine/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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)
Expand Down
18 changes: 0 additions & 18 deletions core/engine/src/value/conversions/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,24 +39,6 @@ impl From<char> 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<String> for JsValue {
#[inline]
fn from(value: String) -> Self {
let _timer = Profiler::global().start_event("From<&str>", "value");

Self::from(JsString::from(value))
}
}

impl From<JsSymbol> for JsValue {
#[inline]
fn from(value: JsSymbol) -> Self {
Expand Down

0 comments on commit e74ca1c

Please sign in to comment.