mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 14:17:36 +00:00
LibJS: Handle existing Intl.Locale objects in CanonicalizeLocaleList
This commit is contained in:
parent
4de05faa8a
commit
27fc3cfe75
2 changed files with 22 additions and 8 deletions
|
@ -12,6 +12,7 @@
|
||||||
#include <LibJS/Runtime/Array.h>
|
#include <LibJS/Runtime/Array.h>
|
||||||
#include <LibJS/Runtime/GlobalObject.h>
|
#include <LibJS/Runtime/GlobalObject.h>
|
||||||
#include <LibJS/Runtime/Intl/AbstractOperations.h>
|
#include <LibJS/Runtime/Intl/AbstractOperations.h>
|
||||||
|
#include <LibJS/Runtime/Intl/Locale.h>
|
||||||
#include <LibUnicode/Locale.h>
|
#include <LibUnicode/Locale.h>
|
||||||
|
|
||||||
namespace JS::Intl {
|
namespace JS::Intl {
|
||||||
|
@ -150,8 +151,7 @@ Vector<String> canonicalize_locale_list(GlobalObject& global_object, Value local
|
||||||
|
|
||||||
Object* object = nullptr;
|
Object* object = nullptr;
|
||||||
// 3. If Type(locales) is String or Type(locales) is Object and locales has an [[InitializedLocale]] internal slot, then
|
// 3. If Type(locales) is String or Type(locales) is Object and locales has an [[InitializedLocale]] internal slot, then
|
||||||
// FIXME: When we have an Intl.Locale object, handle it it here.
|
if (locales.is_string() || (locales.is_object() && is<Locale>(locales.as_object()))) {
|
||||||
if (locales.is_string()) {
|
|
||||||
// a. Let O be CreateArrayFromList(« locales »).
|
// a. Let O be CreateArrayFromList(« locales »).
|
||||||
object = Array::create_from(global_object, { locales });
|
object = Array::create_from(global_object, { locales });
|
||||||
}
|
}
|
||||||
|
@ -195,14 +195,20 @@ Vector<String> canonicalize_locale_list(GlobalObject& global_object, Value local
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
String tag;
|
||||||
|
|
||||||
// iii. If Type(kValue) is Object and kValue has an [[InitializedLocale]] internal slot, then
|
// iii. If Type(kValue) is Object and kValue has an [[InitializedLocale]] internal slot, then
|
||||||
// 1. Let tag be kValue.[[Locale]].
|
if (key_value.is_object() && is<Locale>(key_value.as_object())) {
|
||||||
|
// 1. Let tag be kValue.[[Locale]].
|
||||||
|
tag = static_cast<Locale const&>(key_value.as_object()).locale();
|
||||||
|
}
|
||||||
// iv. Else,
|
// iv. Else,
|
||||||
// 1. Let tag be ? ToString(kValue).
|
else {
|
||||||
// FIXME: When we have an Intl.Locale object, handle it it here.
|
// 1. Let tag be ? ToString(kValue).
|
||||||
auto tag = key_value.to_string(global_object);
|
tag = key_value.to_string(global_object);
|
||||||
if (vm.exception())
|
if (vm.exception())
|
||||||
return {};
|
return {};
|
||||||
|
}
|
||||||
|
|
||||||
// v. If IsStructurallyValidLanguageTag(tag) is false, throw a RangeError exception.
|
// v. If IsStructurallyValidLanguageTag(tag) is false, throw a RangeError exception.
|
||||||
auto locale_id = is_structurally_valid_language_tag(tag);
|
auto locale_id = is_structurally_valid_language_tag(tag);
|
||||||
|
|
|
@ -115,4 +115,12 @@ describe("normal behavior", () => {
|
||||||
"en-US-u-1k-aaa-2k-ccc",
|
"en-US-u-1k-aaa-2k-ccc",
|
||||||
]);
|
]);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test("canonicalize locale objects", () => {
|
||||||
|
const en = new Intl.Locale("en", { script: "Latn" });
|
||||||
|
expect(Intl.getCanonicalLocales(en)).toEqual(["en-Latn"]);
|
||||||
|
|
||||||
|
const es = new Intl.Locale("es", { region: "419" });
|
||||||
|
expect(Intl.getCanonicalLocales([en, es])).toEqual(["en-Latn", "es-419"]);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue