mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 06:27:45 +00:00
LibJS: Add [[LanguageDisplay]] to Intl.DisplayNames's resolvedOptions
This commit is contained in:
parent
27c845eef2
commit
1a3e6e8a7b
2 changed files with 56 additions and 0 deletions
|
@ -116,6 +116,10 @@ JS_DEFINE_NATIVE_FUNCTION(DisplayNamesPrototype::resolved_options)
|
||||||
MUST(options->create_data_property_or_throw(vm.names.type, js_string(vm, display_names->type_string())));
|
MUST(options->create_data_property_or_throw(vm.names.type, js_string(vm, display_names->type_string())));
|
||||||
MUST(options->create_data_property_or_throw(vm.names.fallback, js_string(vm, display_names->fallback_string())));
|
MUST(options->create_data_property_or_throw(vm.names.fallback, js_string(vm, display_names->fallback_string())));
|
||||||
|
|
||||||
|
// NOTE: Step 4c indicates languageDisplay must not be undefined, but it is only set when the type option is language.
|
||||||
|
if (display_names->has_language_display())
|
||||||
|
MUST(options->create_data_property_or_throw(vm.names.languageDisplay, js_string(vm, display_names->language_display_string())));
|
||||||
|
|
||||||
// 5. Return options.
|
// 5. Return options.
|
||||||
return options;
|
return options;
|
||||||
}
|
}
|
||||||
|
|
|
@ -26,6 +26,58 @@ describe("correct behavior", () => {
|
||||||
style: "short",
|
style: "short",
|
||||||
type: "language",
|
type: "language",
|
||||||
fallback: "code",
|
fallback: "code",
|
||||||
|
languageDisplay: "dialect",
|
||||||
|
});
|
||||||
|
|
||||||
|
const ar = new Intl.DisplayNames("ar", { type: "calendar" });
|
||||||
|
expect(ar.resolvedOptions()).toEqual({
|
||||||
|
locale: "ar",
|
||||||
|
style: "long",
|
||||||
|
type: "calendar",
|
||||||
|
fallback: "code",
|
||||||
|
});
|
||||||
|
|
||||||
|
const fr = new Intl.DisplayNames("fr", { type: "dateTimeField" });
|
||||||
|
expect(fr.resolvedOptions()).toEqual({
|
||||||
|
locale: "fr",
|
||||||
|
style: "long",
|
||||||
|
type: "dateTimeField",
|
||||||
|
fallback: "code",
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
test("all valid language displays", () => {
|
||||||
|
const en = new Intl.DisplayNames("en", { type: "language" });
|
||||||
|
expect(en.resolvedOptions()).toEqual({
|
||||||
|
locale: "en",
|
||||||
|
style: "long",
|
||||||
|
type: "language",
|
||||||
|
fallback: "code",
|
||||||
|
languageDisplay: "dialect",
|
||||||
|
});
|
||||||
|
|
||||||
|
const es419 = new Intl.DisplayNames("es-419", {
|
||||||
|
type: "language",
|
||||||
|
languageDisplay: "dialect",
|
||||||
|
});
|
||||||
|
expect(es419.resolvedOptions()).toEqual({
|
||||||
|
locale: "es-419",
|
||||||
|
style: "long",
|
||||||
|
type: "language",
|
||||||
|
fallback: "code",
|
||||||
|
languageDisplay: "dialect",
|
||||||
|
});
|
||||||
|
|
||||||
|
const zhHant = new Intl.DisplayNames(["zh-Hant"], {
|
||||||
|
type: "language",
|
||||||
|
languageDisplay: "standard",
|
||||||
|
});
|
||||||
|
expect(zhHant.resolvedOptions()).toEqual({
|
||||||
|
locale: "zh-Hant",
|
||||||
|
style: "long",
|
||||||
|
type: "language",
|
||||||
|
fallback: "code",
|
||||||
|
languageDisplay: "standard",
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue