Skip to content

Commit fd45665

Browse files
authored
Some cleanup + order of operations fixes (#4190)
* Some cleanup + order of operations fixes * Fix not adding calendar
1 parent 9961f51 commit fd45665

File tree

3 files changed

+172
-78
lines changed

3 files changed

+172
-78
lines changed

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

Lines changed: 0 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ pub use self::{
2929
plain_time::*, plain_year_month::*, zoneddatetime::*,
3030
};
3131

32-
use crate::value::JsVariant;
3332
use crate::{
3433
builtins::{BuiltInBuilder, BuiltInObject, IntrinsicObject},
3534
context::intrinsics::Intrinsics,
@@ -226,30 +225,6 @@ pub(crate) fn get_relative_to_option(
226225
)?))
227226
}
228227

229-
type RelativeTemporalObjectResult = JsResult<(Option<TemporalDate>, Option<TemporalZonedDateTime>)>;
230-
231-
/// 13.21 `ToRelativeTemporalObject ( options )`
232-
pub(crate) fn to_relative_temporal_object(
233-
options: &JsObject,
234-
context: &mut Context,
235-
) -> RelativeTemporalObjectResult {
236-
let relative_to = options.get(js_string!("relativeTo"), context)?;
237-
let plain_date = match relative_to.variant() {
238-
JsVariant::String(relative_to_str) => JsValue::from(relative_to_str.clone()),
239-
JsVariant::Object(relative_to_obj) => JsValue::from(relative_to_obj.clone()),
240-
JsVariant::Undefined => return Ok((None, None)),
241-
_ => {
242-
return Err(JsNativeError::typ()
243-
.with_message("Invalid type for converting to relativeTo object")
244-
.into())
245-
}
246-
};
247-
let plain_date = to_temporal_date(&plain_date, None, context)?;
248-
249-
// TODO: Implement TemporalZonedDateTime conversion when ZonedDateTime is implemented
250-
Ok((Some(plain_date), None))
251-
}
252-
253228
// 13.26 IsPartialTemporalObject ( object )
254229
pub(crate) fn is_partial_temporal_object<'value>(
255230
value: &'value JsValue,

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

Lines changed: 20 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
//! Boa's implementation of the ECMAScript `Temporal.PlainDateTime` builtin object.
2-
#![allow(dead_code, unused_variables)]
32
43
use std::str::FromStr;
54

