From 4e4cf4401d6ecb42dfaed4c392f9174409ae9353 Mon Sep 17 00:00:00 2001 From: nekevss Date: Tue, 30 Jan 2024 19:14:17 -0500 Subject: [PATCH 1/4] Fix accessor attribute and toStringTag property --- .../src/builtins/temporal/calendar/mod.rs | 2 +- .../src/builtins/temporal/duration/mod.rs | 2 +- .../src/builtins/temporal/instant/mod.rs | 10 +++---- .../src/builtins/temporal/plain_date/mod.rs | 30 +++++++++---------- .../builtins/temporal/plain_date_time/mod.rs | 2 +- .../builtins/temporal/plain_month_day/mod.rs | 2 +- .../builtins/temporal/plain_year_month/mod.rs | 18 +++++------ .../src/builtins/temporal/time_zone/mod.rs | 2 +- .../builtins/temporal/zoned_date_time/mod.rs | 2 +- 9 files changed, 35 insertions(+), 35 deletions(-) diff --git a/core/engine/src/builtins/temporal/calendar/mod.rs b/core/engine/src/builtins/temporal/calendar/mod.rs index df034de8d81..37fc7b5d398 100644 --- a/core/engine/src/builtins/temporal/calendar/mod.rs +++ b/core/engine/src/builtins/temporal/calendar/mod.rs @@ -73,7 +73,7 @@ impl IntrinsicObject for Calendar { .build(); BuiltInBuilder::from_standard_constructor::(realm) - .static_property( + .property( JsSymbol::to_string_tag(), Self::NAME, Attribute::CONFIGURABLE, diff --git a/core/engine/src/builtins/temporal/duration/mod.rs b/core/engine/src/builtins/temporal/duration/mod.rs index 0b22282e0f6..0e8178b95dc 100644 --- a/core/engine/src/builtins/temporal/duration/mod.rs +++ b/core/engine/src/builtins/temporal/duration/mod.rs @@ -101,7 +101,7 @@ impl IntrinsicObject for Duration { .build(); BuiltInBuilder::from_standard_constructor::(realm) - .static_property( + .property( JsSymbol::to_string_tag(), Self::NAME, Attribute::READONLY | Attribute::NON_ENUMERABLE | Attribute::CONFIGURABLE, diff --git a/core/engine/src/builtins/temporal/instant/mod.rs b/core/engine/src/builtins/temporal/instant/mod.rs index 777c8f53a69..de62f8c6210 100644 --- a/core/engine/src/builtins/temporal/instant/mod.rs +++ b/core/engine/src/builtins/temporal/instant/mod.rs @@ -58,7 +58,7 @@ impl IntrinsicObject for Instant { .build(); BuiltInBuilder::from_standard_constructor::(realm) - .static_property( + .property( JsSymbol::to_string_tag(), Self::NAME, Attribute::CONFIGURABLE, @@ -67,25 +67,25 @@ impl IntrinsicObject for Instant { utf16!("epochSeconds"), Some(get_seconds), None, - Attribute::default(), + Attribute::CONFIGURABLE, ) .accessor( utf16!("epochMilliseconds"), Some(get_millis), None, - Attribute::default(), + Attribute::CONFIGURABLE, ) .accessor( utf16!("epochMicroseconds"), Some(get_micros), None, - Attribute::default(), + Attribute::CONFIGURABLE, ) .accessor( utf16!("epochNanoseconds"), Some(get_nanos), None, - Attribute::default(), + Attribute::CONFIGURABLE, ) .method(Self::add, js_string!("add"), 1) .method(Self::subtract, js_string!("subtract"), 1) diff --git a/core/engine/src/builtins/temporal/plain_date/mod.rs b/core/engine/src/builtins/temporal/plain_date/mod.rs index 9fa62b5c0fb..e51e25d5385 100644 --- a/core/engine/src/builtins/temporal/plain_date/mod.rs +++ b/core/engine/src/builtins/temporal/plain_date/mod.rs @@ -103,7 +103,7 @@ impl IntrinsicObject for PlainDate { .build(); BuiltInBuilder::from_standard_constructor::(realm) - .static_property( + .property( JsSymbol::to_string_tag(), Self::NAME, Attribute::CONFIGURABLE, @@ -112,70 +112,70 @@ impl IntrinsicObject for PlainDate { utf16!("calendarId"), Some(get_calendar_id), None, - Attribute::default(), + Attribute::CONFIGURABLE, ) - .accessor(utf16!("year"), Some(get_year), None, Attribute::default()) - .accessor(utf16!("month"), Some(get_month), None, Attribute::default()) + .accessor(utf16!("year"), Some(get_year), None, Attribute::CONFIGURABLE) + .accessor(utf16!("month"), Some(get_month), None, Attribute::CONFIGURABLE) .accessor( utf16!("monthCode"), Some(get_month_code), None, - Attribute::default(), + Attribute::CONFIGURABLE, ) - .accessor(utf16!("day"), Some(get_day), None, Attribute::default()) + .accessor(utf16!("day"), Some(get_day), None, Attribute::CONFIGURABLE) .accessor( utf16!("dayOfWeek"), Some(get_day_of_week), None, - Attribute::default(), + Attribute::CONFIGURABLE, ) .accessor( utf16!("dayOfYear"), Some(get_day_of_year), None, - Attribute::default(), + Attribute::CONFIGURABLE, ) .accessor( utf16!("weekOfYear"), Some(get_week_of_year), None, - Attribute::default(), + Attribute::CONFIGURABLE, ) .accessor( utf16!("yearOfWeek"), Some(get_year_of_week), None, - Attribute::default(), + Attribute::CONFIGURABLE, ) .accessor( utf16!("daysInWeek"), Some(get_days_in_week), None, - Attribute::default(), + Attribute::CONFIGURABLE, ) .accessor( utf16!("daysInMonth"), Some(get_days_in_month), None, - Attribute::default(), + Attribute::CONFIGURABLE, ) .accessor( utf16!("daysInYear"), Some(get_days_in_year), None, - Attribute::default(), + Attribute::CONFIGURABLE, ) .accessor( utf16!("monthsInYear"), Some(get_months_in_year), None, - Attribute::default(), + Attribute::CONFIGURABLE, ) .accessor( utf16!("inLeapYear"), Some(get_in_leap_year), None, - Attribute::default(), + Attribute::CONFIGURABLE, ) .method(Self::to_plain_year_month, js_string!("toPlainYearMonth"), 0) .method(Self::to_plain_month_day, js_string!("toPlainMonthDay"), 0) diff --git a/core/engine/src/builtins/temporal/plain_date_time/mod.rs b/core/engine/src/builtins/temporal/plain_date_time/mod.rs index 78e9319e2a7..31e994795cf 100644 --- a/core/engine/src/builtins/temporal/plain_date_time/mod.rs +++ b/core/engine/src/builtins/temporal/plain_date_time/mod.rs @@ -127,7 +127,7 @@ impl IntrinsicObject for PlainDateTime { .build(); BuiltInBuilder::from_standard_constructor::(realm) - .static_property( + .property( JsSymbol::to_string_tag(), Self::NAME, Attribute::CONFIGURABLE, diff --git a/core/engine/src/builtins/temporal/plain_month_day/mod.rs b/core/engine/src/builtins/temporal/plain_month_day/mod.rs index 719061dd51a..a4a664ccad5 100644 --- a/core/engine/src/builtins/temporal/plain_month_day/mod.rs +++ b/core/engine/src/builtins/temporal/plain_month_day/mod.rs @@ -38,7 +38,7 @@ impl IntrinsicObject for PlainMonthDay { let _timer = Profiler::global().start_event(std::any::type_name::(), "init"); BuiltInBuilder::from_standard_constructor::(realm) - .static_property( + .property( JsSymbol::to_string_tag(), Self::NAME, Attribute::CONFIGURABLE, diff --git a/core/engine/src/builtins/temporal/plain_year_month/mod.rs b/core/engine/src/builtins/temporal/plain_year_month/mod.rs index b3808f546f3..fa213d89303 100644 --- a/core/engine/src/builtins/temporal/plain_year_month/mod.rs +++ b/core/engine/src/builtins/temporal/plain_year_month/mod.rs @@ -70,7 +70,7 @@ impl IntrinsicObject for PlainYearMonth { .build(); BuiltInBuilder::from_standard_constructor::(realm) - .static_property( + .property( JsSymbol::to_string_tag(), Self::NAME, Attribute::CONFIGURABLE, @@ -79,39 +79,39 @@ impl IntrinsicObject for PlainYearMonth { utf16!("calendarId"), Some(get_calendar_id), None, - Attribute::default(), + Attribute::CONFIGURABLE, ) - .accessor(utf16!("year"), Some(get_year), None, Attribute::default()) - .accessor(utf16!("month"), Some(get_month), None, Attribute::default()) + .accessor(utf16!("year"), Some(get_year), None, Attribute::CONFIGURABLE) + .accessor(utf16!("month"), Some(get_month), None, Attribute::CONFIGURABLE) .accessor( utf16!("monthCode"), Some(get_month_code), None, - Attribute::default(), + Attribute::CONFIGURABLE, ) .accessor( utf16!("daysInMonth"), Some(get_days_in_month), None, - Attribute::default(), + Attribute::CONFIGURABLE, ) .accessor( utf16!("daysInYear"), Some(get_days_in_year), None, - Attribute::default(), + Attribute::CONFIGURABLE, ) .accessor( utf16!("monthsInYear"), Some(get_months_in_year), None, - Attribute::default(), + Attribute::CONFIGURABLE, ) .accessor( utf16!("inLeapYear"), Some(get_in_leap_year), None, - Attribute::default(), + Attribute::CONFIGURABLE, ) .method(Self::with, js_string!("with"), 2) .method(Self::add, js_string!("add"), 2) diff --git a/core/engine/src/builtins/temporal/time_zone/mod.rs b/core/engine/src/builtins/temporal/time_zone/mod.rs index 109f59b87f2..d906b54e8a1 100644 --- a/core/engine/src/builtins/temporal/time_zone/mod.rs +++ b/core/engine/src/builtins/temporal/time_zone/mod.rs @@ -85,7 +85,7 @@ impl IntrinsicObject for TimeZone { ) .method(Self::to_string, js_string!("toString"), 0) .method(Self::to_string, js_string!("toJSON"), 0) - .static_property( + .property( JsSymbol::to_string_tag(), Self::NAME, Attribute::READONLY | Attribute::NON_ENUMERABLE | Attribute::CONFIGURABLE, diff --git a/core/engine/src/builtins/temporal/zoned_date_time/mod.rs b/core/engine/src/builtins/temporal/zoned_date_time/mod.rs index 355d806ed67..b1e089c8e2f 100644 --- a/core/engine/src/builtins/temporal/zoned_date_time/mod.rs +++ b/core/engine/src/builtins/temporal/zoned_date_time/mod.rs @@ -44,7 +44,7 @@ impl IntrinsicObject for ZonedDateTime { let _timer = Profiler::global().start_event(std::any::type_name::(), "init"); BuiltInBuilder::from_standard_constructor::(realm) - .static_property( + .property( JsSymbol::to_string_tag(), Self::NAME, Attribute::CONFIGURABLE, From 86412efcbb8f74e0f2780feebd8719fa440f69d9 Mon Sep 17 00:00:00 2001 From: nekevss Date: Tue, 30 Jan 2024 21:07:05 -0500 Subject: [PATCH 2/4] Fix calendar methods and custom extends calendar calling --- .../src/builtins/temporal/calendar/mod.rs | 50 +++++++++---------- .../src/builtins/temporal/calendar/object.rs | 32 ++++++------ core/temporal/src/components/date.rs | 4 +- core/temporal/src/components/datetime.rs | 4 +- 4 files changed, 44 insertions(+), 46 deletions(-) diff --git a/core/engine/src/builtins/temporal/calendar/mod.rs b/core/engine/src/builtins/temporal/calendar/mod.rs index 37fc7b5d398..526360e0ec5 100644 --- a/core/engine/src/builtins/temporal/calendar/mod.rs +++ b/core/engine/src/builtins/temporal/calendar/mod.rs @@ -9,9 +9,7 @@ use super::{ }; use crate::{ builtins::{ - iterable::IteratorHint, - options::{get_option, get_options_object}, - temporal, Array, BuiltInBuilder, BuiltInConstructor, BuiltInObject, IntrinsicObject, + iterable::IteratorHint, options::{get_option, get_options_object}, temporal, Array, BuiltInBuilder, BuiltInConstructor, BuiltInObject, IntrinsicObject }, context::intrinsics::{Intrinsics, StandardConstructor, StandardConstructors}, js_string, @@ -175,7 +173,7 @@ impl Calendar { .and_then(JsObject::downcast_ref::) .ok_or_else(|| { JsNativeError::typ() - .with_message("the this value of Calendar must be a Calendar object.") + .with_message("the this value of Calendar.prototype.id must be a Calendar object.") })?; Ok(JsString::from(calendar.slot.identifier(context)?.as_str()).into()) @@ -194,7 +192,7 @@ impl Calendar { .and_then(JsObject::downcast_ref::) .ok_or_else(|| { JsNativeError::typ() - .with_message("this value of Calendar must be a Calendar object.") + .with_message("this value of Calendar dateFromFields must be a Calendar object.") })?; // 3. If Type(fields) is not Object, throw a TypeError exception. @@ -274,7 +272,7 @@ impl Calendar { .and_then(JsObject::downcast_ref::) .ok_or_else(|| { JsNativeError::typ() - .with_message("this value of Calendar must be a Calendar object.") + .with_message("this value of Calendar yearMonthFromFields must be a Calendar object.") })?; let fields = args.get_or_undefined(0); @@ -350,7 +348,7 @@ impl Calendar { .and_then(JsObject::downcast_ref::) .ok_or_else(|| { JsNativeError::typ() - .with_message("this value of Calendar must be a Calendar object.") + .with_message("this value of Calendar monthDayFromFields must be a Calendar object.") })?; // 3. If Type(fields) is not Object, throw a TypeError exception. @@ -422,7 +420,7 @@ impl Calendar { .and_then(JsObject::downcast_ref::) .ok_or_else(|| { JsNativeError::typ() - .with_message("this value of Calendar must be a Calendar object.") + .with_message("this value of Calendar dateAdd must be a Calendar object.") })?; // 4. Set date to ? ToTemporalDate(date). @@ -461,7 +459,7 @@ impl Calendar { .and_then(JsObject::downcast_ref::) .ok_or_else(|| { JsNativeError::typ() - .with_message("this value of Calendar must be a Calendar object.") + .with_message("this value of Calendar dateUntil must be a Calendar object.") })?; // 4. Set one to ? ToTemporalDate(one). @@ -497,7 +495,7 @@ impl Calendar { .and_then(JsObject::downcast_ref::) .ok_or_else(|| { JsNativeError::typ() - .with_message("this value of Calendar must be a Calendar object.") + .with_message("this value of Calendar era must be a Calendar object.") })?; let date_like = to_calendar_date_like(args.get_or_undefined(0), context)?; @@ -517,7 +515,7 @@ impl Calendar { .and_then(JsObject::downcast_ref::) .ok_or_else(|| { JsNativeError::typ() - .with_message("this value of Calendar must be a Calendar object.") + .with_message("this value of Calendar eraYear must be a Calendar object.") })?; let date_like = to_calendar_date_like(args.get_or_undefined(0), context)?; @@ -537,7 +535,7 @@ impl Calendar { .and_then(JsObject::downcast_ref::) .ok_or_else(|| { JsNativeError::typ() - .with_message("this value of Calendar must be a Calendar object.") + .with_message("this value of Calendar year must be a Calendar object.") })?; let date_like = to_calendar_date_like(args.get_or_undefined(0), context)?; @@ -554,7 +552,7 @@ impl Calendar { .and_then(JsObject::downcast_ref::) .ok_or_else(|| { JsNativeError::typ() - .with_message("this value of Calendar must be a Calendar object.") + .with_message("this value of Calendar month must be a Calendar object.") })?; let date_like = to_calendar_date_like(args.get_or_undefined(0), context)?; @@ -576,7 +574,7 @@ impl Calendar { .and_then(JsObject::downcast_ref::) .ok_or_else(|| { JsNativeError::typ() - .with_message("this value of Calendar must be a Calendar object.") + .with_message("this value of Calendar monthCode must be a Calendar object.") })?; let date_like = to_calendar_date_like(args.get_or_undefined(0), context)?; @@ -593,7 +591,7 @@ impl Calendar { .and_then(JsObject::downcast_ref::) .ok_or_else(|| { JsNativeError::typ() - .with_message("this value of Calendar must be a Calendar object.") + .with_message("this value of Calendar day must be a Calendar object.") })?; let date_like = to_calendar_date_like(args.get_or_undefined(0), context)?; @@ -612,7 +610,7 @@ impl Calendar { .and_then(JsObject::downcast_ref::) .ok_or_else(|| { JsNativeError::typ() - .with_message("this value of Calendar must be a Calendar object.") + .with_message("this value of Calendar dayOfWeek must be a Calendar object.") })?; // 3. Let temporalDate be ? ToTemporalDate(temporalDateLike). @@ -632,7 +630,7 @@ impl Calendar { .and_then(JsObject::downcast_ref::) .ok_or_else(|| { JsNativeError::typ() - .with_message("this value of Calendar must be a Calendar object.") + .with_message("this value of Calendar dayOfYear must be a Calendar object.") })?; // 3. Let temporalDate be ? ToTemporalDate(temporalDateLike). @@ -652,7 +650,7 @@ impl Calendar { .and_then(JsObject::downcast_ref::) .ok_or_else(|| { JsNativeError::typ() - .with_message("this value of Calendar must be a Calendar object.") + .with_message("this value of Calendar weekOfYear must be a Calendar object.") })?; // 3. Let temporalDate be ? ToTemporalDate(temporalDateLike). @@ -672,7 +670,7 @@ impl Calendar { .and_then(JsObject::downcast_ref::) .ok_or_else(|| { JsNativeError::typ() - .with_message("this value of Calendar must be a Calendar object.") + .with_message("this value of Calendar yearOfWeek must be a Calendar object.") })?; // 3. Let temporalDate be ? ToTemporalDate(temporalDateLike). @@ -692,7 +690,7 @@ impl Calendar { .and_then(JsObject::downcast_ref::) .ok_or_else(|| { JsNativeError::typ() - .with_message("this value of Calendar must be a Calendar object.") + .with_message("this value of Calendar daysInWeek must be a Calendar object.") })?; // 3. Let temporalDate be ? ToTemporalDate(temporalDateLike). @@ -712,7 +710,7 @@ impl Calendar { .and_then(JsObject::downcast_ref::) .ok_or_else(|| { JsNativeError::typ() - .with_message("this value of Calendar must be a Calendar object.") + .with_message("this value of Calendar daysInMonth must be a Calendar object.") })?; let date_like = to_calendar_date_like(args.get_or_undefined(0), context)?; @@ -729,7 +727,7 @@ impl Calendar { .and_then(JsObject::downcast_ref::) .ok_or_else(|| { JsNativeError::typ() - .with_message("this value of Calendar must be a Calendar object.") + .with_message("this value of Calendar daysInYear must be a Calendar object.") })?; let date_like = to_calendar_date_like(args.get_or_undefined(0), context)?; @@ -749,7 +747,7 @@ impl Calendar { .and_then(JsObject::downcast_ref::) .ok_or_else(|| { JsNativeError::typ() - .with_message("this value of Calendar must be a Calendar object.") + .with_message("this value of Calendar monthsInYear must be a Calendar object.") })?; let date_like = to_calendar_date_like(args.get_or_undefined(0), context)?; @@ -766,7 +764,7 @@ impl Calendar { .and_then(JsObject::downcast_ref::) .ok_or_else(|| { JsNativeError::typ() - .with_message("this value of Calendar must be a Calendar object.") + .with_message("this value of Calendar inLeapYear must be a Calendar object.") })?; let date_like = to_calendar_date_like(args.get_or_undefined(0), context)?; @@ -785,7 +783,7 @@ impl Calendar { .and_then(JsObject::downcast_ref::) .ok_or_else(|| { JsNativeError::typ() - .with_message("this value of Calendar must be a Calendar object.") + .with_message("this value of Calendar Fields must be a Calendar object.") })?; // Custom Calendars override the `fields` method. @@ -902,7 +900,7 @@ impl Calendar { .and_then(JsObject::downcast_ref::) .ok_or_else(|| { JsNativeError::typ() - .with_message("this value of Calendar must be a Calendar object.") + .with_message("this value of Calendar mergeFields must be a Calendar object.") })?; let fields = args.get_or_undefined(0).to_object(context)?; diff --git a/core/engine/src/builtins/temporal/calendar/object.rs b/core/engine/src/builtins/temporal/calendar/object.rs index 3f1d385d7dc..ff0969760d7 100644 --- a/core/engine/src/builtins/temporal/calendar/object.rs +++ b/core/engine/src/builtins/temporal/calendar/object.rs @@ -267,7 +267,7 @@ impl CalendarProtocol for JsCustomCalendar { let val = method .as_callable() .expect("is method") - .call(&method, &[date_like], context) + .call(&self.calendar.clone().into(), &[date_like], context) .map_err(|err| TemporalError::general(err.to_string()))?; // Validate the return value. @@ -314,7 +314,7 @@ impl CalendarProtocol for JsCustomCalendar { let val = method .as_callable() .expect("is method") - .call(&method, &[date_like], context) + .call(&self.calendar.clone().into(), &[date_like], context) .map_err(|err| TemporalError::general(err.to_string()))?; // Validate the return value. @@ -361,7 +361,7 @@ impl CalendarProtocol for JsCustomCalendar { let val = method .as_callable() .expect("is method") - .call(&method, &[date_like], context) + .call(&self.calendar.clone().into(), &[date_like], context) .map_err(|err| TemporalError::general(err.to_string()))?; let JsValue::String(result) = val else { @@ -393,7 +393,7 @@ impl CalendarProtocol for JsCustomCalendar { let val = method .as_callable() .expect("is method") - .call(&method, &[date_like], context) + .call(&self.calendar.clone().into(), &[date_like], context) .map_err(|err| TemporalError::general(err.to_string()))?; // Validate the return value. @@ -440,7 +440,7 @@ impl CalendarProtocol for JsCustomCalendar { let val = method .as_callable() .expect("is method") - .call(&method, &[date_like], context) + .call(&self.calendar.clone().into(), &[date_like], context) .map_err(|err| TemporalError::general(err.to_string()))?; // Validate the return value. @@ -489,7 +489,7 @@ impl CalendarProtocol for JsCustomCalendar { let val = method .as_callable() .expect("is method") - .call(&method, &[date_like], context) + .call(&self.calendar.clone().into(), &[date_like], context) .map_err(|err| TemporalError::general(err.to_string()))?; // Validate the return value. @@ -538,7 +538,7 @@ impl CalendarProtocol for JsCustomCalendar { let val = method .as_callable() .expect("is method") - .call(&method, &[date_like], context) + .call(&self.calendar.clone().into(), &[date_like], context) .map_err(|err| TemporalError::general(err.to_string()))?; // Validate the return value. @@ -587,7 +587,7 @@ impl CalendarProtocol for JsCustomCalendar { let val = method .as_callable() .expect("is method") - .call(&method, &[date_like], context) + .call(&self.calendar.clone().into(), &[date_like], context) .map_err(|err| TemporalError::general(err.to_string()))?; // Validate the return value. @@ -629,7 +629,7 @@ impl CalendarProtocol for JsCustomCalendar { let val = method .as_callable() .expect("is method") - .call(&method, &[date_like], context) + .call(&self.calendar.clone().into(), &[date_like], context) .map_err(|err| TemporalError::general(err.to_string()))?; // Validate the return value. @@ -677,7 +677,7 @@ impl CalendarProtocol for JsCustomCalendar { let val = method .as_callable() .expect("is method") - .call(&method, &[date_like], context) + .call(&self.calendar.clone().into(), &[date_like], context) .map_err(|err| TemporalError::general(err.to_string()))?; // Validate the return value. @@ -728,7 +728,7 @@ impl CalendarProtocol for JsCustomCalendar { let val = method .as_callable() .expect("is method") - .call(&method, &[date_like], context) + .call(&self.calendar.clone().into(), &[date_like], context) .map_err(|err| TemporalError::general(err.to_string()))?; // Validate the return value. @@ -777,7 +777,7 @@ impl CalendarProtocol for JsCustomCalendar { let val = method .as_callable() .expect("is method") - .call(&method, &[date_like], context) + .call(&self.calendar.clone().into(), &[date_like], context) .map_err(|err| TemporalError::general(err.to_string()))?; // Validate the return value. @@ -828,7 +828,7 @@ impl CalendarProtocol for JsCustomCalendar { let val = method .as_callable() .expect("is method") - .call(&method, &[date_like], context) + .call(&self.calendar.clone().into(), &[date_like], context) .map_err(|err| TemporalError::general(err.to_string()))?; let JsValue::Boolean(result) = val else { @@ -858,7 +858,7 @@ impl CalendarProtocol for JsCustomCalendar { let result = method .as_callable() .expect("is method") - .call(&method, &[fields_js.into()], context) + .call(&self.calendar.clone().into(), &[fields_js.into()], context) .map_err(|e| TemporalError::general(e.to_string()))?; // validate result and map to a `Vec` @@ -909,7 +909,7 @@ impl CalendarProtocol for JsCustomCalendar { let value = method .as_callable() .expect("is method") - .call(&method, &[fields.into(), add_fields.into()], context) + .call(&self.calendar.clone().into(), &[fields.into(), add_fields.into()], context) .map_err(|e| TemporalError::general(e.to_string()))?; let JsValue::Object(o) = value else { @@ -930,7 +930,7 @@ impl CalendarProtocol for JsCustomCalendar { .calendar .__get__( &PropertyKey::from(utf16!("id")), - JsValue::undefined(), + self.calendar.clone().into(), &mut context.into(), ) .expect("method must exist on a object that implements the CalendarProtocol."); diff --git a/core/temporal/src/components/date.rs b/core/temporal/src/components/date.rs index 85a4279393b..6f8d5f647a6 100644 --- a/core/temporal/src/components/date.rs +++ b/core/temporal/src/components/date.rs @@ -195,7 +195,7 @@ impl Date { /// Returns the calendar day of year value with provided context. pub fn contextual_day_of_year(&self, context: &mut dyn Any) -> TemporalResult { - self.calendar.day_of_week( + self.calendar.day_of_year( &super::calendar::CalendarDateLike::Date(self.clone()), context, ) @@ -203,7 +203,7 @@ impl Date { /// Returns the calendar day of year value. pub fn day_of_year(&self) -> TemporalResult { - self.contextual_day_of_week(&mut ()) + self.contextual_day_of_year(&mut ()) } /// Returns the calendar week of year value with provided context. diff --git a/core/temporal/src/components/datetime.rs b/core/temporal/src/components/datetime.rs index 0b166690626..12cdcdd62e3 100644 --- a/core/temporal/src/components/datetime.rs +++ b/core/temporal/src/components/datetime.rs @@ -238,7 +238,7 @@ impl DateTime { /// Returns the calendar day of year value with provided context. pub fn contextual_day_of_year(&self, context: &mut dyn Any) -> TemporalResult { - self.calendar.day_of_week( + self.calendar.day_of_year( &super::calendar::CalendarDateLike::DateTime(self.clone()), context, ) @@ -246,7 +246,7 @@ impl DateTime { /// Returns the calendar day of year value. pub fn day_of_year(&self) -> TemporalResult { - self.contextual_day_of_week(&mut ()) + self.contextual_day_of_year(&mut ()) } /// Returns the calendar week of year value with provided context. From 68a6d8818d8c170c5ba9e6a0f37af29da78c8ff0 Mon Sep 17 00:00:00 2001 From: nekevss Date: Wed, 31 Jan 2024 06:58:51 -0500 Subject: [PATCH 3/4] Complete attribute update --- .../src/builtins/temporal/calendar/mod.rs | 2 +- .../src/builtins/temporal/duration/mod.rs | 24 +++++++++---------- .../src/builtins/temporal/plain_time/mod.rs | 12 +++++----- 3 files changed, 19 insertions(+), 19 deletions(-) diff --git a/core/engine/src/builtins/temporal/calendar/mod.rs b/core/engine/src/builtins/temporal/calendar/mod.rs index 526360e0ec5..5fbbcc82767 100644 --- a/core/engine/src/builtins/temporal/calendar/mod.rs +++ b/core/engine/src/builtins/temporal/calendar/mod.rs @@ -76,7 +76,7 @@ impl IntrinsicObject for Calendar { Self::NAME, Attribute::CONFIGURABLE, ) - .accessor(utf16!("id"), Some(get_id), None, Attribute::default()) + .accessor(utf16!("id"), Some(get_id), None, Attribute::CONFIGURABLE) .static_method(Self::from, js_string!("from"), 1) .method(Self::date_from_fields, js_string!("dateFromFields"), 2) .method( diff --git a/core/engine/src/builtins/temporal/duration/mod.rs b/core/engine/src/builtins/temporal/duration/mod.rs index 0e8178b95dc..fc40476bcba 100644 --- a/core/engine/src/builtins/temporal/duration/mod.rs +++ b/core/engine/src/builtins/temporal/duration/mod.rs @@ -106,48 +106,48 @@ impl IntrinsicObject for Duration { Self::NAME, Attribute::READONLY | Attribute::NON_ENUMERABLE | Attribute::CONFIGURABLE, ) - .accessor(utf16!("years"), Some(get_years), None, Attribute::default()) + .accessor(utf16!("years"), Some(get_years), None, Attribute::CONFIGURABLE) .accessor( utf16!("months"), Some(get_months), None, - Attribute::default(), + Attribute::CONFIGURABLE, ) - .accessor(utf16!("weeks"), Some(get_weeks), None, Attribute::default()) - .accessor(utf16!("days"), Some(get_days), None, Attribute::default()) - .accessor(utf16!("hours"), Some(get_hours), None, Attribute::default()) + .accessor(utf16!("weeks"), Some(get_weeks), None, Attribute::CONFIGURABLE) + .accessor(utf16!("days"), Some(get_days), None, Attribute::CONFIGURABLE) + .accessor(utf16!("hours"), Some(get_hours), None, Attribute::CONFIGURABLE) .accessor( utf16!("minutes"), Some(get_minutes), None, - Attribute::default(), + Attribute::CONFIGURABLE, ) .accessor( utf16!("seconds"), Some(get_seconds), None, - Attribute::default(), + Attribute::CONFIGURABLE, ) .accessor( utf16!("milliseconds"), Some(get_milliseconds), None, - Attribute::default(), + Attribute::CONFIGURABLE, ) .accessor( utf16!("microseconds"), Some(get_microseconds), None, - Attribute::default(), + Attribute::CONFIGURABLE, ) .accessor( utf16!("nanoseconds"), Some(get_nanoseconds), None, - Attribute::default(), + Attribute::CONFIGURABLE, ) - .accessor(utf16!("sign"), Some(get_sign), None, Attribute::default()) - .accessor(utf16!("blank"), Some(is_blank), None, Attribute::default()) + .accessor(utf16!("sign"), Some(get_sign), None, Attribute::CONFIGURABLE) + .accessor(utf16!("blank"), Some(is_blank), None, Attribute::CONFIGURABLE) .method(Self::with, js_string!("with"), 1) .method(Self::negated, js_string!("negated"), 0) .method(Self::abs, js_string!("abs"), 0) diff --git a/core/engine/src/builtins/temporal/plain_time/mod.rs b/core/engine/src/builtins/temporal/plain_time/mod.rs index 781db455872..b0cf38caf9b 100644 --- a/core/engine/src/builtins/temporal/plain_time/mod.rs +++ b/core/engine/src/builtins/temporal/plain_time/mod.rs @@ -66,7 +66,7 @@ impl IntrinsicObject for PlainTime { .build(); BuiltInBuilder::from_standard_constructor::(realm) - .static_property( + .property( JsSymbol::to_string_tag(), Self::NAME, Attribute::CONFIGURABLE, @@ -76,31 +76,31 @@ impl IntrinsicObject for PlainTime { utf16!("minute"), Some(get_minute), None, - Attribute::default(), + Attribute::CONFIGURABLE, ) .accessor( utf16!("second"), Some(get_second), None, - Attribute::default(), + Attribute::CONFIGURABLE, ) .accessor( utf16!("millisecond"), Some(get_millisecond), None, - Attribute::default(), + Attribute::CONFIGURABLE, ) .accessor( utf16!("microsecond"), Some(get_microsecond), None, - Attribute::default(), + Attribute::CONFIGURABLE, ) .accessor( utf16!("nanosecond"), Some(get_nanosecond), None, - Attribute::default(), + Attribute::CONFIGURABLE, ) .method(Self::add, js_string!("add"), 1) .method(Self::subtract, js_string!("subtract"), 1) From 7b0226c5b335aaa96df06b1742a9e879ca2cd35a Mon Sep 17 00:00:00 2001 From: nekevss Date: Wed, 31 Jan 2024 07:09:38 -0500 Subject: [PATCH 4/4] run cargo fmt --- .../src/builtins/temporal/calendar/mod.rs | 24 +++++++---- .../src/builtins/temporal/calendar/object.rs | 6 ++- .../src/builtins/temporal/duration/mod.rs | 42 ++++++++++++++++--- .../src/builtins/temporal/plain_date/mod.rs | 14 ++++++- .../builtins/temporal/plain_year_month/mod.rs | 14 ++++++- 5 files changed, 80 insertions(+), 20 deletions(-) diff --git a/core/engine/src/builtins/temporal/calendar/mod.rs b/core/engine/src/builtins/temporal/calendar/mod.rs index 5fbbcc82767..56c6368d1a0 100644 --- a/core/engine/src/builtins/temporal/calendar/mod.rs +++ b/core/engine/src/builtins/temporal/calendar/mod.rs @@ -9,7 +9,9 @@ use super::{ }; use crate::{ builtins::{ - iterable::IteratorHint, options::{get_option, get_options_object}, temporal, Array, BuiltInBuilder, BuiltInConstructor, BuiltInObject, IntrinsicObject + iterable::IteratorHint, + options::{get_option, get_options_object}, + temporal, Array, BuiltInBuilder, BuiltInConstructor, BuiltInObject, IntrinsicObject, }, context::intrinsics::{Intrinsics, StandardConstructor, StandardConstructors}, js_string, @@ -172,8 +174,9 @@ impl Calendar { .as_object() .and_then(JsObject::downcast_ref::) .ok_or_else(|| { - JsNativeError::typ() - .with_message("the this value of Calendar.prototype.id must be a Calendar object.") + JsNativeError::typ().with_message( + "the this value of Calendar.prototype.id must be a Calendar object.", + ) })?; Ok(JsString::from(calendar.slot.identifier(context)?.as_str()).into()) @@ -191,8 +194,9 @@ impl Calendar { .as_object() .and_then(JsObject::downcast_ref::) .ok_or_else(|| { - JsNativeError::typ() - .with_message("this value of Calendar dateFromFields must be a Calendar object.") + JsNativeError::typ().with_message( + "this value of Calendar dateFromFields must be a Calendar object.", + ) })?; // 3. If Type(fields) is not Object, throw a TypeError exception. @@ -271,8 +275,9 @@ impl Calendar { .as_object() .and_then(JsObject::downcast_ref::) .ok_or_else(|| { - JsNativeError::typ() - .with_message("this value of Calendar yearMonthFromFields must be a Calendar object.") + JsNativeError::typ().with_message( + "this value of Calendar yearMonthFromFields must be a Calendar object.", + ) })?; let fields = args.get_or_undefined(0); @@ -347,8 +352,9 @@ impl Calendar { .as_object() .and_then(JsObject::downcast_ref::) .ok_or_else(|| { - JsNativeError::typ() - .with_message("this value of Calendar monthDayFromFields must be a Calendar object.") + JsNativeError::typ().with_message( + "this value of Calendar monthDayFromFields must be a Calendar object.", + ) })?; // 3. If Type(fields) is not Object, throw a TypeError exception. diff --git a/core/engine/src/builtins/temporal/calendar/object.rs b/core/engine/src/builtins/temporal/calendar/object.rs index ff0969760d7..bbb93de6d73 100644 --- a/core/engine/src/builtins/temporal/calendar/object.rs +++ b/core/engine/src/builtins/temporal/calendar/object.rs @@ -909,7 +909,11 @@ impl CalendarProtocol for JsCustomCalendar { let value = method .as_callable() .expect("is method") - .call(&self.calendar.clone().into(), &[fields.into(), add_fields.into()], context) + .call( + &self.calendar.clone().into(), + &[fields.into(), add_fields.into()], + context, + ) .map_err(|e| TemporalError::general(e.to_string()))?; let JsValue::Object(o) = value else { diff --git a/core/engine/src/builtins/temporal/duration/mod.rs b/core/engine/src/builtins/temporal/duration/mod.rs index fc40476bcba..57c40760f30 100644 --- a/core/engine/src/builtins/temporal/duration/mod.rs +++ b/core/engine/src/builtins/temporal/duration/mod.rs @@ -106,16 +106,36 @@ impl IntrinsicObject for Duration { Self::NAME, Attribute::READONLY | Attribute::NON_ENUMERABLE | Attribute::CONFIGURABLE, ) - .accessor(utf16!("years"), Some(get_years), None, Attribute::CONFIGURABLE) + .accessor( + utf16!("years"), + Some(get_years), + None, + Attribute::CONFIGURABLE, + ) .accessor( utf16!("months"), Some(get_months), None, Attribute::CONFIGURABLE, ) - .accessor(utf16!("weeks"), Some(get_weeks), None, Attribute::CONFIGURABLE) - .accessor(utf16!("days"), Some(get_days), None, Attribute::CONFIGURABLE) - .accessor(utf16!("hours"), Some(get_hours), None, Attribute::CONFIGURABLE) + .accessor( + utf16!("weeks"), + Some(get_weeks), + None, + Attribute::CONFIGURABLE, + ) + .accessor( + utf16!("days"), + Some(get_days), + None, + Attribute::CONFIGURABLE, + ) + .accessor( + utf16!("hours"), + Some(get_hours), + None, + Attribute::CONFIGURABLE, + ) .accessor( utf16!("minutes"), Some(get_minutes), @@ -146,8 +166,18 @@ impl IntrinsicObject for Duration { None, Attribute::CONFIGURABLE, ) - .accessor(utf16!("sign"), Some(get_sign), None, Attribute::CONFIGURABLE) - .accessor(utf16!("blank"), Some(is_blank), None, Attribute::CONFIGURABLE) + .accessor( + utf16!("sign"), + Some(get_sign), + None, + Attribute::CONFIGURABLE, + ) + .accessor( + utf16!("blank"), + Some(is_blank), + None, + Attribute::CONFIGURABLE, + ) .method(Self::with, js_string!("with"), 1) .method(Self::negated, js_string!("negated"), 0) .method(Self::abs, js_string!("abs"), 0) diff --git a/core/engine/src/builtins/temporal/plain_date/mod.rs b/core/engine/src/builtins/temporal/plain_date/mod.rs index e51e25d5385..beeba836f63 100644 --- a/core/engine/src/builtins/temporal/plain_date/mod.rs +++ b/core/engine/src/builtins/temporal/plain_date/mod.rs @@ -114,8 +114,18 @@ impl IntrinsicObject for PlainDate { None, Attribute::CONFIGURABLE, ) - .accessor(utf16!("year"), Some(get_year), None, Attribute::CONFIGURABLE) - .accessor(utf16!("month"), Some(get_month), None, Attribute::CONFIGURABLE) + .accessor( + utf16!("year"), + Some(get_year), + None, + Attribute::CONFIGURABLE, + ) + .accessor( + utf16!("month"), + Some(get_month), + None, + Attribute::CONFIGURABLE, + ) .accessor( utf16!("monthCode"), Some(get_month_code), diff --git a/core/engine/src/builtins/temporal/plain_year_month/mod.rs b/core/engine/src/builtins/temporal/plain_year_month/mod.rs index fa213d89303..97b580d2f85 100644 --- a/core/engine/src/builtins/temporal/plain_year_month/mod.rs +++ b/core/engine/src/builtins/temporal/plain_year_month/mod.rs @@ -81,8 +81,18 @@ impl IntrinsicObject for PlainYearMonth { None, Attribute::CONFIGURABLE, ) - .accessor(utf16!("year"), Some(get_year), None, Attribute::CONFIGURABLE) - .accessor(utf16!("month"), Some(get_month), None, Attribute::CONFIGURABLE) + .accessor( + utf16!("year"), + Some(get_year), + None, + Attribute::CONFIGURABLE, + ) + .accessor( + utf16!("month"), + Some(get_month), + None, + Attribute::CONFIGURABLE, + ) .accessor( utf16!("monthCode"), Some(get_month_code),