Skip to content

Commit

Permalink
Bump temporal_rs to latest commit (#3880)
Browse files Browse the repository at this point in the history
* Bump temporal_rs to latest commit

* Fix build

* update test262

* bump temporal pt. 2

* bump temporal pt. 3

* bump temporal (last time)
  • Loading branch information
jedel1043 authored Jun 25, 2024
1 parent 149693a commit 2458d73
Show file tree
Hide file tree
Showing 9 changed files with 150 additions and 243 deletions.
257 changes: 126 additions & 131 deletions Cargo.lock

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ intrusive-collections = "0.9.6"
cfg-if = "1.0.0"
either = "1.12.0"
sys-locale = "0.3.1"
temporal_rs = { git = "https://github.com/boa-dev/temporal.git", rev = "61a05fbb7c72353deda72a3df0e6887d65b840d2" }
temporal_rs = { git = "https://github.com/boa-dev/temporal.git", rev = "ec2f2d00294ee641285ec1570df6683ecd0d1a8e" }
web-time = "1.1.0"
criterion = "0.5.1"
float-cmp = "0.9.0"
Expand Down
2 changes: 1 addition & 1 deletion core/engine/src/builtins/options.rs
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ impl OptionType for f64 {

if !value.is_finite() {
return Err(JsNativeError::range()
.with_message("roundingIncrement must be finite.")
.with_message("numeric option must be finite.")
.into());
}

Expand Down
7 changes: 4 additions & 3 deletions core/engine/src/builtins/temporal/duration/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@ use boa_macros::js_str;
use boa_profiler::Profiler;
use temporal_rs::{
components::Duration as InnerDuration,
options::{RelativeTo, TemporalRoundingMode, TemporalUnit},
options::{RelativeTo, RoundingIncrement, TemporalRoundingMode, TemporalUnit},
};

use super::{
options::{get_temporal_rounding_increment, get_temporal_unit, TemporalUnitGroup},
options::{get_temporal_unit, TemporalUnitGroup},
to_integer_if_integral, DateTimeValues,
};

Expand Down Expand Up @@ -658,7 +658,8 @@ impl Duration {
super::to_relative_temporal_object(&round_to, context)?;

// 13. Let roundingIncrement be ? ToTemporalRoundingIncrement(roundTo).
let rounding_increment = get_temporal_rounding_increment(&round_to, context)?;
let rounding_increment =
get_option::<RoundingIncrement>(&round_to, js_str!("roundingIncrement"), context)?;

// 14. Let roundingMode be ? ToTemporalRoundingMode(roundTo, "halfExpand").
let rounding_mode =
Expand Down
1 change: 1 addition & 0 deletions core/engine/src/builtins/temporal/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ impl From<TemporalError> for JsNativeError {
ErrorKind::Type => JsNativeError::typ().with_message(value.message()),
ErrorKind::Generic => JsNativeError::error().with_message(value.message()),
ErrorKind::Syntax => JsNativeError::syntax().with_message(value.message()),
ErrorKind::Assert => JsNativeError::error().with_message("internal engine error"),
}
}
}
Expand Down
8 changes: 5 additions & 3 deletions core/engine/src/builtins/temporal/instant/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ use boa_macros::js_str;
use boa_profiler::Profiler;
use temporal_rs::{
components::Instant as InnerInstant,
options::{TemporalRoundingMode, TemporalUnit},
options::{RoundingIncrement, TemporalRoundingMode, TemporalUnit},
};

/// The `Temporal.Instant` object.
Expand Down Expand Up @@ -287,7 +287,8 @@ impl Instant {
// Fetch the necessary options.
let options = get_options_object(args.get_or_undefined(1))?;
let mode = get_option::<TemporalRoundingMode>(&options, js_str!("roundingMode"), context)?;
let increment = get_option::<f64>(&options, js_str!("roundingIncrement"), context)?;
let increment =
get_option::<RoundingIncrement>(&options, js_str!("roundingIncrement"), context)?;
let smallest_unit = get_option::<TemporalUnit>(&options, js_str!("smallestUnit"), context)?;
let largest_unit = get_option::<TemporalUnit>(&options, js_str!("largestUnit"), context)?;
let result = instant
Expand Down Expand Up @@ -315,7 +316,8 @@ impl Instant {
let other = to_temporal_instant(args.get_or_undefined(0))?;
let options = get_options_object(args.get_or_undefined(1))?;
let mode = get_option::<TemporalRoundingMode>(&options, js_str!("roundingMode"), context)?;
let increment = get_option::<f64>(&options, js_str!("roundingIncrement"), context)?;
let increment =
get_option::<RoundingIncrement>(&options, js_str!("roundingIncrement"), context)?;
let smallest_unit = get_option::<TemporalUnit>(&options, js_str!("smallestUnit"), context)?;
let largest_unit = get_option::<TemporalUnit>(&options, js_str!("largestUnit"), context)?;
let result = instant
Expand Down
50 changes: 11 additions & 39 deletions core/engine/src/builtins/temporal/options.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,53 +9,17 @@
// https://github.com/tc39/proposal-temporal/blob/main/polyfill/index.d.ts

use crate::{
builtins::options::{get_option, ParsableOptionType},
js_string,
builtins::options::{get_option, OptionType, ParsableOptionType},
string::JsStr,
Context, JsNativeError, JsObject, JsResult,
Context, JsNativeError, JsObject, JsResult, JsValue,
};
use temporal_rs::options::{
ArithmeticOverflow, DurationOverflow, InstantDisambiguation, OffsetDisambiguation,
TemporalRoundingMode, TemporalUnit,
RoundingIncrement, TemporalRoundingMode, TemporalUnit,
};

// TODO: Expand docs on the below options.

// TODO: Remove and refactor: migrate to `boa_temporal`
#[inline]
pub(crate) fn get_temporal_rounding_increment(
options: &JsObject,
context: &mut Context,
) -> JsResult<Option<f64>> {
// 1. Let increment be ? GetOption(normalizedOptions, "roundingIncrement", "number", undefined, 1𝔽).
let value = options.get(js_string!("roundingIncrement"), context)?;

if value.is_undefined() {
return Ok(None);
}
let increment = value.to_number(context)?;

// 2. If increment is not finite, throw a RangeError exception.
if !increment.is_finite() {
return Err(JsNativeError::range()
.with_message("rounding increment was out of range.")
.into());
}

// 3. Let integerIncrement be truncate(ℝ(increment)).
let integer_increment = increment.trunc();

// 4. If integerIncrement < 1 or integerIncrement > 10^9, throw a RangeError exception.
if !(1.0..=1_000_000_000.0).contains(&integer_increment) {
return Err(JsNativeError::range()
.with_message("rounding increment was out of range.")
.into());
}

// 5. Return integerIncrement.
Ok(Some(integer_increment))
}

/// Gets the `TemporalUnit` from an options object.
#[inline]
pub(crate) fn get_temporal_unit(
Expand Down Expand Up @@ -135,3 +99,11 @@ impl ParsableOptionType for DurationOverflow {}
impl ParsableOptionType for InstantDisambiguation {}
impl ParsableOptionType for OffsetDisambiguation {}
impl ParsableOptionType for TemporalRoundingMode {}

impl OptionType for RoundingIncrement {
fn from_value(value: JsValue, context: &mut Context) -> JsResult<Self> {
let value = value.to_number(context)?;

Ok(RoundingIncrement::try_from(value)?)
}
}
64 changes: 0 additions & 64 deletions core/engine/src/builtins/temporal/time_zone/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -336,70 +336,6 @@ pub(super) fn create_temporal_time_zone(
.into())
}

/// Abstract operation `ParseTimeZoneOffsetString ( offsetString )`
///
/// The abstract operation `ParseTimeZoneOffsetString` takes argument `offsetString` (a String). It
/// parses the argument as a numeric UTC offset string and returns a signed integer representing
/// that offset as a number of nanoseconds.
///
/// More information:
/// - [ECMAScript specififcation][spec]
///
/// [spec]: https://tc39.es/ecma262/#sec-parsetimezoneoffsetstring
#[allow(clippy::unnecessary_wraps, unused)]
fn parse_timezone_offset_string(offset_string: &str, context: &mut Context) -> JsResult<i64> {
use temporal_rs::parser::{Cursor, TemporalTimeZoneString};

// 1. Let parseResult be ParseText(StringToCodePoints(offsetString), UTCOffset).
let parse_result = TemporalTimeZoneString::parse(&mut Cursor::new(offset_string))?;

// 2. Assert: parseResult is not a List of errors.
// 3. Assert: parseResult contains a TemporalSign Parse Node.
let Some(utc_offset) = parse_result.offset else {
return Err(JsNativeError::typ()
.with_message("Offset string was not a valid offset")
.into());
};

// 4. Let parsedSign be the source text matched by the TemporalSign Parse Node contained within
// parseResult.
// 5. If parsedSign is the single code point U+002D (HYPHEN-MINUS) or U+2212 (MINUS SIGN), then
let sign = utc_offset.sign;
// a. Let sign be -1.
// 6. Else,
// a. Let sign be 1.

// 7. NOTE: Applications of StringToNumber below do not lose precision, since each of the parsed
// values is guaranteed to be a sufficiently short string of decimal digits.
// 8. Assert: parseResult contains an Hour Parse Node.
// 9. Let parsedHours be the source text matched by the Hour Parse Node contained within parseResult.
let parsed_hours = utc_offset.hour;

// 10. Let hours be ℝ(StringToNumber(CodePointsToString(parsedHours))).
// 11. If parseResult does not contain a MinuteSecond Parse Node, then
// a. Let minutes be 0.
// 12. Else,
// a. Let parsedMinutes be the source text matched by the first MinuteSecond Parse Node contained within parseResult.
// b. Let minutes be ℝ(StringToNumber(CodePointsToString(parsedMinutes))).
// 13. If parseResult does not contain two MinuteSecond Parse Nodes, then
// a. Let seconds be 0.
// 14. Else,
// a. Let parsedSeconds be the source text matched by the second MinuteSecond Parse Node contained within parseResult.
// b. Let seconds be ℝ(StringToNumber(CodePointsToString(parsedSeconds))).
// 15. If parseResult does not contain a TemporalDecimalFraction Parse Node, then
// a. Let nanoseconds be 0.
// 16. Else,
// a. Let parsedFraction be the source text matched by the TemporalDecimalFraction Parse Node contained within parseResult.
// b. Let fraction be the string-concatenation of CodePointsToString(parsedFraction) and "000000000".
// c. Let nanosecondsString be the substring of fraction from 1 to 10.
// d. Let nanoseconds be ℝ(StringToNumber(nanosecondsString)).
// 17. Return sign × (((hours × 60 + minutes) × 60 + seconds) × 10^9 + nanoseconds).

Err(JsNativeError::error()
.with_message("not yet implemented.")
.into())
}

/// Abstract operation `FormatTimeZoneOffsetString ( offsetNanoseconds )`
fn format_time_zone_offset_string(offset_nanoseconds: i64) -> String {
// 1. Assert: offsetNanoseconds is an integer.
Expand Down
2 changes: 1 addition & 1 deletion test262_config.toml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
commit = "c00830acef42bdb0e917b5fdec76ed9d399c0eea"
commit = "c47b716e8d6bea0c4510d449fd22b7ed5f8b0151"

[ignored]
# Not implemented yet:
Expand Down

0 comments on commit 2458d73

Please sign in to comment.