1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-28 05:17:34 +00:00

LibJS: Use special case folding for String.prototype.to{Lower,Upper}Case

Note we still have one String.prototype.toLowerCase test262 failure due
to not yet parsing WordBreakProperty.txt.
This commit is contained in:
Timothy Flynn 2021-07-27 14:02:47 -04:00 committed by Linus Groh
parent 39f971e42b
commit 2dc9ae00af
3 changed files with 40 additions and 18 deletions

View file

@ -381,33 +381,23 @@ JS_DEFINE_NATIVE_FUNCTION(StringPrototype::index_of)
// 22.1.3.26 String.prototype.toLowerCase ( ), https://tc39.es/ecma262/#sec-string.prototype.tolowercase
JS_DEFINE_NATIVE_FUNCTION(StringPrototype::to_lowercase)
{
auto string = utf16_string_from(vm, global_object);
if (vm.exception())
auto string = ak_string_from(vm, global_object);
if (!string.has_value())
return {};
Utf16View utf16_string_view { string };
StringBuilder builder;
for (auto code_point : utf16_string_view)
builder.append_code_point(Unicode::to_unicode_lowercase(code_point));
return js_string(vm, builder.to_string());
auto lowercase = Unicode::to_unicode_lowercase_full(*string);
return js_string(vm, move(lowercase));
}
// 22.1.3.28 String.prototype.toUpperCase ( ), https://tc39.es/ecma262/#sec-string.prototype.touppercase
JS_DEFINE_NATIVE_FUNCTION(StringPrototype::to_uppercase)
{
auto string = utf16_string_from(vm, global_object);
if (vm.exception())
auto string = ak_string_from(vm, global_object);
if (!string.has_value())
return {};
Utf16View utf16_string_view { string };
StringBuilder builder;
for (auto code_point : utf16_string_view)
builder.append_code_point(Unicode::to_unicode_uppercase(code_point));
return js_string(vm, builder.to_string());
auto uppercase = Unicode::to_unicode_uppercase_full(*string);
return js_string(vm, move(uppercase));
}
// 22.1.3.27 String.prototype.toString ( ), https://tc39.es/ecma262/#sec-string.prototype.tostring