Skip to content

Commit b345775

Browse files
update Boa to be inline with Temporal (#4034)
* 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]>
1 parent 20fe60f commit b345775

File tree

14 files changed

+258
-178
lines changed

14 files changed

+258
-178
lines changed

Cargo.lock

+51-3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ intrusive-collections = "0.9.7"
111111
cfg-if = "1.0.0"
112112
either = "1.13.0"
113113
sys-locale = "0.3.2"
114-
temporal_rs = { git = "https://github.com/boa-dev/temporal.git", rev = "1e7901d07a83211e62373ab94284a7d1ada4c913" }
114+
temporal_rs = "0.0.4"
115115
web-time = "1.1.0"
116116
criterion = "0.5.1"
117117
float-cmp = "0.10.0"

core/engine/src/builtins/temporal/calendar/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use std::str::FromStr;
44

55
use super::extract_from_temporal_type;
66
use crate::{js_string, Context, JsNativeError, JsObject, JsResult, JsValue};
7-
use temporal_rs::components::calendar::Calendar;
7+
use temporal_rs::Calendar;
88

99
// -- `Calendar` Abstract Operations --
1010

core/engine/src/builtins/temporal/duration/mod.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,10 @@ use crate::{
1616
use boa_gc::{Finalize, Trace};
1717
use boa_profiler::Profiler;
1818
use temporal_rs::{
19-
components::{duration::PartialDuration, Duration as InnerDuration},
2019
options::{RelativeTo, RoundingIncrement, RoundingOptions, TemporalRoundingMode, TemporalUnit},
20+
partial::PartialDuration,
2121
primitive::FiniteF64,
22+
Duration as InnerDuration,
2223
};
2324

2425
use super::{

core/engine/src/builtins/temporal/instant/mod.rs

+15-19
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@ use boa_gc::{Finalize, Trace};
2424
use boa_profiler::Profiler;
2525
use num_traits::ToPrimitive;
2626
use temporal_rs::{
27-
components::Instant as InnerInstant,
2827
options::{RoundingIncrement, RoundingOptions, TemporalRoundingMode},
28+
Instant as InnerInstant,
2929
};
3030

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

49-
let get_seconds = BuiltInBuilder::callable(realm, Self::get_epoc_seconds)
49+
let get_seconds = BuiltInBuilder::callable(realm, Self::get_epoch_seconds)
5050
.name(js_string!("get epochSeconds"))
5151
.build();
5252

53-
let get_millis = BuiltInBuilder::callable(realm, Self::get_epoc_milliseconds)
53+
let get_millis = BuiltInBuilder::callable(realm, Self::get_epoch_milliseconds)
5454
.name(js_string!("get epochMilliseconds"))
5555
.build();
5656

57-
let get_micros = BuiltInBuilder::callable(realm, Self::get_epoc_microseconds)
57+
let get_micros = BuiltInBuilder::callable(realm, Self::get_epoch_microseconds)
5858
.name(js_string!("get epochMicroseconds"))
5959
.build();
6060

61-
let get_nanos = BuiltInBuilder::callable(realm, Self::get_epoc_nanoseconds)
61+
let get_nanos = BuiltInBuilder::callable(realm, Self::get_epoch_nanoseconds)
6262
.name(js_string!("get epochNanoseconds"))
6363
.build();
6464

@@ -150,7 +150,7 @@ impl BuiltInConstructor for Instant {
150150

151151
// 3. If ! IsValidEpochNanoseconds(epochNanoseconds) is false, throw a RangeError exception.
152152
// NOTE: temporal_rs::Instant asserts that the epochNanoseconds are valid.
153-
let instant = InnerInstant::new(epoch_nanos.as_inner().to_i128().unwrap_or(i128::MAX))?;
153+
let instant = InnerInstant::try_new(epoch_nanos.as_inner().to_i128().unwrap_or(i128::MAX))?;
154154
// 4. Return ? CreateTemporalInstant(epochNanoseconds, NewTarget).
155155
create_temporal_instant(instant, Some(new_target.clone()), context)
156156
}
@@ -201,7 +201,7 @@ impl Instant {
201201
// 3. Return ! CreateTemporalInstant(epochNanoseconds).
202202
let nanos = epoch_nanos.as_inner().to_i128();
203203
create_temporal_instant(
204-
InnerInstant::new(nanos.unwrap_or(i128::MAX))?,
204+
InnerInstant::try_new(nanos.unwrap_or(i128::MAX))?,
205205
None,
206206
context,
207207
)
@@ -226,7 +226,7 @@ impl Instant {
226226

227227
impl Instant {
228228
/// 8.3.3 get Temporal.Instant.prototype.epochSeconds
229-
pub(crate) fn get_epoc_seconds(
229+
pub(crate) fn get_epoch_seconds(
230230
this: &JsValue,
231231
_: &[JsValue],
232232
_: &mut Context,
@@ -240,11 +240,11 @@ impl Instant {
240240
JsNativeError::typ().with_message("the this object must be an instant object.")
241241
})?;
242242
// 3. Let ns be instant.[[Nanoseconds]].
243-
Ok(instant.inner.epoch_seconds().into())
243+
Ok(JsBigInt::from(instant.inner.epoch_seconds()).into())
244244
}
245245

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

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

288286
/// 8.3.6 get Temporal.Instant.prototype.epochNanoseconds
289-
pub(crate) fn get_epoc_nanoseconds(
287+
pub(crate) fn get_epoch_nanoseconds(
290288
this: &JsValue,
291289
_: &[JsValue],
292290
_: &mut Context,
@@ -301,9 +299,7 @@ impl Instant {
301299
})?;
302300
// 3. Let ns be instant.[[Nanoseconds]].
303301
// 4. Return ns.
304-
let big_int = JsBigInt::try_from(instant.inner.epoch_nanoseconds())
305-
.expect("valid nanoseconds is in range of BigInt");
306-
Ok(big_int.into())
302+
Ok(JsBigInt::from(instant.inner.epoch_nanoseconds()).into())
307303
}
308304

309305
/// 8.3.7 `Temporal.Instant.prototype.add ( temporalDurationLike )`

core/engine/src/builtins/temporal/mod.rs

+1-4
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,7 @@ use crate::{
3737
Context, JsBigInt, JsNativeError, JsObject, JsResult, JsString, JsSymbol, JsValue,
3838
};
3939
use boa_profiler::Profiler;
40-
use temporal_rs::{
41-
components::{Date as TemporalDate, ZonedDateTime as TemporalZonedDateTime},
42-
NS_PER_DAY,
43-
};
40+
use temporal_rs::{PlainDate as TemporalDate, ZonedDateTime as TemporalZonedDateTime, NS_PER_DAY};
4441

4542
// TODO: Remove in favor of `temporal_rs`
4643
pub(crate) fn ns_max_instant() -> JsBigInt {

core/engine/src/builtins/temporal/now.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ use crate::{
1111
Context, JsBigInt, JsNativeError, JsObject, JsResult, JsString, JsSymbol, JsValue,
1212
};
1313
use boa_profiler::Profiler;
14-
use temporal_rs::components::tz::TimeZone;
14+
use temporal_rs::TimeZone;
1515

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

core/engine/src/builtins/temporal/options.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ use crate::{
1313
js_string, Context, JsNativeError, JsObject, JsResult, JsString, JsValue,
1414
};
1515
use temporal_rs::options::{
16-
ArithmeticOverflow, CalendarName, DifferenceSettings, DurationOverflow, InstantDisambiguation,
16+
ArithmeticOverflow, CalendarName, DifferenceSettings, Disambiguation, DurationOverflow,
1717
OffsetDisambiguation, RoundingIncrement, TemporalRoundingMode, TemporalUnit,
1818
};
1919

@@ -113,7 +113,7 @@ fn datetime_units() -> impl Iterator<Item = TemporalUnit> {
113113
impl ParsableOptionType for TemporalUnit {}
114114
impl ParsableOptionType for ArithmeticOverflow {}
115115
impl ParsableOptionType for DurationOverflow {}
116-
impl ParsableOptionType for InstantDisambiguation {}
116+
impl ParsableOptionType for Disambiguation {}
117117
impl ParsableOptionType for OffsetDisambiguation {}
118118
impl ParsableOptionType for TemporalRoundingMode {}
119119
impl ParsableOptionType for CalendarName {}

0 commit comments

Comments
 (0)