diff --git a/boa_engine/src/builtins/intl/collator/mod.rs b/boa_engine/src/builtins/intl/collator/mod.rs index d23b0e99ae..61f10b900b 100644 --- a/boa_engine/src/builtins/intl/collator/mod.rs +++ b/boa_engine/src/builtins/intl/collator/mod.rs @@ -34,7 +34,7 @@ use crate::{ use super::{ locale::{canonicalize_locale_list, resolve_locale, supported_locales, validate_extension}, - options::{coerce_options_to_object, IntlOptions, LocaleMatcher}, + options::{coerce_options_to_object, IntlOptions}, Service, }; @@ -241,31 +241,28 @@ impl BuiltInConstructor for Collator { // a. Let localeData be %Collator%.[[SortLocaleData]]. // 6. Else, // a. Let localeData be %Collator%.[[SearchLocaleData]]. - let usage = - get_option::(&options, utf16!("usage"), false, context)?.unwrap_or_default(); + let usage = get_option(&options, utf16!("usage"), context)?.unwrap_or_default(); // 7. Let opt be a new Record. // 8. Let matcher be ? GetOption(options, "localeMatcher", string, « "lookup", "best fit" », "best fit"). // 9. Set opt.[[localeMatcher]] to matcher. - let matcher = - get_option::(&options, utf16!("localeMatcher"), false, context)? - .unwrap_or_default(); + let matcher = get_option(&options, utf16!("localeMatcher"), context)?.unwrap_or_default(); // 10. Let collation be ? GetOption(options, "collation", string, empty, undefined). // 11. If collation is not undefined, then // a. If collation does not match the Unicode Locale Identifier type nonterminal, throw a RangeError exception. // 12. Set opt.[[co]] to collation. - let collation = get_option::(&options, utf16!("collation"), false, context)?; + let collation = get_option(&options, utf16!("collation"), context)?; // 13. Let numeric be ? GetOption(options, "numeric", boolean, empty, undefined). // 14. If numeric is not undefined, then // a. Let numeric be ! ToString(numeric). // 15. Set opt.[[kn]] to numeric. - let numeric = get_option::(&options, utf16!("numeric"), false, context)?; + let numeric = get_option(&options, utf16!("numeric"), context)?; // 16. Let caseFirst be ? GetOption(options, "caseFirst", string, « "upper", "lower", "false" », undefined). // 17. Set opt.[[kf]] to caseFirst. - let case_first = get_option::(&options, utf16!("caseFirst"), false, context)?; + let case_first = get_option(&options, utf16!("caseFirst"), context)?; let mut intl_options = IntlOptions { matcher, @@ -314,22 +311,20 @@ impl BuiltInConstructor for Collator { // 26. Let sensitivity be ? GetOption(options, "sensitivity", string, « "base", "accent", "case", "variant" », undefined). // 28. Set collator.[[Sensitivity]] to sensitivity. - let sensitivity = - get_option::(&options, utf16!("sensitivity"), false, context)? - // 27. If sensitivity is undefined, then - // a. If usage is "sort", then - // i. Let sensitivity be "variant". - // b. Else, - // i. Let dataLocale be r.[[dataLocale]]. - // ii. Let dataLocaleData be localeData.[[]]. - // iii. Let sensitivity be dataLocaleData.[[sensitivity]]. - .or_else(|| (usage == Usage::Sort).then_some(Sensitivity::Variant)); + let sensitivity = get_option(&options, utf16!("sensitivity"), context)? + // 27. If sensitivity is undefined, then + // a. If usage is "sort", then + // i. Let sensitivity be "variant". + // b. Else, + // i. Let dataLocale be r.[[dataLocale]]. + // ii. Let dataLocaleData be localeData.[[]]. + // iii. Let sensitivity be dataLocaleData.[[sensitivity]]. + .or_else(|| (usage == Usage::Sort).then_some(Sensitivity::Variant)); // 29. Let ignorePunctuation be ? GetOption(options, "ignorePunctuation", boolean, empty, false). // 30. Set collator.[[IgnorePunctuation]] to ignorePunctuation. - let ignore_punctuation = - get_option::(&options, utf16!("ignorePunctuation"), false, context)? - .unwrap_or_default(); + let ignore_punctuation: bool = + get_option(&options, utf16!("ignorePunctuation"), context)?.unwrap_or_default(); let (strength, case_level) = sensitivity.map(Sensitivity::to_collator_options).unzip(); diff --git a/boa_engine/src/builtins/intl/list_format/mod.rs b/boa_engine/src/builtins/intl/list_format/mod.rs index 1041ef6786..59e114ab3b 100644 --- a/boa_engine/src/builtins/intl/list_format/mod.rs +++ b/boa_engine/src/builtins/intl/list_format/mod.rs @@ -22,7 +22,7 @@ use crate::{ use super::{ locale::{canonicalize_locale_list, resolve_locale, supported_locales}, - options::{IntlOptions, LocaleMatcher}, + options::IntlOptions, Service, }; @@ -111,9 +111,7 @@ impl BuiltInConstructor for ListFormat { // 5. Let opt be a new Record. // 6. Let matcher be ? GetOption(options, "localeMatcher", string, « "lookup", "best fit" », "best fit"). - let matcher = - get_option::(&options, utf16!("localeMatcher"), false, context)? - .unwrap_or_default(); + let matcher = get_option(&options, utf16!("localeMatcher"), context)?.unwrap_or_default(); // 7. Set opt.[[localeMatcher]] to matcher. // 8. Let localeData be %ListFormat%.[[LocaleData]]. @@ -130,13 +128,11 @@ impl BuiltInConstructor for ListFormat { // 11. Let type be ? GetOption(options, "type", string, « "conjunction", "disjunction", "unit" », "conjunction"). // 12. Set listFormat.[[Type]] to type. - let typ = get_option::(&options, utf16!("type"), false, context)? - .unwrap_or_default(); + let typ = get_option(&options, utf16!("type"), context)?.unwrap_or_default(); // 13. Let style be ? GetOption(options, "style", string, « "long", "short", "narrow" », "long"). // 14. Set listFormat.[[Style]] to style. - let style = get_option::(&options, utf16!("style"), false, context)? - .unwrap_or(ListLength::Wide); + let style = get_option(&options, utf16!("style"), context)?.unwrap_or(ListLength::Wide); // 15. Let dataLocale be r.[[dataLocale]]. // 16. Let dataLocaleData be localeData.[[]]. diff --git a/boa_engine/src/builtins/intl/locale/mod.rs b/boa_engine/src/builtins/intl/locale/mod.rs index a0e683d03b..3af04a8456 100644 --- a/boa_engine/src/builtins/intl/locale/mod.rs +++ b/boa_engine/src/builtins/intl/locale/mod.rs @@ -7,9 +7,7 @@ use boa_profiler::Profiler; use icu_collator::CaseFirst; use icu_datetime::options::preferences::HourCycle; use icu_locid::{ - extensions::unicode::Value, - extensions_unicode_key as key, extensions_unicode_value as value, - subtags::{Language, Region, Script}, + extensions::unicode::Value, extensions_unicode_key as key, extensions_unicode_value as value, }; #[cfg(test)] @@ -237,27 +235,18 @@ impl BuiltInConstructor for Locale { // 3. If ! IsStructurallyValidLanguageTag(tag) is false, throw a RangeError exception. // 4. Let language be ? GetOption(options, "language", string, empty, undefined). // 5. If language is not undefined, then - let language = get_option::(options, utf16!("language"), false, context)? - // a. If language does not match the unicode_language_subtag production, throw a RangeError exception. - .map(|s| s.to_std_string_escaped().parse::()) - .transpose() - .map_err(|e| JsNativeError::range().with_message(e.to_string()))?; + // a. If language does not match the unicode_language_subtag production, throw a RangeError exception. + let language = get_option(options, utf16!("language"), context)?; // 6. Let script be ? GetOption(options, "script", string, empty, undefined). // 7. If script is not undefined, then - let script = get_option::(options, utf16!("script"), false, context)? - .map(|s| s.to_std_string_escaped().parse::