Skip to content

Commit

Permalink
Fix js_str macro to correctly handle latin1 strings
Browse files Browse the repository at this point in the history
  • Loading branch information
jedel1043 committed Aug 19, 2024
1 parent 424896d commit 3a964e7
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions core/macros/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand All @@ -197,8 +196,9 @@ pub fn js_str(input: TokenStream) -> TokenStream {
})
.collect::<Vec<_>>();
if is_latin1 {
let latin1 = utf16.iter().map(|&c| c as u8).collect::<Vec<_>>();
quote! {
::boa_engine::string::JsStr::latin1(#utf8.as_bytes())
::boa_engine::string::JsStr::latin1([#(#latin1),*].as_slice())
}
} else {
quote! {
Expand Down

0 comments on commit 3a964e7

Please sign in to comment.