#![allow(clippy::string_lit_as_bytes)]
use crate::{
builtins::{Array, BuiltInBuilder, BuiltInObject, IntrinsicObject},
context::{intrinsics::Intrinsics, BoaProvider},
object::JsObject,
property::Attribute,
realm::Realm,
symbol::JsSymbol,
Context, JsArgs, JsResult, JsValue,
};
use boa_profiler::Profiler;
use icu_provider::KeyedDataMarker;
pub(crate) mod collator;
pub(crate) mod date_time_format;
pub(crate) mod list_format;
pub(crate) mod locale;
pub(crate) mod segmenter;
pub(crate) use self::{
collator::Collator, date_time_format::DateTimeFormat, list_format::ListFormat, locale::Locale,
segmenter::Segmenter,
};
mod options;
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
pub(crate) struct Intl;
impl IntrinsicObject for Intl {
fn init(realm: &Realm) {
let _timer = Profiler::global().start_event(Self::NAME, "init");
BuiltInBuilder::with_intrinsic::<Self>(realm)
.static_property(
JsSymbol::to_string_tag(),
Self::NAME,
Attribute::CONFIGURABLE,
)
.static_property(
Collator::NAME,
realm.intrinsics().constructors().collator().constructor(),
Collator::ATTRIBUTE,
)
.static_property(
ListFormat::NAME,
realm
.intrinsics()
.constructors()
.list_format()
.constructor(),
ListFormat::ATTRIBUTE,
)
.static_property(
Locale::NAME,
realm.intrinsics().constructors().locale().constructor(),
Locale::ATTRIBUTE,
)
.static_property(
Segmenter::NAME,
realm.intrinsics().constructors().segmenter().constructor(),
Segmenter::ATTRIBUTE,
)
.static_property(
DateTimeFormat::NAME,
realm
.intrinsics()
.constructors()
.date_time_format()
.constructor(),
DateTimeFormat::ATTRIBUTE,
)
.static_method(Self::get_canonical_locales, "getCanonicalLocales", 1)
.build();
}
fn get(intrinsics: &Intrinsics) -> JsObject {
intrinsics.objects().intl()
}
}
impl BuiltInObject for Intl {
const NAME: &'static str = "Intl";
}
impl Intl {
pub(crate) fn get_canonical_locales(
_: &JsValue,
args: &[JsValue],
context: &mut Context<'_>,
) -> JsResult<JsValue> {
let locales = args.get_or_undefined(0);
let ll = locale::canonicalize_locale_list(locales, context)?;
Ok(JsValue::Object(Array::create_array_from_list(
ll.into_iter().map(|loc| loc.to_string().into()),
context,
)))
}
}
trait Service {
type LangMarker: KeyedDataMarker;
type LocaleOptions;
fn resolve(
_locale: &mut icu_locid::Locale,
_options: &mut Self::LocaleOptions,
_provider: BoaProvider<'_>,
) {
}
}