diff --git a/Cargo.lock b/Cargo.lock index 8e45487230..7f20811393 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -443,10 +443,20 @@ dependencies = [ name = "boa_icu_provider" version = "0.19.0" dependencies = [ + "icu_casemap", + "icu_collator", + "icu_datetime", + "icu_decimal", + "icu_list", + "icu_locid_transform", + "icu_normalizer", + "icu_plurals", "icu_provider", "icu_provider_adapters", "icu_provider_blob", + "icu_segmenter", "once_cell", + "paste", ] [[package]] @@ -1364,7 +1374,6 @@ dependencies = [ "icu_locid_transform", "icu_normalizer", "icu_plurals", - "icu_provider", "icu_segmenter", "log", "simple_logger", diff --git a/core/engine/src/builtins/intl/collator/mod.rs b/core/engine/src/builtins/intl/collator/mod.rs index 2181de6182..ea700d78b9 100644 --- a/core/engine/src/builtins/intl/collator/mod.rs +++ b/core/engine/src/builtins/intl/collator/mod.rs @@ -17,7 +17,7 @@ use crate::{ OrdinaryObject, }, context::{ - icu::IntlProvider, + icu::{ErasedProvider, IntlProvider}, intrinsics::{Intrinsics, StandardConstructor, StandardConstructors}, }, js_string, @@ -279,7 +279,7 @@ impl BuiltInConstructor for Collator { requested_locales, &mut intl_options, context.intl_provider(), - ); + )?; let collator_locale = { // `collator_locale` needs to be different from the resolved locale because ECMA402 doesn't @@ -335,18 +335,23 @@ impl BuiltInConstructor for Collator { .then_some((AlternateHandling::Shifted, MaxVariable::Punctuation)) .unzip(); - let collator = - icu_collator::Collator::try_new_unstable(context.intl_provider(), &collator_locale, { - let mut options = icu_collator::CollatorOptions::new(); - options.strength = strength; - options.case_level = case_level; - options.case_first = case_first; - options.numeric = Some(if numeric { Numeric::On } else { Numeric::Off }); - options.alternate_handling = alternate_handling; - options.max_variable = max_variable; - options - }) - .map_err(|e| JsNativeError::typ().with_message(e.to_string()))?; + let mut options = icu_collator::CollatorOptions::new(); + options.strength = strength; + options.case_level = case_level; + options.case_first = case_first; + options.numeric = Some(if numeric { Numeric::On } else { Numeric::Off }); + options.alternate_handling = alternate_handling; + options.max_variable = max_variable; + + let collator = match context.intl_provider().erased_provider() { + ErasedProvider::Any(a) => { + icu_collator::Collator::try_new_with_any_provider(a, &collator_locale, options) + } + ErasedProvider::Buffer(b) => { + icu_collator::Collator::try_new_with_buffer_provider(b, &collator_locale, options) + } + } + .map_err(|e| JsNativeError::typ().with_message(e.to_string()))?; let prototype = get_prototype_from_constructor(new_target, StandardConstructors::collator, context)?; diff --git a/core/engine/src/builtins/intl/list_format/mod.rs b/core/engine/src/builtins/intl/list_format/mod.rs index 58695ab1e5..94c838326d 100644 --- a/core/engine/src/builtins/intl/list_format/mod.rs +++ b/core/engine/src/builtins/intl/list_format/mod.rs @@ -12,7 +12,10 @@ use crate::{ options::{get_option, get_options_object}, Array, BuiltInBuilder, BuiltInConstructor, BuiltInObject, IntrinsicObject, OrdinaryObject, }, - context::intrinsics::{Intrinsics, StandardConstructor, StandardConstructors}, + context::{ + icu::ErasedProvider, + intrinsics::{Intrinsics, StandardConstructor, StandardConstructors}, + }, js_string, object::{internal_methods::get_prototype_from_constructor, JsObject}, property::Attribute, @@ -128,7 +131,7 @@ impl BuiltInConstructor for ListFormat { ..Default::default() }, context.intl_provider(), - ); + )?; // 11. Let type be ? GetOption(options, "type", string, « "conjunction", "disjunction", "unit" », "conjunction"). // 12. Set listFormat.[[Type]] to type. @@ -142,23 +145,26 @@ impl BuiltInConstructor for ListFormat { // 16. Let dataLocaleData be localeData.[[]]. // 17. Let dataLocaleTypes be dataLocaleData.[[]]. // 18. Set listFormat.[[Templates]] to dataLocaleTypes.[[