Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement prototype of NumberFormat #3669

Merged
merged 4 commits into from
Feb 12, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ static_assertions = "1.1.0"
textwrap = "0.16.0"
thin-vec = "0.2.13"
time = {version = "0.3.34", no-default-features = true, features = ["local-offset", "large-dates", "wasm-bindgen", "parsing", "formatting", "macros"]}
tinystr = "0.7.5"

# ICU4X

Expand All @@ -85,6 +86,7 @@ icu_provider_adapters = { version = "~1.4.0", default-features = false }
icu_provider_blob = { version = "~1.4.0", default-features = false }
icu_properties = { version = "~1.4.0", default-features = true }
icu_normalizer = { version = "~1.4.1", default-features = true }
icu_decimal = { version = "~1.4.0", default-features = false }
writeable = "~0.5.4"
yoke = "~0.7.3"
zerofrom = "~0.1.3"
Expand Down
9 changes: 7 additions & 2 deletions core/engine/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,13 @@ intl = [
"dep:icu_casemap",
"dep:icu_list",
"dep:icu_segmenter",
"dep:icu_decimal",
"dep:writeable",
"dep:sys-locale",
"dep:yoke",
"dep:zerofrom",
"dep:fixed_decimal",
"dep:tinystr",
]

fuzz = ["boa_ast/arbitrary", "boa_interner/arbitrary"]
Expand Down Expand Up @@ -93,6 +95,7 @@ arrayvec = "0.7.4"
intrusive-collections = "0.9.6"
cfg-if = "1.0.0"
time.workspace = true
hashbrown.workspace = true

# intl deps
boa_icu_provider = {workspace = true, features = ["std"], optional = true }
Expand All @@ -107,11 +110,13 @@ icu_plurals = { workspace = true, default-features = false, features = ["serde",
icu_list = { workspace = true, default-features = false, features = ["serde"], optional = true }
icu_casemap = { workspace = true, default-features = false, features = ["serde"], optional = true}
icu_segmenter = { workspace = true, default-features = false, features = ["auto", "serde"], optional = true }
icu_decimal = { workspace = true, default-features = false, features = ["serde"], optional = true }
writeable = { workspace = true, optional = true }
yoke = { workspace = true, optional = true }
zerofrom = { workspace = true, optional = true }
fixed_decimal = { workspace = true, features = ["ryu", "experimental"], optional = true}
hashbrown.workspace = true
fixed_decimal = { workspace = true, features = ["ryu", "experimental"], optional = true }
tinystr = { workspace = true, optional = true }


[target.'cfg(all(target_family = "wasm", not(any(target_os = "emscripten", target_os = "wasi"))))'.dependencies]
web-time = { version = "1.0.0", optional = true }
Expand Down
36 changes: 31 additions & 5 deletions core/engine/src/builtins/intl/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,10 @@ use crate::{
realm::Realm,
string::common::StaticJsStrings,
symbol::JsSymbol,
Context, JsArgs, JsResult, JsString, JsValue,
Context, JsArgs, JsData, JsResult, JsString, JsValue,
};

use boa_gc::{Finalize, Trace};
use boa_profiler::Profiler;
use icu_provider::KeyedDataMarker;

Expand All @@ -38,14 +39,30 @@ pub(crate) mod segmenter;

pub(crate) use self::{
collator::Collator, date_time_format::DateTimeFormat, list_format::ListFormat, locale::Locale,
plural_rules::PluralRules, segmenter::Segmenter,
number_format::NumberFormat, plural_rules::PluralRules, segmenter::Segmenter,
};

mod options;

/// JavaScript `Intl` object.
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
pub(crate) struct Intl;
#[derive(Debug, Clone, Trace, Finalize, JsData)]
#[boa_gc(unsafe_empty_trace)]
pub struct Intl {
fallback_symbol: JsSymbol,
}

impl Intl {
/// Gets this realm's `Intl` object's `[[FallbackSymbol]]` slot.
#[must_use]
pub fn fallback_symbol(&self) -> JsSymbol {
self.fallback_symbol.clone()
}

pub(crate) fn new() -> Option<Self> {
let fallback_symbol = JsSymbol::new(Some(js_string!("IntlLegacyConstructedSymbol")))?;
Some(Self { fallback_symbol })
}
}

impl IntrinsicObject for Intl {
fn init(realm: &Realm) {
Expand Down Expand Up @@ -99,6 +116,15 @@ impl IntrinsicObject for Intl {
.constructor(),
DateTimeFormat::ATTRIBUTE,
)
.static_property(
NumberFormat::NAME,
realm
.intrinsics()
.constructors()
.number_format()
.constructor(),
NumberFormat::ATTRIBUTE,
)
.static_method(
Self::get_canonical_locales,
js_string!("getCanonicalLocales"),
Expand All @@ -108,7 +134,7 @@ impl IntrinsicObject for Intl {
}

fn get(intrinsics: &Intrinsics) -> JsObject {
intrinsics.objects().intl()
intrinsics.objects().intl().upcast()
}
}

Expand Down