11use crate :: {
2- Context , JsBigInt , JsResult , JsValue , JsVariant ,
2+ Context , JsBigInt , JsResult , JsString , JsValue , JsVariant ,
33 builtins:: {
44 Number ,
55 number:: { f64_to_int32, f64_to_uint32} ,
66 } ,
77 error:: JsNativeError ,
8- js_string,
98 value:: { JsSymbol , Numeric , PreferredType } ,
109} ;
1110
@@ -24,15 +23,29 @@ impl JsValue {
2423 ( JsVariant :: BigInt ( x) , JsVariant :: BigInt ( y) ) => Self :: new ( JsBigInt :: add ( & x, & y) ) ,
2524
2625 // String concat
27- ( JsVariant :: String ( x) , JsVariant :: String ( y) ) => Self :: from ( js_string ! ( & x, & y) ) ,
26+ ( JsVariant :: String ( x) , JsVariant :: String ( y) ) => {
27+ let result = JsString :: concat ( x. as_str ( ) , y. as_str ( ) )
28+ . map_err ( |_| JsNativeError :: range ( ) . with_message ( "Invalid string length" ) ) ?;
29+ Self :: from ( result)
30+ }
2831
2932 // Slow path:
3033 ( _, _) => {
3134 let x = self . to_primitive ( context, PreferredType :: Default ) ?;
3235 let y = other. to_primitive ( context, PreferredType :: Default ) ?;
3336 match ( x. variant ( ) , y. variant ( ) ) {
34- ( JsVariant :: String ( x) , _) => Self :: from ( js_string ! ( & x, & y. to_string( context) ?) ) ,
35- ( _, JsVariant :: String ( y) ) => Self :: from ( js_string ! ( & x. to_string( context) ?, & y) ) ,
37+ ( JsVariant :: String ( x) , _) => {
38+ let y_str = y. to_string ( context) ?;
39+ let result = JsString :: concat ( x. as_str ( ) , y_str. as_str ( ) )
40+ . map_err ( |_| JsNativeError :: range ( ) . with_message ( "Invalid string length" ) ) ?;
41+ Self :: from ( result)
42+ }
43+ ( _, JsVariant :: String ( y) ) => {
44+ let x_str = x. to_string ( context) ?;
45+ let result = JsString :: concat ( x_str. as_str ( ) , y. as_str ( ) )
46+ . map_err ( |_| JsNativeError :: range ( ) . with_message ( "Invalid string length" ) ) ?;
47+ Self :: from ( result)
48+ }
3649 ( _, _) => {
3750 match ( x. to_numeric ( context) ?, y. to_numeric ( context) ?) {
3851 ( Numeric :: Number ( x) , Numeric :: Number ( y) ) => Self :: new ( x + y) ,
0 commit comments