Explorar o código

LibJS: Convert short string literal PrimitiveString instances to String

Timothy Flynn %!s(int64=2) %!d(string=hai) anos
pai
achega
69a56a8e39

+ 2 - 2
Userland/Libraries/LibJS/Runtime/NumberPrototype.cpp

@@ -450,9 +450,9 @@ JS_DEFINE_NATIVE_FUNCTION(NumberPrototype::to_string)
     if (number_value.is_negative_infinity())
         return PrimitiveString::create(vm, "-Infinity");
     if (number_value.is_nan())
-        return PrimitiveString::create(vm, "NaN");
+        return PrimitiveString::create(vm, String::from_utf8_short_string("NaN"sv));
     if (number_value.is_positive_zero() || number_value.is_negative_zero())
-        return PrimitiveString::create(vm, "0");
+        return PrimitiveString::create(vm, String::from_utf8_short_string("0"sv));
 
     double number = number_value.as_double();
     bool negative = number < 0;

+ 1 - 1
Userland/Libraries/LibJS/Runtime/StringPrototype.cpp

@@ -494,7 +494,7 @@ JS_DEFINE_NATIVE_FUNCTION(StringPrototype::match_all)
 
     auto string = TRY(this_object.to_utf16_string(vm));
 
-    auto rx = TRY(regexp_create(vm, regexp, PrimitiveString::create(vm, "g")));
+    auto rx = TRY(regexp_create(vm, regexp, PrimitiveString::create(vm, String::from_utf8_short_string("g"sv))));
     return TRY(Value(rx).invoke(vm, *vm.well_known_symbol_match_all(), PrimitiveString::create(vm, move(string))));
 }