From 3a964e7df30272d2c476060a74ef91ad943bd2f9 Mon Sep 17 00:00:00 2001 From: jedel1043 Date: Sun, 18 Aug 2024 23:08:30 -0600 Subject: [PATCH] Fix `js_str` macro to correctly handle latin1 strings --- core/macros/src/lib.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/core/macros/src/lib.rs b/core/macros/src/lib.rs index 027e6c0478a..5d71196faeb 100644 --- a/core/macros/src/lib.rs +++ b/core/macros/src/lib.rs @@ -185,10 +185,9 @@ pub fn utf16(input: TokenStream) -> TokenStream { #[proc_macro] pub fn js_str(input: TokenStream) -> TokenStream { let literal = parse_macro_input!(input as LitStr); - let utf8 = literal.value(); let mut is_latin1 = true; - let utf16 = utf8 + let utf16 = literal.value() .encode_utf16() .inspect(|x| { if *x > u8::MAX.into() { @@ -197,8 +196,9 @@ pub fn js_str(input: TokenStream) -> TokenStream { }) .collect::>(); if is_latin1 { + let latin1 = utf16.iter().map(|&c| c as u8).collect::>(); quote! { - ::boa_engine::string::JsStr::latin1(#utf8.as_bytes()) + ::boa_engine::string::JsStr::latin1([#(#latin1),*].as_slice()) } } else { quote! {