Skip to content

Commit fe216b1

Browse files
catamorphismConstellation
authored andcommitted
[Temporal] Enable all PlainYearMonth test262 tests
https://bugs.webkit.org/show_bug.cgi?id=305156 Reviewed by Justin Michaud and Yusuke Suzuki. Also fix several bugs that were hidden by PlainYearMonth being skipped in config.yaml: * Negate rounding mode when calling PlainYearMonth since method * Fix bug where negative month should be checked before options * Fix month code checking bug in with when supplied month code differs from existing month * JSTests/test262/config.yaml: * Source/JavaScriptCore/runtime/TemporalCalendar.cpp: (JSC::TemporalCalendar::isoDateFromFields): (JSC::TemporalCalendar::yearMonthFromFields): * Source/JavaScriptCore/runtime/TemporalPlainDate.cpp: (JSC::TemporalPlainDate::toYearMonth): * Source/JavaScriptCore/runtime/TemporalPlainDateTime.cpp: (JSC::TemporalPlainDateTime::from): * Source/JavaScriptCore/runtime/TemporalPlainDateTime.h: * Source/JavaScriptCore/runtime/TemporalPlainDateTimeConstructor.cpp: (JSC::JSC_DEFINE_HOST_FUNCTION): * Source/JavaScriptCore/runtime/TemporalPlainDateTimePrototype.cpp: (JSC::JSC_DEFINE_HOST_FUNCTION): * Source/JavaScriptCore/runtime/TemporalPlainMonthDay.cpp: (JSC::TemporalPlainMonthDay::from): * Source/JavaScriptCore/runtime/TemporalPlainMonthDay.h: * Source/JavaScriptCore/runtime/TemporalPlainMonthDayPrototype.cpp: (JSC::JSC_DEFINE_HOST_FUNCTION): * Source/JavaScriptCore/runtime/TemporalPlainYearMonth.cpp: (JSC::TemporalPlainYearMonth::with): (JSC::TemporalPlainYearMonth::sinceOrUntil): Canonical link: https://commits.webkit.org/305330@main
1 parent c510554 commit fe216b1

11 files changed

+44
-28
lines changed

JSTests/test262/config.yaml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ skip:
3131
- test/built-ins/Temporal/PlainDateTime/prototype/toZonedDateTime
3232
- test/built-ins/Temporal/PlainDateTime/prototype/until
3333
- test/built-ins/Temporal/PlainDateTime/prototype/withCalendar
34-
- test/built-ins/Temporal/PlainYearMonth
3534
- test/built-ins/Temporal/ZonedDateTime
3635
- test/intl402/Temporal/Instant/prototype/toZonedDateTimeISO
3736
- test/intl402/Temporal/Now

