Skip to content

Commit

Permalink
update Boa to be inline with Temporal (#4034)
Browse files Browse the repository at this point in the history
* update Boa to be inline with Temporal

* use TinyAsciiStr

* tidyup

* updates MonthDay

* remove commented code

* use intoOrUndefined

* add documentation to macros tests

* use tinyasciiistr from temporal

* patch update_temporal per discussion + version 0.0.4 bump changes

---------

Co-authored-by: Kevin Ness <[email protected]>
  • Loading branch information
jasonwilliams and nekevss authored Dec 5, 2024
1 parent 20fe60f commit b345775
Show file tree
Hide file tree
Showing 14 changed files with 258 additions and 178 deletions.
54 changes: 51 additions & 3 deletions Cargo.lock

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

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ intrusive-collections = "0.9.7"
cfg-if = "1.0.0"
either = "1.13.0"
sys-locale = "0.3.2"
temporal_rs = { git = "https://github.com/boa-dev/temporal.git", rev = "1e7901d07a83211e62373ab94284a7d1ada4c913" }
temporal_rs = "0.0.4"
web-time = "1.1.0"
criterion = "0.5.1"
float-cmp = "0.10.0"
Expand Down
2 changes: 1 addition & 1 deletion core/engine/src/builtins/temporal/calendar/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use std::str::FromStr;

use super::extract_from_temporal_type;
use crate::{js_string, Context, JsNativeError, JsObject, JsResult, JsValue};
use temporal_rs::components::calendar::Calendar;
use temporal_rs::Calendar;

// -- `Calendar` Abstract Operations --

Expand Down
3 changes: 2 additions & 1 deletion core/engine/src/builtins/temporal/duration/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,10 @@ use crate::{
use boa_gc::{Finalize, Trace};
use boa_profiler::Profiler;
use temporal_rs::{
components::{duration::PartialDuration, Duration as InnerDuration},
options::{RelativeTo, RoundingIncrement, RoundingOptions, TemporalRoundingMode, TemporalUnit},
partial::PartialDuration,
primitive::FiniteF64,
Duration as InnerDuration,
};

use super::{
Expand Down
34 changes: 15 additions & 19 deletions core/engine/src/builtins/temporal/instant/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ use boa_gc::{Finalize, Trace};
use boa_profiler::Profiler;
use num_traits::ToPrimitive;
use temporal_rs::{
components::Instant as InnerInstant,
options::{RoundingIncrement, RoundingOptions, TemporalRoundingMode},
Instant as InnerInstant,
};

use super::options::get_difference_settings;
Expand All @@ -46,19 +46,19 @@ impl IntrinsicObject for Instant {
fn init(realm: &Realm) {
let _timer = Profiler::global().start_event(std::any::type_name::<Self>(), "init");

let get_seconds = BuiltInBuilder::callable(realm, Self::get_epoc_seconds)
let get_seconds = BuiltInBuilder::callable(realm, Self::get_epoch_seconds)
.name(js_string!("get epochSeconds"))
.build();

let get_millis = BuiltInBuilder::callable(realm, Self::get_epoc_milliseconds)
let get_millis = BuiltInBuilder::callable(realm, Self::get_epoch_milliseconds)
.name(js_string!("get epochMilliseconds"))
.build();

let get_micros = BuiltInBuilder::callable(realm, Self::get_epoc_microseconds)
let get_micros = BuiltInBuilder::callable(realm, Self::get_epoch_microseconds)
.name(js_string!("get epochMicroseconds"))
.build();

let get_nanos = BuiltInBuilder::callable(realm, Self::get_epoc_nanoseconds)
let get_nanos = BuiltInBuilder::callable(realm, Self::get_epoch_nanoseconds)
.name(js_string!("get epochNanoseconds"))
.build();

Expand Down Expand Up @@ -150,7 +150,7 @@ impl BuiltInConstructor for Instant {

// 3. If ! IsValidEpochNanoseconds(epochNanoseconds) is false, throw a RangeError exception.
// NOTE: temporal_rs::Instant asserts that the epochNanoseconds are valid.
let instant = InnerInstant::new(epoch_nanos.as_inner().to_i128().unwrap_or(i128::MAX))?;
let instant = InnerInstant::try_new(epoch_nanos.as_inner().to_i128().unwrap_or(i128::MAX))?;
// 4. Return ? CreateTemporalInstant(epochNanoseconds, NewTarget).
create_temporal_instant(instant, Some(new_target.clone()), context)
}
Expand Down Expand Up @@ -201,7 +201,7 @@ impl Instant {
// 3. Return ! CreateTemporalInstant(epochNanoseconds).
let nanos = epoch_nanos.as_inner().to_i128();
create_temporal_instant(
InnerInstant::new(nanos.unwrap_or(i128::MAX))?,
InnerInstant::try_new(nanos.unwrap_or(i128::MAX))?,
None,
context,
)
Expand All @@ -226,7 +226,7 @@ impl Instant {

impl Instant {
/// 8.3.3 get Temporal.Instant.prototype.epochSeconds
pub(crate) fn get_epoc_seconds(
pub(crate) fn get_epoch_seconds(
this: &JsValue,
_: &[JsValue],
_: &mut Context,
Expand All @@ -240,11 +240,11 @@ impl Instant {
JsNativeError::typ().with_message("the this object must be an instant object.")
})?;
// 3. Let ns be instant.[[Nanoseconds]].
Ok(instant.inner.epoch_seconds().into())
Ok(JsBigInt::from(instant.inner.epoch_seconds()).into())
}

/// 8.3.4 get Temporal.Instant.prototype.epochMilliseconds
pub(crate) fn get_epoc_milliseconds(
pub(crate) fn get_epoch_milliseconds(
this: &JsValue,
_: &[JsValue],
_: &mut Context,
Expand All @@ -260,11 +260,11 @@ impl Instant {
// 3. Let ns be instant.[[Nanoseconds]].
// 4. Let ms be floor(ℝ(ns) / 106).
// 5. Return 𝔽(ms).
Ok(instant.inner.epoch_milliseconds().into())
Ok(JsBigInt::from(instant.inner.epoch_milliseconds()).into())
}

/// 8.3.5 get Temporal.Instant.prototype.epochMicroseconds
pub(crate) fn get_epoc_microseconds(
pub(crate) fn get_epoch_microseconds(
this: &JsValue,
_: &[JsValue],
_: &mut Context,
Expand All @@ -280,13 +280,11 @@ impl Instant {
// 3. Let ns be instant.[[Nanoseconds]].
// 4. Let µs be floor(ℝ(ns) / 103).
// 5. Return ℤ(µs).
let big_int = JsBigInt::try_from(instant.inner.epoch_microseconds())
.expect("valid microseconds is in range of BigInt");
Ok(big_int.into())
Ok(JsBigInt::from(instant.inner.epoch_microseconds()).into())
}

/// 8.3.6 get Temporal.Instant.prototype.epochNanoseconds
pub(crate) fn get_epoc_nanoseconds(
pub(crate) fn get_epoch_nanoseconds(
this: &JsValue,
_: &[JsValue],
_: &mut Context,
Expand All @@ -301,9 +299,7 @@ impl Instant {
})?;
// 3. Let ns be instant.[[Nanoseconds]].
// 4. Return ns.
let big_int = JsBigInt::try_from(instant.inner.epoch_nanoseconds())
.expect("valid nanoseconds is in range of BigInt");
Ok(big_int.into())
Ok(JsBigInt::from(instant.inner.epoch_nanoseconds()).into())
}

/// 8.3.7 `Temporal.Instant.prototype.add ( temporalDurationLike )`
Expand Down
5 changes: 1 addition & 4 deletions core/engine/src/builtins/temporal/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,7 @@ use crate::{
Context, JsBigInt, JsNativeError, JsObject, JsResult, JsString, JsSymbol, JsValue,
};
use boa_profiler::Profiler;
use temporal_rs::{
components::{Date as TemporalDate, ZonedDateTime as TemporalZonedDateTime},
NS_PER_DAY,
};
use temporal_rs::{PlainDate as TemporalDate, ZonedDateTime as TemporalZonedDateTime, NS_PER_DAY};

// TODO: Remove in favor of `temporal_rs`
pub(crate) fn ns_max_instant() -> JsBigInt {
Expand Down
2 changes: 1 addition & 1 deletion core/engine/src/builtins/temporal/now.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use crate::{
Context, JsBigInt, JsNativeError, JsObject, JsResult, JsString, JsSymbol, JsValue,
};
use boa_profiler::Profiler;
use temporal_rs::components::tz::TimeZone;
use temporal_rs::TimeZone;

use super::{ns_max_instant, ns_min_instant, time_zone::default_time_zone};

Expand Down
4 changes: 2 additions & 2 deletions core/engine/src/builtins/temporal/options.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use crate::{
js_string, Context, JsNativeError, JsObject, JsResult, JsString, JsValue,
};
use temporal_rs::options::{
ArithmeticOverflow, CalendarName, DifferenceSettings, DurationOverflow, InstantDisambiguation,
ArithmeticOverflow, CalendarName, DifferenceSettings, Disambiguation, DurationOverflow,
OffsetDisambiguation, RoundingIncrement, TemporalRoundingMode, TemporalUnit,
};

Expand Down Expand Up @@ -113,7 +113,7 @@ fn datetime_units() -> impl Iterator<Item = TemporalUnit> {
impl ParsableOptionType for TemporalUnit {}
impl ParsableOptionType for ArithmeticOverflow {}
impl ParsableOptionType for DurationOverflow {}
impl ParsableOptionType for InstantDisambiguation {}
impl ParsableOptionType for Disambiguation {}
impl ParsableOptionType for OffsetDisambiguation {}
impl ParsableOptionType for TemporalRoundingMode {}
impl ParsableOptionType for CalendarName {}
Expand Down
Loading

0 comments on commit b345775

Please sign in to comment.