@@ -434,7 +433,7 @@ impl BuiltInConstructor for PlainDateTime {
434433

435434
impl PlainDateTime {
436435
/// 5.3.3 get `Temporal.PlainDatedt.prototype.calendarId`
437-
fn get_calendar_id(this: &JsValue, _: &[JsValue], context: &mut Context) -> JsResult<JsValue> {
436+
fn get_calendar_id(this: &JsValue, _: &[JsValue], _: &mut Context) -> JsResult<JsValue> {
438437
let dt = this
439438
.as_object()
440439
.and_then(JsObject::downcast_ref::<Self>)
@@ -446,7 +445,7 @@ impl PlainDateTime {
446445
}
447446

448447
/// 5.3.4 get `Temporal.PlainDatedt.prototype.year`
449-
fn get_era(this: &JsValue, _: &[JsValue], context: &mut Context) -> JsResult<JsValue> {
448+
fn get_era(this: &JsValue, _: &[JsValue], _: &mut Context) -> JsResult<JsValue> {
450449
let dt = this
451450
.as_object()
452451
.and_then(JsObject::downcast_ref::<Self>)
@@ -462,7 +461,7 @@ impl PlainDateTime {
462461
}
463462

464463
/// 5.3.5 get `Temporal.PlainDatedt.prototype.eraYear`
465-
fn get_era_year(this: &JsValue, _: &[JsValue], context: &mut Context) -> JsResult<JsValue> {
464+
fn get_era_year(this: &JsValue, _: &[JsValue], _: &mut Context) -> JsResult<JsValue> {
466465
let dt = this
467466
.as_object()
468467
.and_then(JsObject::downcast_ref::<Self>)
@@ -474,7 +473,7 @@ impl PlainDateTime {
474473
}
475474

476475
/// 5.3.6 get `Temporal.PlainDatedt.prototype.year`
477-
fn get_year(this: &JsValue, _: &[JsValue], context: &mut Context) -> JsResult<JsValue> {
476+
fn get_year(this: &JsValue, _: &[JsValue], _: &mut Context) -> JsResult<JsValue> {
478477
let dt = this
479478
.as_object()
480479
.and_then(JsObject::downcast_ref::<Self>)
@@ -486,7 +485,7 @@ impl PlainDateTime {
486485
}
487486

488487
/// 5.3.7 get `Temporal.PlainDatedt.prototype.month`
489-
fn get_month(this: &JsValue, _: &[JsValue], context: &mut Context) -> JsResult<JsValue> {
488+
fn get_month(this: &JsValue, _: &[JsValue], _: &mut Context) -> JsResult<JsValue> {
490489
let dt = this
491490
.as_object()
492491
.and_then(JsObject::downcast_ref::<Self>)
@@ -498,7 +497,7 @@ impl PlainDateTime {
498497
}
499498

500499
/// 5.3.8 get Temporal.PlainDatedt.prototype.monthCode
501-
fn get_month_code(this: &JsValue, _: &[JsValue], context: &mut Context) -> JsResult<JsValue> {
500+
fn get_month_code(this: &JsValue, _: &[JsValue], _: &mut Context) -> JsResult<JsValue> {
502501
let dt = this
503502
.as_object()
504503
.and_then(JsObject::downcast_ref::<Self>)
@@ -510,7 +509,7 @@ impl PlainDateTime {
510509
}
511510

512511
/// 5.3.9 get `Temporal.PlainDatedt.prototype.day`
513-
fn get_day(this: &JsValue, _: &[JsValue], context: &mut Context) -> JsResult<JsValue> {
512+
fn get_day(this: &JsValue, _: &[JsValue], _: &mut Context) -> JsResult<JsValue> {
514513
let dt = this
515514
.as_object()
516515
.and_then(JsObject::downcast_ref::<Self>)
@@ -612,7 +611,7 @@ impl PlainDateTime {
612611
}
613612

614613
/// 5.3.16 get `Temporal.PlainDatedt.prototype.dayOfWeek`
615-
fn get_day_of_week(this: &JsValue, _: &[JsValue], context: &mut Context) -> JsResult<JsValue> {
614+
fn get_day_of_week(this: &JsValue, _: &[JsValue], _: &mut Context) -> JsResult<JsValue> {
616615
let dt = this
617616
.as_object()
618617
.and_then(JsObject::downcast_ref::<Self>)
@@ -624,7 +623,7 @@ impl PlainDateTime {
624623
}
625624

626625
/// 5.3.17 get `Temporal.PlainDatedt.prototype.dayOfYear`
627-
fn get_day_of_year(this: &JsValue, _: &[JsValue], context: &mut Context) -> JsResult<JsValue> {
626+
fn get_day_of_year(this: &JsValue, _: &[JsValue], _: &mut Context) -> JsResult<JsValue> {
628627
let dt = this
629628
.as_object()
630629
.and_then(JsObject::downcast_ref::<Self>)
@@ -636,7 +635,7 @@ impl PlainDateTime {
636635
}
637636

638637
/// 5.3.18 get `Temporal.PlainDatedt.prototype.weekOfYear`
639-
fn get_week_of_year(this: &JsValue, _: &[JsValue], context: &mut Context) -> JsResult<JsValue> {
638+
fn get_week_of_year(this: &JsValue, _: &[JsValue], _: &mut Context) -> JsResult<JsValue> {
640639
let dt = this
641640
.as_object()
642641
.and_then(JsObject::downcast_ref::<Self>)
@@ -648,7 +647,7 @@ impl PlainDateTime {
648647
}
649648

650649
/// 5.3.19 get `Temporal.PlainDatedt.prototype.yearOfWeek`
651-
fn get_year_of_week(this: &JsValue, _: &[JsValue], context: &mut Context) -> JsResult<JsValue> {
650+
fn get_year_of_week(this: &JsValue, _: &[JsValue], _: &mut Context) -> JsResult<JsValue> {
652651
let dt = this
653652
.as_object()
654653
.and_then(JsObject::downcast_ref::<Self>)
@@ -660,7 +659,7 @@ impl PlainDateTime {
660659
}
661660

662661
/// 5.3.20 get `Temporal.PlainDatedt.prototype.daysInWeek`
663-
fn get_days_in_week(this: &JsValue, _: &[JsValue], context: &mut Context) -> JsResult<JsValue> {
662+
fn get_days_in_week(this: &JsValue, _: &[JsValue], _: &mut Context) -> JsResult<JsValue> {
664663
let dt = this
665664
.as_object()
666665
.and_then(JsObject::downcast_ref::<Self>)
@@ -672,11 +671,7 @@ impl PlainDateTime {
672671
}
673672

674673
/// 5.3.21 get `Temporal.PlainDatedt.prototype.daysInMonth`
675-
fn get_days_in_month(
676-
this: &JsValue,
677-
_: &[JsValue],
678-
context: &mut Context,
679-
) -> JsResult<JsValue> {
674+
fn get_days_in_month(this: &JsValue, _: &[JsValue], _: &mut Context) -> JsResult<JsValue> {
680675
let dt = this
681676
.as_object()
682677
.and_then(JsObject::downcast_ref::<Self>)
@@ -688,7 +683,7 @@ impl PlainDateTime {
688683
}
689684

690685
/// 5.3.22 get `Temporal.PlainDatedt.prototype.daysInYear`
691-
fn get_days_in_year(this: &JsValue, _: &[JsValue], context: &mut Context) -> JsResult<JsValue> {
686+
fn get_days_in_year(this: &JsValue, _: &[JsValue], _: &mut Context) -> JsResult<JsValue> {
692687
let dt = this
693688
.as_object()
694689
.and_then(JsObject::downcast_ref::<Self>)
@@ -700,11 +695,7 @@ impl PlainDateTime {
700695
}
701696

702697
/// 5.3.23 get `Temporal.PlainDatedt.prototype.monthsInYear`
703-
fn get_months_in_year(
704-
this: &JsValue,
705-
_: &[JsValue],
706-
context: &mut Context,
707-
) -> JsResult<JsValue> {
698+
fn get_months_in_year(this: &JsValue, _: &[JsValue], _: &mut Context) -> JsResult<JsValue> {
708699
let dt = this
709700
.as_object()
710701
.and_then(JsObject::downcast_ref::<Self>)
@@ -716,7 +707,7 @@ impl PlainDateTime {
716707
}
717708

718709
/// 5.3.24 get `Temporal.PlainDatedt.prototype.inLeapYear`
719-
fn get_in_leap_year(this: &JsValue, _: &[JsValue], context: &mut Context) -> JsResult<JsValue> {
710+
fn get_in_leap_year(this: &JsValue, _: &[JsValue], _: &mut Context) -> JsResult<JsValue> {
720711
let dt = this
721712
.as_object()
722713
.and_then(JsObject::downcast_ref::<Self>)
@@ -953,9 +944,6 @@ impl PlainDateTime {
953944
}
954945
};
955946

956-
let (plain_relative_to, zoned_relative_to) =
957-
super::to_relative_temporal_object(&round_to, context)?;
958-
959947
let mut options = RoundingOptions::default();
960948

961949
options.increment =
@@ -1033,11 +1021,7 @@ impl PlainDateTime {
10331021
}
10341022

10351023
/// 5.3.35 `Temporal.PlainDateTime.prototype.toLocaleString ( [ locales [ , options ] ] )`
1036-
fn to_locale_string(
1037-
this: &JsValue,
1038-
args: &[JsValue],
1039-
context: &mut Context,
1040-
) -> JsResult<JsValue> {
1024+
fn to_locale_string(this: &JsValue, _args: &[JsValue], _: &mut Context) -> JsResult<JsValue> {
10411025
// TODO: Update for ECMA-402 compliance
10421026
let dt = this
10431027
.as_object()
@@ -1053,7 +1037,7 @@ impl PlainDateTime {
10531037
}
10541038

10551039
/// 5.3.36 `Temporal.PlainDateTime.prototype.toJSON ( )`
1056-
fn to_json(this: &JsValue, args: &[JsValue], context: &mut Context) -> JsResult<JsValue> {
1040+
fn to_json(this: &JsValue, _: &[JsValue], _: &mut Context) -> JsResult<JsValue> {
10571041
let dt = this
10581042
.as_object()
10591043
.and_then(JsObject::downcast_ref::<Self>)
@@ -1105,8 +1089,8 @@ impl PlainDateTime {
11051089
.into())
11061090
}
11071091

1108-
fn to_plain_date(this: &JsValue, _: &[JsValue], context: &mut Context) -> JsResult<JsValue> {
1109-
let dt = this
1092+
fn to_plain_date(this: &JsValue, _: &[JsValue], _: &mut Context) -> JsResult<JsValue> {
1093+
let _dt = this
11101094
.as_object()
11111095
.and_then(JsObject::downcast_ref::<Self>)
11121096
.ok_or_else(|| {

0 commit comments

Comments
 (0)