Skip to content

Commit

Permalink
Review changes, general cleanup, and post rebase fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
nekevss committed Sep 30, 2023
1 parent f0edbed commit 05d4bfc
Show file tree
Hide file tree
Showing 31 changed files with 596 additions and 660 deletions.
24 changes: 18 additions & 6 deletions boa_ast/src/temporal/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,22 @@ pub struct IsoParseRecord {
pub date: DateRecord,
/// Parsed Time
pub time: Option<TimeSpec>,
/// Parsed Offset
/// Parsed `TimeZoneAnnotation`
/// Parsed `TimeZone` data (UTCOffset | IANA name)
pub tz: Option<TimeZone>,
/// Parsed Annotations
/// The parsed calendar value.
pub calendar: Option<String>,
}

/// An ISO Date Node consisting of only date fields and any calendar value.
#[derive(Default, Debug)]
pub struct ISODate {
/// Date Year
pub year: i32,
/// Date Month
pub month: i32,
/// Date Day
pub day: i32,
/// The calendar value.
pub calendar: Option<String>,
}

Expand Down Expand Up @@ -69,7 +81,7 @@ pub struct TimeZone {
/// TimeZoneIANAName
pub name: Option<String>,
/// TimeZoneOffset
pub offset: Option<UtcOffset>,
pub offset: Option<UTCOffset>,
}

/// A valid `TimeZoneIdentifier` that is defined by
Expand All @@ -78,14 +90,14 @@ pub struct TimeZone {
#[derive(Debug, Clone)]
pub enum TzIdentifier {
/// A valid UTC `TimeZoneIdentifier` value
UtcOffset(UtcOffset),
UtcOffset(UTCOffset),
/// A valid IANA name `TimeZoneIdentifier` value
TzIANAName(String),
}

/// A full precision `UtcOffset`
#[derive(Debug, Clone, Copy)]
pub struct UtcOffset {
pub struct UTCOffset {
/// The `+`/`-` sign of this `UtcOffset`
pub sign: i8,
/// The hour value of the `UtcOffset`
Expand Down
2 changes: 1 addition & 1 deletion boa_cli/src/debug/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ fn create_boa_object(context: &mut Context<'_>) -> JsObject {
let realm_module = realm::create_object(context);
let limits_module = limits::create_object(context);

ObjectInitializer::new(context.realm().clone())
ObjectInitializer::new(context)
.property(
js_string!("function"),
function_module,
Expand Down
4 changes: 1 addition & 3 deletions boa_engine/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,6 @@ intl = [

fuzz = ["boa_ast/arbitrary", "boa_interner/arbitrary"]

experimental = ["boa_parser/experimental", "dep:icu_calendar"]

# Enable Boa's VM instruction flowgraph generator.
flowgraph = []

Expand All @@ -49,7 +47,7 @@ trace = []
annex-b = ["boa_parser/annex-b"]

# Enable experimental features, like Stage 3 proposals.
experimental = []
experimental = ["boa_parser/experimental", "dep:icu_calendar"]

[dependencies]
boa_interner.workspace = true
Expand Down
4 changes: 2 additions & 2 deletions boa_engine/src/builtins/intl/segmenter/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ impl Segmenter {
// b. Let v be the value of segmenter's internal slot whose name is the Internal Slot value of the current row.
// c. Assert: v is not undefined.
// d. Perform ! CreateDataPropertyOrThrow(options, p, v).
let options = ObjectInitializer::new(context.realm().clone())
let options = ObjectInitializer::new(context)
.property(
js_string!("locale"),
js_string!(segmenter.locale.to_string()),
Expand Down Expand Up @@ -314,7 +314,7 @@ fn create_segment_data_object(
let segment = js_string!(&string[range]);

// 5. Let result be OrdinaryObjectCreate(%Object.prototype%).
let object = &mut ObjectInitializer::new(context.realm().clone());
let object = &mut ObjectInitializer::new(context);

object
// 7. Perform ! CreateDataPropertyOrThrow(result, "segment", segment).
Expand Down
3 changes: 0 additions & 3 deletions boa_engine/src/builtins/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,6 @@ pub mod escape;
#[cfg(feature = "intl")]
pub mod intl;

#[cfg(feature = "experimental")]
pub mod temporal;

// TODO: remove `cfg` when `Temporal` gets to stage 4.
#[cfg(any(feature = "intl", feature = "experimental"))]
pub(crate) mod options;
Expand Down
24 changes: 10 additions & 14 deletions boa_engine/src/builtins/temporal/calendar/iso.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,21 @@
use crate::{
builtins::temporal::{
self, create_temporal_date, create_temporal_duration,
date_equations::{
epoch_time_for_year, mathematical_days_in_year, mathematical_in_leap_year,
},
options::{get_temporal_unit, ArithmeticOverflow, TemporalUnit},
self, create_temporal_date,
date_equations::mathematical_days_in_year,
options::{ArithmeticOverflow, TemporalUnit},
plain_date::iso::IsoDateRecord,
to_temporal_date,
},
js_string,
property::PropertyKey,
string::utf16,
Context, JsArgs, JsNativeError, JsResult, JsString, JsValue,
Context, JsNativeError, JsResult, JsString, JsValue,
};

use super::BuiltinCalendar;

use icu_calendar::{
iso::Iso,
types::IsoWeekday,
week::{RelativeUnit, WeekCalculator},
Calendar, Date,
};
Expand Down Expand Up @@ -55,7 +51,7 @@ impl BuiltinCalendar for IsoCalendar {
// 9. Return ? CreateTemporalDate(result.[[Year]], result.[[Month]], result.[[Day]], "iso8601").
Ok(create_temporal_date(
IsoDateRecord::from_date_iso(date),
"iso8601".into(),
js_string!("iso8601").into(),
None,
context,
)?
Expand Down Expand Up @@ -88,7 +84,7 @@ impl BuiltinCalendar for IsoCalendar {
// 10. Return ? CreateTemporalYearMonth(result.[[Year]], result.[[Month]], "iso8601", result.[[ReferenceISODay]]).
temporal::create_temporal_year_month(
IsoDateRecord::from_date_iso(result),
"iso8601".into(),
js_string!("iso8601").into(),
None,
context,
)
Expand Down Expand Up @@ -120,7 +116,7 @@ impl BuiltinCalendar for IsoCalendar {
// 10. Return ? CreateTemporalMonthDay(result.[[Month]], result.[[Day]], "iso8601", result.[[ReferenceISOYear]]).
temporal::create_temporal_month_day(
IsoDateRecord::from_date_iso(result),
JsValue::from("iso8601"),
js_string!("iso8601").into(),
None,
context,
)
Expand Down Expand Up @@ -209,7 +205,7 @@ impl BuiltinCalendar for IsoCalendar {
)
.map_err(|err| JsNativeError::range().with_message(err.to_string()))?;

Ok(date.month().code.to_string().into())
Ok(JsString::from(date.month().code.to_string()).into())
}

/// Returns the `day` for the `Iso` calendar.
Expand Down Expand Up @@ -354,9 +350,9 @@ impl BuiltinCalendar for IsoCalendar {
let key_string = key.to_string();
result.push(key);
if key_string.as_str() == "month" {
result.push("monthCode".into());
result.push(utf16!("monthCode").into());
} else if key_string.as_str() == "monthCode" {
result.push("month".into());
result.push(utf16!("month").into());
}
}
result
Expand Down
Loading

0 comments on commit 05d4bfc

Please sign in to comment.