Source/JavaScriptCore/runtime/TemporalCalendar.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -262,7 +262,9 @@ ISO8601::PlainDate TemporalCalendar::isoDateFromFields(JSGlobalObject* globalObj
262262
if (std::holds_alternative<TemporalOverflow>(optionsOrOverflow))
263263
overflow = std::get<TemporalOverflow>(optionsOrOverflow);
264264
else {
265-
overflow = toTemporalOverflow(globalObject, std::get<JSObject*>(optionsOrOverflow));
265+
JSObject* options = std::get<JSObject*>(optionsOrOverflow);
266+
ASSERT(options);
267+
overflow = toTemporalOverflow(globalObject, options);
266268
RETURN_IF_EXCEPTION(scope, { });
267269
}
268270

@@ -355,8 +357,6 @@ ISO8601::PlainDate TemporalCalendar::isoDateFromFields(JSGlobalObject* globalObj
355357
// https://tc39.es/proposal-temporal/#sec-temporal-calendaryearmonthfromfields
356358
ISO8601::PlainDate TemporalCalendar::yearMonthFromFields(JSGlobalObject* globalObject, int32_t year, int32_t month, std::optional<ParsedMonthCode> monthCode, TemporalOverflow overflow)
357359
{
358-
// 2. Let firstDayIndex be the 1-based index of the first day of the month described by fields
359-
// (i.e., 1 unless the month's first day is skipped by this calendar.)
360360
return isoDateFromFields(globalObject, TemporalDateFormat::YearMonth, year, month, 1, monthCode, overflow);
361361
}
362362

Source/JavaScriptCore/runtime/TemporalPlainDate.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -394,6 +394,13 @@ TemporalPlainDate::toYearMonth(JSGlobalObject* globalObject, JSObject* temporalD
394394
return { };
395395
}
396396

397+
// See step 9(c)(iv) of PrepareCalendarFields
398+
// https://tc39.es/proposal-temporal/#sec-temporal-preparecalendarfields
399+
if (doubleMonth <= 0) {
400+
throwRangeError(globalObject, scope, "month property must be a positive integer"_s);
401+
return { };
402+
}
403+
397404
if (!isInBounds<int32_t>(doubleMonth)) [[unlikely]] {
398405
// Later checks will report error
399406
month = ISO8601::outOfRangeYear;

Source/JavaScriptCore/runtime/TemporalPlainDateTime.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ TemporalPlainDateTime* TemporalPlainDateTime::tryCreateIfValid(JSGlobalObject* g
109109
}
110110

111111
// https://tc39.es/proposal-temporal/#sec-temporal-totemporaldatetime
112-
TemporalPlainDateTime* TemporalPlainDateTime::from(JSGlobalObject* globalObject, JSValue itemValue, std::optional<JSObject*> optionsValue)
112+
TemporalPlainDateTime* TemporalPlainDateTime::from(JSGlobalObject* globalObject, JSValue itemValue, JSObject* options)
113113
{
114114
VM& vm = globalObject->vm();
115115
auto scope = DECLARE_THROW_SCOPE(vm);
@@ -131,8 +131,8 @@ TemporalPlainDateTime* TemporalPlainDateTime::from(JSGlobalObject* globalObject,
131131
}
132132

133133
Variant<JSObject*, TemporalOverflow> optionsOrOverflow = TemporalOverflow::Constrain;
134-
if (optionsValue)
135-
optionsOrOverflow = optionsValue.value();
134+
if (options)
135+
optionsOrOverflow = options;
136136
auto overflow = TemporalOverflow::Constrain;
137137
auto plainDate = TemporalCalendar::isoDateFromFields(globalObject, asObject(itemValue), TemporalDateFormat::Date, optionsOrOverflow, overflow);
138138
RETURN_IF_EXCEPTION(scope, { });
@@ -155,8 +155,8 @@ TemporalPlainDateTime* TemporalPlainDateTime::from(JSGlobalObject* globalObject,
155155
auto string = itemValue.toWTFString(globalObject);
156156
RETURN_IF_EXCEPTION(scope, { });
157157

158-
if (optionsValue) {
159-
toTemporalOverflow(globalObject, optionsValue.value()); // Validate overflow
158+
if (options) {
159+
toTemporalOverflow(globalObject, options); // Validate overflow
160160
RETURN_IF_EXCEPTION(scope, { });
161161
}
162162

Source/JavaScriptCore/runtime/TemporalPlainDateTime.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ class TemporalPlainDateTime final : public JSNonFinalObject {
4848

4949
DECLARE_INFO;
5050

51-
static TemporalPlainDateTime* from(JSGlobalObject*, JSValue, std::optional<JSObject*>);
51+
static TemporalPlainDateTime* from(JSGlobalObject*, JSValue, JSObject*);
5252
static int32_t compare(TemporalPlainDateTime*, TemporalPlainDateTime*);
5353

5454
TemporalCalendar* calendar() { return m_calendar.get(this); }

Source/JavaScriptCore/runtime/TemporalPlainDateTimeConstructor.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -138,10 +138,10 @@ JSC_DEFINE_HOST_FUNCTION(temporalPlainDateTimeConstructorFuncCompare, (JSGlobalO
138138
VM& vm = globalObject->vm();
139139
auto scope = DECLARE_THROW_SCOPE(vm);
140140

141-
auto* one = TemporalPlainDateTime::from(globalObject, callFrame->argument(0), std::nullopt);
141+
auto* one = TemporalPlainDateTime::from(globalObject, callFrame->argument(0), nullptr);
142142
RETURN_IF_EXCEPTION(scope, { });
143143

144-
auto* two = TemporalPlainDateTime::from(globalObject, callFrame->argument(1), std::nullopt);
144+
auto* two = TemporalPlainDateTime::from(globalObject, callFrame->argument(1), nullptr);
145145
RETURN_IF_EXCEPTION(scope, { });
146146

147147
return JSValue::encode(jsNumber(TemporalPlainDateTime::compare(one, two)));

Source/JavaScriptCore/runtime/TemporalPlainDateTimePrototype.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -290,7 +290,7 @@ JSC_DEFINE_HOST_FUNCTION(temporalPlainDateTimePrototypeFuncEquals, (JSGlobalObje
290290
if (!plainDateTime)
291291
return throwVMTypeError(globalObject, scope, "Temporal.PlainDateTime.prototype.equals called on value that's not a PlainDateTime"_s);
292292

293-
auto* other = TemporalPlainDateTime::from(globalObject, callFrame->argument(0), std::nullopt);
293+
auto* other = TemporalPlainDateTime::from(globalObject, callFrame->argument(0), nullptr);
294294
RETURN_IF_EXCEPTION(scope, { });
295295

296296
if (plainDateTime->plainDate() != other->plainDate() || plainDateTime->plainTime() != other->plainTime())

Source/JavaScriptCore/runtime/TemporalPlainMonthDay.cpp

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ String TemporalPlainMonthDay::toString(JSGlobalObject* globalObject, JSValue opt
121121

122122
// https://tc39.es/proposal-temporal/#sec-temporal.plainmonthday.from
123123
// https://tc39.es/proposal-temporal/#sec-temporal-totemporalmonthday
124-
TemporalPlainMonthDay* TemporalPlainMonthDay::from(JSGlobalObject* globalObject, JSValue itemValue, std::optional<JSValue> optionsValue)
124+
TemporalPlainMonthDay* TemporalPlainMonthDay::from(JSGlobalObject* globalObject, JSValue itemValue, JSValue optionsValue)
125125
{
126126
VM& vm = globalObject->vm();
127127
auto scope = DECLARE_THROW_SCOPE(vm);
@@ -136,18 +136,17 @@ TemporalPlainMonthDay* TemporalPlainMonthDay::from(JSGlobalObject* globalObject,
136136
RETURN_IF_EXCEPTION(scope, { });
137137
// Overflow has to be validated even though it's not used;
138138
// see step 9 of ToTemporalMonthDay
139-
if (optionsValue) {
140-
toTemporalOverflow(globalObject, optionsValue.value());
139+
if (!optionsValue.isUndefined()) {
140+
JSObject* options = intlGetOptionsObject(globalObject, optionsValue);
141+
RETURN_IF_EXCEPTION(scope, { });
142+
toTemporalOverflow(globalObject, options);
141143
RETURN_IF_EXCEPTION(scope, { });
142144
}
143145
return result;
144146
}
145147

146-
std::optional<JSObject*> options;
147-
if (optionsValue) {
148-
options = intlGetOptionsObject(globalObject, optionsValue.value());
149-
RETURN_IF_EXCEPTION(scope, { });
150-
}
148+
JSObject* options = intlGetOptionsObject(globalObject, optionsValue);
149+
RETURN_IF_EXCEPTION(scope, { });
151150

152151
if (itemValue.isObject()) {
153152
if (itemValue.inherits<TemporalPlainMonthDay>())
@@ -167,7 +166,7 @@ TemporalPlainMonthDay* TemporalPlainMonthDay::from(JSGlobalObject* globalObject,
167166

168167
Variant<JSObject*, TemporalOverflow> optionsOrOverflow = TemporalOverflow::Constrain;
169168
if (options)
170-
optionsOrOverflow = options.value();
169+
optionsOrOverflow = options;
171170
auto overflow = TemporalOverflow::Constrain;
172171
auto plainMonthDay = TemporalCalendar::isoDateFromFields(globalObject, asObject(itemValue), TemporalDateFormat::MonthDay, optionsOrOverflow, overflow);
173172
RETURN_IF_EXCEPTION(scope, { });

Source/JavaScriptCore/runtime/TemporalPlainMonthDay.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ class TemporalPlainMonthDay final : public JSNonFinalObject {
4747

4848
DECLARE_INFO;
4949

50-
static TemporalPlainMonthDay* from(JSGlobalObject*, JSValue, std::optional<JSValue>);
50+
static TemporalPlainMonthDay* from(JSGlobalObject*, JSValue, JSValue);
5151
static TemporalPlainMonthDay* from(JSGlobalObject*, WTF::String);
5252

5353
TemporalCalendar* calendar() { return m_calendar.get(this); }

Source/JavaScriptCore/runtime/TemporalPlainMonthDayPrototype.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ JSC_DEFINE_HOST_FUNCTION(temporalPlainMonthDayPrototypeFuncEquals, (JSGlobalObje
166166
if (!monthDay) [[unlikely]]
167167
return throwVMTypeError(globalObject, scope, "Temporal.PlainMonthDay.prototype.equals called on value that's not a PlainMonthDay"_s);
168168

169-
auto* other = TemporalPlainMonthDay::from(globalObject, callFrame->argument(0), std::nullopt);
169+
auto* other = TemporalPlainMonthDay::from(globalObject, callFrame->argument(0), jsUndefined());
170170
RETURN_IF_EXCEPTION(scope, { });
171171

172172
if (monthDay->plainMonthDay() != other->plainMonthDay())

0 commit comments

Comments
 (0)