|
@@ -7,6 +7,7 @@
|
|
|
|
|
|
#include <LibJS/Runtime/AbstractOperations.h>
|
|
#include <LibJS/Runtime/AbstractOperations.h>
|
|
#include <LibJS/Runtime/Array.h>
|
|
#include <LibJS/Runtime/Array.h>
|
|
|
|
+#include <LibJS/Runtime/Completion.h>
|
|
#include <LibJS/Runtime/GlobalObject.h>
|
|
#include <LibJS/Runtime/GlobalObject.h>
|
|
#include <LibJS/Runtime/Temporal/AbstractOperations.h>
|
|
#include <LibJS/Runtime/Temporal/AbstractOperations.h>
|
|
#include <LibJS/Runtime/Temporal/Calendar.h>
|
|
#include <LibJS/Runtime/Temporal/Calendar.h>
|
|
@@ -29,7 +30,7 @@ Calendar::Calendar(String identifier, Object& prototype)
|
|
}
|
|
}
|
|
|
|
|
|
// 12.1.1 CreateTemporalCalendar ( identifier [ , newTarget ] ), https://tc39.es/proposal-temporal/#sec-temporal-createtemporalcalendar
|
|
// 12.1.1 CreateTemporalCalendar ( identifier [ , newTarget ] ), https://tc39.es/proposal-temporal/#sec-temporal-createtemporalcalendar
|
|
-Calendar* create_temporal_calendar(GlobalObject& global_object, String const& identifier, FunctionObject const* new_target)
|
|
|
|
|
|
+ThrowCompletionOr<Calendar*> create_temporal_calendar(GlobalObject& global_object, String const& identifier, FunctionObject const* new_target)
|
|
{
|
|
{
|
|
// 1. Assert: ! IsBuiltinCalendar(identifier) is true.
|
|
// 1. Assert: ! IsBuiltinCalendar(identifier) is true.
|
|
VERIFY(is_builtin_calendar(identifier));
|
|
VERIFY(is_builtin_calendar(identifier));
|
|
@@ -40,7 +41,7 @@ Calendar* create_temporal_calendar(GlobalObject& global_object, String const& id
|
|
|
|
|
|
// 3. Let object be ? OrdinaryCreateFromConstructor(newTarget, "%Temporal.Calendar.prototype%", « [[InitializedTemporalCalendar]], [[Identifier]] »).
|
|
// 3. Let object be ? OrdinaryCreateFromConstructor(newTarget, "%Temporal.Calendar.prototype%", « [[InitializedTemporalCalendar]], [[Identifier]] »).
|
|
// 4. Set object.[[Identifier]] to identifier.
|
|
// 4. Set object.[[Identifier]] to identifier.
|
|
- auto* object = TRY_OR_DISCARD(ordinary_create_from_constructor<Calendar>(global_object, *new_target, &GlobalObject::temporal_calendar_prototype, identifier));
|
|
|
|
|
|
+ auto* object = TRY(ordinary_create_from_constructor<Calendar>(global_object, *new_target, &GlobalObject::temporal_calendar_prototype, identifier));
|
|
|
|
|
|
// 5. Return object.
|
|
// 5. Return object.
|
|
return object;
|
|
return object;
|
|
@@ -59,22 +60,20 @@ bool is_builtin_calendar(String const& identifier)
|
|
}
|
|
}
|
|
|
|
|
|
// 12.1.3 GetBuiltinCalendar ( id ), https://tc39.es/proposal-temporal/#sec-temporal-getbuiltincalendar
|
|
// 12.1.3 GetBuiltinCalendar ( id ), https://tc39.es/proposal-temporal/#sec-temporal-getbuiltincalendar
|
|
-Calendar* get_builtin_calendar(GlobalObject& global_object, String const& identifier)
|
|
|
|
|
|
+ThrowCompletionOr<Calendar*> get_builtin_calendar(GlobalObject& global_object, String const& identifier)
|
|
{
|
|
{
|
|
auto& vm = global_object.vm();
|
|
auto& vm = global_object.vm();
|
|
|
|
|
|
// 1. If ! IsBuiltinCalendar(id) is false, throw a RangeError exception.
|
|
// 1. If ! IsBuiltinCalendar(id) is false, throw a RangeError exception.
|
|
- if (!is_builtin_calendar(identifier)) {
|
|
|
|
- vm.throw_exception<RangeError>(global_object, ErrorType::TemporalInvalidCalendarIdentifier, identifier);
|
|
|
|
- return {};
|
|
|
|
- }
|
|
|
|
|
|
+ if (!is_builtin_calendar(identifier))
|
|
|
|
+ return vm.throw_completion<RangeError>(global_object, ErrorType::TemporalInvalidCalendarIdentifier, identifier);
|
|
|
|
|
|
// 2. Return ? Construct(%Temporal.Calendar%, « id »).
|
|
// 2. Return ? Construct(%Temporal.Calendar%, « id »).
|
|
MarkedValueList arguments(vm.heap());
|
|
MarkedValueList arguments(vm.heap());
|
|
arguments.append(js_string(vm, identifier));
|
|
arguments.append(js_string(vm, identifier));
|
|
auto calendar = vm.construct(*global_object.temporal_calendar_constructor(), *global_object.temporal_calendar_constructor(), move(arguments));
|
|
auto calendar = vm.construct(*global_object.temporal_calendar_constructor(), *global_object.temporal_calendar_constructor(), move(arguments));
|
|
- if (vm.exception())
|
|
|
|
- return {};
|
|
|
|
|
|
+ if (auto* exception = vm.exception())
|
|
|
|
+ return throw_completion(exception->value());
|
|
return static_cast<Calendar*>(&calendar.as_object());
|
|
return static_cast<Calendar*>(&calendar.as_object());
|
|
}
|
|
}
|
|
|
|
|
|
@@ -82,18 +81,18 @@ Calendar* get_builtin_calendar(GlobalObject& global_object, String const& identi
|
|
Calendar* get_iso8601_calendar(GlobalObject& global_object)
|
|
Calendar* get_iso8601_calendar(GlobalObject& global_object)
|
|
{
|
|
{
|
|
// 1. Return ! GetBuiltinCalendar("iso8601").
|
|
// 1. Return ! GetBuiltinCalendar("iso8601").
|
|
- return get_builtin_calendar(global_object, "iso8601");
|
|
|
|
|
|
+ return get_builtin_calendar(global_object, "iso8601").release_value();
|
|
}
|
|
}
|
|
|
|
|
|
// 12.1.5 CalendarFields ( calendar, fieldNames ), https://tc39.es/proposal-temporal/#sec-temporal-calendarfields
|
|
// 12.1.5 CalendarFields ( calendar, fieldNames ), https://tc39.es/proposal-temporal/#sec-temporal-calendarfields
|
|
-Vector<String> calendar_fields(GlobalObject& global_object, Object& calendar, Vector<StringView> const& field_names)
|
|
|
|
|
|
+ThrowCompletionOr<Vector<String>> calendar_fields(GlobalObject& global_object, Object& calendar, Vector<StringView> const& field_names)
|
|
{
|
|
{
|
|
auto& vm = global_object.vm();
|
|
auto& vm = global_object.vm();
|
|
|
|
|
|
// 1. Let fields be ? GetMethod(calendar, "fields").
|
|
// 1. Let fields be ? GetMethod(calendar, "fields").
|
|
auto fields = Value(&calendar).get_method(global_object, vm.names.fields);
|
|
auto fields = Value(&calendar).get_method(global_object, vm.names.fields);
|
|
- if (vm.exception())
|
|
|
|
- return {};
|
|
|
|
|
|
+ if (auto* exception = vm.exception())
|
|
|
|
+ return throw_completion(exception->value());
|
|
|
|
|
|
// 2. Let fieldsArray be ! CreateArrayFromList(fieldNames).
|
|
// 2. Let fieldsArray be ! CreateArrayFromList(fieldNames).
|
|
auto field_names_values = MarkedValueList { vm.heap() };
|
|
auto field_names_values = MarkedValueList { vm.heap() };
|
|
@@ -105,12 +104,12 @@ Vector<String> calendar_fields(GlobalObject& global_object, Object& calendar, Ve
|
|
if (fields) {
|
|
if (fields) {
|
|
// a. Set fieldsArray to ? Call(fields, calendar, « fieldsArray »).
|
|
// a. Set fieldsArray to ? Call(fields, calendar, « fieldsArray »).
|
|
fields_array = vm.call(*fields, &calendar, fields_array);
|
|
fields_array = vm.call(*fields, &calendar, fields_array);
|
|
- if (vm.exception())
|
|
|
|
- return {};
|
|
|
|
|
|
+ if (auto* exception = vm.exception())
|
|
|
|
+ return throw_completion(exception->value());
|
|
}
|
|
}
|
|
|
|
|
|
// 4. Return ? IterableToListOfType(fieldsArray, « String »).
|
|
// 4. Return ? IterableToListOfType(fieldsArray, « String »).
|
|
- auto list = TRY_OR_DISCARD(iterable_to_list_of_type(global_object, fields_array, { OptionType::String }));
|
|
|
|
|
|
+ auto list = TRY(iterable_to_list_of_type(global_object, fields_array, { OptionType::String }));
|
|
|
|
|
|
Vector<String> result;
|
|
Vector<String> result;
|
|
for (auto& value : list)
|
|
for (auto& value : list)
|
|
@@ -119,171 +118,187 @@ Vector<String> calendar_fields(GlobalObject& global_object, Object& calendar, Ve
|
|
}
|
|
}
|
|
|
|
|
|
// 12.1.9 CalendarYear ( calendar, dateLike ), https://tc39.es/proposal-temporal/#sec-temporal-calendaryear
|
|
// 12.1.9 CalendarYear ( calendar, dateLike ), https://tc39.es/proposal-temporal/#sec-temporal-calendaryear
|
|
-double calendar_year(GlobalObject& global_object, Object& calendar, Object& date_like)
|
|
|
|
|
|
+ThrowCompletionOr<double> calendar_year(GlobalObject& global_object, Object& calendar, Object& date_like)
|
|
{
|
|
{
|
|
auto& vm = global_object.vm();
|
|
auto& vm = global_object.vm();
|
|
// 1. Assert: Type(calendar) is Object.
|
|
// 1. Assert: Type(calendar) is Object.
|
|
|
|
|
|
// 2. Let result be ? Invoke(calendar, "year", « dateLike »).
|
|
// 2. Let result be ? Invoke(calendar, "year", « dateLike »).
|
|
auto result = Value(&calendar).invoke(global_object, vm.names.year, &date_like);
|
|
auto result = Value(&calendar).invoke(global_object, vm.names.year, &date_like);
|
|
- if (vm.exception())
|
|
|
|
- return {};
|
|
|
|
|
|
+ if (auto* exception = vm.exception())
|
|
|
|
+ return throw_completion(exception->value());
|
|
|
|
|
|
// 3. If result is undefined, throw a RangeError exception.
|
|
// 3. If result is undefined, throw a RangeError exception.
|
|
- if (result.is_undefined()) {
|
|
|
|
- vm.throw_exception<RangeError>(global_object, ErrorType::TemporalInvalidCalendarFunctionResult, vm.names.year.as_string(), vm.names.undefined.as_string());
|
|
|
|
- return {};
|
|
|
|
- }
|
|
|
|
|
|
+ if (result.is_undefined())
|
|
|
|
+ return vm.throw_completion<RangeError>(global_object, ErrorType::TemporalInvalidCalendarFunctionResult, vm.names.year.as_string(), vm.names.undefined.as_string());
|
|
|
|
|
|
// 4. Return ? ToIntegerThrowOnInfinity(result).
|
|
// 4. Return ? ToIntegerThrowOnInfinity(result).
|
|
- return TRY_OR_DISCARD(to_integer_throw_on_infinity(global_object, result, ErrorType::TemporalInvalidCalendarFunctionResult, vm.names.year.as_string(), vm.names.Infinity.as_string()));
|
|
|
|
|
|
+ return TRY(to_integer_throw_on_infinity(global_object, result, ErrorType::TemporalInvalidCalendarFunctionResult, vm.names.year.as_string(), vm.names.Infinity.as_string()));
|
|
}
|
|
}
|
|
|
|
|
|
// 12.1.10 CalendarMonth ( calendar, dateLike ), https://tc39.es/proposal-temporal/#sec-temporal-calendarmonth
|
|
// 12.1.10 CalendarMonth ( calendar, dateLike ), https://tc39.es/proposal-temporal/#sec-temporal-calendarmonth
|
|
-double calendar_month(GlobalObject& global_object, Object& calendar, Object& date_like)
|
|
|
|
|
|
+ThrowCompletionOr<double> calendar_month(GlobalObject& global_object, Object& calendar, Object& date_like)
|
|
{
|
|
{
|
|
auto& vm = global_object.vm();
|
|
auto& vm = global_object.vm();
|
|
// 1. Assert: Type(calendar) is Object.
|
|
// 1. Assert: Type(calendar) is Object.
|
|
|
|
|
|
// 2. Let result be ? Invoke(calendar, "month", « dateLike »).
|
|
// 2. Let result be ? Invoke(calendar, "month", « dateLike »).
|
|
auto result = Value(&calendar).invoke(global_object, vm.names.month, &date_like);
|
|
auto result = Value(&calendar).invoke(global_object, vm.names.month, &date_like);
|
|
- if (vm.exception())
|
|
|
|
- return {};
|
|
|
|
|
|
+ if (auto* exception = vm.exception())
|
|
|
|
+ return throw_completion(exception->value());
|
|
|
|
|
|
// 3. If result is undefined, throw a RangeError exception.
|
|
// 3. If result is undefined, throw a RangeError exception.
|
|
- if (result.is_undefined()) {
|
|
|
|
- vm.throw_exception<RangeError>(global_object, ErrorType::TemporalInvalidCalendarFunctionResult, vm.names.month.as_string(), vm.names.undefined.as_string());
|
|
|
|
- return {};
|
|
|
|
- }
|
|
|
|
|
|
+ if (result.is_undefined())
|
|
|
|
+ return vm.throw_completion<RangeError>(global_object, ErrorType::TemporalInvalidCalendarFunctionResult, vm.names.month.as_string(), vm.names.undefined.as_string());
|
|
|
|
|
|
// 4. Return ? ToPositiveInteger(result).
|
|
// 4. Return ? ToPositiveInteger(result).
|
|
- return TRY_OR_DISCARD(to_positive_integer(global_object, result));
|
|
|
|
|
|
+ return TRY(to_positive_integer(global_object, result));
|
|
}
|
|
}
|
|
|
|
|
|
// 12.1.11 CalendarMonthCode ( calendar, dateLike ), https://tc39.es/proposal-temporal/#sec-temporal-calendarmonthcode
|
|
// 12.1.11 CalendarMonthCode ( calendar, dateLike ), https://tc39.es/proposal-temporal/#sec-temporal-calendarmonthcode
|
|
-String calendar_month_code(GlobalObject& global_object, Object& calendar, Object& date_like)
|
|
|
|
|
|
+ThrowCompletionOr<String> calendar_month_code(GlobalObject& global_object, Object& calendar, Object& date_like)
|
|
{
|
|
{
|
|
auto& vm = global_object.vm();
|
|
auto& vm = global_object.vm();
|
|
// 1. Assert: Type(calendar) is Object.
|
|
// 1. Assert: Type(calendar) is Object.
|
|
|
|
|
|
// 2. Let result be ? Invoke(calendar, "monthCode", « dateLike »).
|
|
// 2. Let result be ? Invoke(calendar, "monthCode", « dateLike »).
|
|
auto result = Value(&calendar).invoke(global_object, vm.names.monthCode, &date_like);
|
|
auto result = Value(&calendar).invoke(global_object, vm.names.monthCode, &date_like);
|
|
- if (vm.exception())
|
|
|
|
- return {};
|
|
|
|
|
|
+ if (auto* exception = vm.exception())
|
|
|
|
+ return throw_completion(exception->value());
|
|
|
|
|
|
// 3. If result is undefined, throw a RangeError exception.
|
|
// 3. If result is undefined, throw a RangeError exception.
|
|
- if (result.is_undefined()) {
|
|
|
|
- vm.throw_exception<RangeError>(global_object, ErrorType::TemporalInvalidCalendarFunctionResult, vm.names.monthCode.as_string(), vm.names.undefined.as_string());
|
|
|
|
- return {};
|
|
|
|
- }
|
|
|
|
|
|
+ if (result.is_undefined())
|
|
|
|
+ return vm.throw_completion<RangeError>(global_object, ErrorType::TemporalInvalidCalendarFunctionResult, vm.names.monthCode.as_string(), vm.names.undefined.as_string());
|
|
|
|
|
|
// 4. Return ? ToString(result).
|
|
// 4. Return ? ToString(result).
|
|
return result.to_string(global_object);
|
|
return result.to_string(global_object);
|
|
}
|
|
}
|
|
|
|
|
|
// 12.1.12 CalendarDay ( calendar, dateLike ), https://tc39.es/proposal-temporal/#sec-temporal-calendarday
|
|
// 12.1.12 CalendarDay ( calendar, dateLike ), https://tc39.es/proposal-temporal/#sec-temporal-calendarday
|
|
-double calendar_day(GlobalObject& global_object, Object& calendar, Object& date_like)
|
|
|
|
|
|
+ThrowCompletionOr<double> calendar_day(GlobalObject& global_object, Object& calendar, Object& date_like)
|
|
{
|
|
{
|
|
auto& vm = global_object.vm();
|
|
auto& vm = global_object.vm();
|
|
// 1. Assert: Type(calendar) is Object.
|
|
// 1. Assert: Type(calendar) is Object.
|
|
|
|
|
|
// 2. Let result be ? Invoke(calendar, "day", « dateLike »).
|
|
// 2. Let result be ? Invoke(calendar, "day", « dateLike »).
|
|
auto result = Value(&calendar).invoke(global_object, vm.names.day, &date_like);
|
|
auto result = Value(&calendar).invoke(global_object, vm.names.day, &date_like);
|
|
- if (vm.exception())
|
|
|
|
- return {};
|
|
|
|
|
|
+ if (auto* exception = vm.exception())
|
|
|
|
+ return throw_completion(exception->value());
|
|
|
|
|
|
// 3. If result is undefined, throw a RangeError exception.
|
|
// 3. If result is undefined, throw a RangeError exception.
|
|
- if (result.is_undefined()) {
|
|
|
|
- vm.throw_exception<RangeError>(global_object, ErrorType::TemporalInvalidCalendarFunctionResult, vm.names.day.as_string(), vm.names.undefined.as_string());
|
|
|
|
- return {};
|
|
|
|
- }
|
|
|
|
|
|
+ if (result.is_undefined())
|
|
|
|
+ return vm.throw_completion<RangeError>(global_object, ErrorType::TemporalInvalidCalendarFunctionResult, vm.names.day.as_string(), vm.names.undefined.as_string());
|
|
|
|
|
|
// 4. Return ? ToPositiveInteger(result).
|
|
// 4. Return ? ToPositiveInteger(result).
|
|
- return TRY_OR_DISCARD(to_positive_integer(global_object, result));
|
|
|
|
|
|
+ return TRY(to_positive_integer(global_object, result));
|
|
}
|
|
}
|
|
|
|
|
|
// 12.1.13 CalendarDayOfWeek ( calendar, dateLike ), https://tc39.es/proposal-temporal/#sec-temporal-calendardayofweek
|
|
// 12.1.13 CalendarDayOfWeek ( calendar, dateLike ), https://tc39.es/proposal-temporal/#sec-temporal-calendardayofweek
|
|
-Value calendar_day_of_week(GlobalObject& global_object, Object& calendar, Object& date_like)
|
|
|
|
|
|
+ThrowCompletionOr<Value> calendar_day_of_week(GlobalObject& global_object, Object& calendar, Object& date_like)
|
|
{
|
|
{
|
|
auto& vm = global_object.vm();
|
|
auto& vm = global_object.vm();
|
|
// 1. Assert: Type(calendar) is Object.
|
|
// 1. Assert: Type(calendar) is Object.
|
|
|
|
|
|
// 2. Return ? Invoke(calendar, "dayOfWeek", « dateLike »).
|
|
// 2. Return ? Invoke(calendar, "dayOfWeek", « dateLike »).
|
|
- return Value(&calendar).invoke(global_object, vm.names.dayOfWeek, &date_like);
|
|
|
|
|
|
+ auto day_of_week = Value(&calendar).invoke(global_object, vm.names.dayOfWeek, &date_like);
|
|
|
|
+ if (auto* exception = vm.exception())
|
|
|
|
+ return throw_completion(exception->value());
|
|
|
|
+ return day_of_week;
|
|
}
|
|
}
|
|
|
|
|
|
// 12.1.14 CalendarDayOfYear ( calendar, dateLike ), https://tc39.es/proposal-temporal/#sec-temporal-calendardayofyear
|
|
// 12.1.14 CalendarDayOfYear ( calendar, dateLike ), https://tc39.es/proposal-temporal/#sec-temporal-calendardayofyear
|
|
-Value calendar_day_of_year(GlobalObject& global_object, Object& calendar, Object& date_like)
|
|
|
|
|
|
+ThrowCompletionOr<Value> calendar_day_of_year(GlobalObject& global_object, Object& calendar, Object& date_like)
|
|
{
|
|
{
|
|
auto& vm = global_object.vm();
|
|
auto& vm = global_object.vm();
|
|
// 1. Assert: Type(calendar) is Object.
|
|
// 1. Assert: Type(calendar) is Object.
|
|
|
|
|
|
// 2. Return ? Invoke(calendar, "dayOfYear", « dateLike »).
|
|
// 2. Return ? Invoke(calendar, "dayOfYear", « dateLike »).
|
|
- return Value(&calendar).invoke(global_object, vm.names.dayOfYear, &date_like);
|
|
|
|
|
|
+ auto day_of_year = Value(&calendar).invoke(global_object, vm.names.dayOfYear, &date_like);
|
|
|
|
+ if (auto* exception = vm.exception())
|
|
|
|
+ return throw_completion(exception->value());
|
|
|
|
+ return day_of_year;
|
|
}
|
|
}
|
|
|
|
|
|
// 12.1.15 CalendarWeekOfYear ( calendar, dateLike ), https://tc39.es/proposal-temporal/#sec-temporal-calendarweekofyear
|
|
// 12.1.15 CalendarWeekOfYear ( calendar, dateLike ), https://tc39.es/proposal-temporal/#sec-temporal-calendarweekofyear
|
|
-Value calendar_week_of_year(GlobalObject& global_object, Object& calendar, Object& date_like)
|
|
|
|
|
|
+ThrowCompletionOr<Value> calendar_week_of_year(GlobalObject& global_object, Object& calendar, Object& date_like)
|
|
{
|
|
{
|
|
auto& vm = global_object.vm();
|
|
auto& vm = global_object.vm();
|
|
// 1. Assert: Type(calendar) is Object.
|
|
// 1. Assert: Type(calendar) is Object.
|
|
|
|
|
|
// 2. Return ? Invoke(calendar, "weekOfYear", « dateLike »).
|
|
// 2. Return ? Invoke(calendar, "weekOfYear", « dateLike »).
|
|
- return Value(&calendar).invoke(global_object, vm.names.weekOfYear, &date_like);
|
|
|
|
|
|
+ auto week_of_year = Value(&calendar).invoke(global_object, vm.names.weekOfYear, &date_like);
|
|
|
|
+ if (auto* exception = vm.exception())
|
|
|
|
+ return throw_completion(exception->value());
|
|
|
|
+ return week_of_year;
|
|
}
|
|
}
|
|
|
|
|
|
// 12.1.16 CalendarDaysInWeek ( calendar, dateLike ), https://tc39.es/proposal-temporal/#sec-temporal-calendardaysinweek
|
|
// 12.1.16 CalendarDaysInWeek ( calendar, dateLike ), https://tc39.es/proposal-temporal/#sec-temporal-calendardaysinweek
|
|
-Value calendar_days_in_week(GlobalObject& global_object, Object& calendar, Object& date_like)
|
|
|
|
|
|
+ThrowCompletionOr<Value> calendar_days_in_week(GlobalObject& global_object, Object& calendar, Object& date_like)
|
|
{
|
|
{
|
|
auto& vm = global_object.vm();
|
|
auto& vm = global_object.vm();
|
|
// 1. Assert: Type(calendar) is Object.
|
|
// 1. Assert: Type(calendar) is Object.
|
|
|
|
|
|
// 2. Return ? Invoke(calendar, "daysInWeek", « dateLike »).
|
|
// 2. Return ? Invoke(calendar, "daysInWeek", « dateLike »).
|
|
- return Value(&calendar).invoke(global_object, vm.names.daysInWeek, &date_like);
|
|
|
|
|
|
+ auto days_in_week = Value(&calendar).invoke(global_object, vm.names.daysInWeek, &date_like);
|
|
|
|
+ if (auto* exception = vm.exception())
|
|
|
|
+ return throw_completion(exception->value());
|
|
|
|
+ return days_in_week;
|
|
}
|
|
}
|
|
|
|
|
|
// 12.1.17 CalendarDaysInMonth ( calendar, dateLike ), https://tc39.es/proposal-temporal/#sec-temporal-calendardaysinmonth
|
|
// 12.1.17 CalendarDaysInMonth ( calendar, dateLike ), https://tc39.es/proposal-temporal/#sec-temporal-calendardaysinmonth
|
|
-Value calendar_days_in_month(GlobalObject& global_object, Object& calendar, Object& date_like)
|
|
|
|
|
|
+ThrowCompletionOr<Value> calendar_days_in_month(GlobalObject& global_object, Object& calendar, Object& date_like)
|
|
{
|
|
{
|
|
auto& vm = global_object.vm();
|
|
auto& vm = global_object.vm();
|
|
// 1. Assert: Type(calendar) is Object.
|
|
// 1. Assert: Type(calendar) is Object.
|
|
|
|
|
|
// 2. Return ? Invoke(calendar, "daysInMonth", « dateLike »).
|
|
// 2. Return ? Invoke(calendar, "daysInMonth", « dateLike »).
|
|
- return Value(&calendar).invoke(global_object, vm.names.daysInMonth, &date_like);
|
|
|
|
|
|
+ auto days_in_month = Value(&calendar).invoke(global_object, vm.names.daysInMonth, &date_like);
|
|
|
|
+ if (auto* exception = vm.exception())
|
|
|
|
+ return throw_completion(exception->value());
|
|
|
|
+ return days_in_month;
|
|
}
|
|
}
|
|
|
|
|
|
// 12.1.18 CalendarDaysInYear ( calendar, dateLike ), https://tc39.es/proposal-temporal/#sec-temporal-calendardaysinyear
|
|
// 12.1.18 CalendarDaysInYear ( calendar, dateLike ), https://tc39.es/proposal-temporal/#sec-temporal-calendardaysinyear
|
|
-Value calendar_days_in_year(GlobalObject& global_object, Object& calendar, Object& date_like)
|
|
|
|
|
|
+ThrowCompletionOr<Value> calendar_days_in_year(GlobalObject& global_object, Object& calendar, Object& date_like)
|
|
{
|
|
{
|
|
auto& vm = global_object.vm();
|
|
auto& vm = global_object.vm();
|
|
// 1. Assert: Type(calendar) is Object.
|
|
// 1. Assert: Type(calendar) is Object.
|
|
|
|
|
|
// 2. Return ? Invoke(calendar, "daysInYear", « dateLike »).
|
|
// 2. Return ? Invoke(calendar, "daysInYear", « dateLike »).
|
|
- return Value(&calendar).invoke(global_object, vm.names.daysInYear, &date_like);
|
|
|
|
|
|
+ auto days_in_year = Value(&calendar).invoke(global_object, vm.names.daysInYear, &date_like);
|
|
|
|
+ if (auto* exception = vm.exception())
|
|
|
|
+ return throw_completion(exception->value());
|
|
|
|
+ return days_in_year;
|
|
}
|
|
}
|
|
|
|
|
|
// 12.1.19 CalendarMonthsInYear ( calendar, dateLike ), https://tc39.es/proposal-temporal/#sec-temporal-calendarmonthsinyear
|
|
// 12.1.19 CalendarMonthsInYear ( calendar, dateLike ), https://tc39.es/proposal-temporal/#sec-temporal-calendarmonthsinyear
|
|
-Value calendar_months_in_year(GlobalObject& global_object, Object& calendar, Object& date_like)
|
|
|
|
|
|
+ThrowCompletionOr<Value> calendar_months_in_year(GlobalObject& global_object, Object& calendar, Object& date_like)
|
|
{
|
|
{
|
|
auto& vm = global_object.vm();
|
|
auto& vm = global_object.vm();
|
|
// 1. Assert: Type(calendar) is Object.
|
|
// 1. Assert: Type(calendar) is Object.
|
|
|
|
|
|
// 2. Return ? Invoke(calendar, "monthsInYear", « dateLike »).
|
|
// 2. Return ? Invoke(calendar, "monthsInYear", « dateLike »).
|
|
- return Value(&calendar).invoke(global_object, vm.names.monthsInYear, &date_like);
|
|
|
|
|
|
+ auto months_in_year = Value(&calendar).invoke(global_object, vm.names.monthsInYear, &date_like);
|
|
|
|
+ if (auto* exception = vm.exception())
|
|
|
|
+ return throw_completion(exception->value());
|
|
|
|
+ return months_in_year;
|
|
}
|
|
}
|
|
|
|
|
|
// 12.1.20 CalendarInLeapYear ( calendar, dateLike ), https://tc39.es/proposal-temporal/#sec-temporal-calendarinleapyear
|
|
// 12.1.20 CalendarInLeapYear ( calendar, dateLike ), https://tc39.es/proposal-temporal/#sec-temporal-calendarinleapyear
|
|
-Value calendar_in_leap_year(GlobalObject& global_object, Object& calendar, Object& date_like)
|
|
|
|
|
|
+ThrowCompletionOr<Value> calendar_in_leap_year(GlobalObject& global_object, Object& calendar, Object& date_like)
|
|
{
|
|
{
|
|
auto& vm = global_object.vm();
|
|
auto& vm = global_object.vm();
|
|
// 1. Assert: Type(calendar) is Object.
|
|
// 1. Assert: Type(calendar) is Object.
|
|
|
|
|
|
// 2. Return ? Invoke(calendar, "inLeapYear", « dateLike »).
|
|
// 2. Return ? Invoke(calendar, "inLeapYear", « dateLike »).
|
|
- return Value(&calendar).invoke(global_object, vm.names.inLeapYear, &date_like);
|
|
|
|
|
|
+ auto in_leap_year = Value(&calendar).invoke(global_object, vm.names.inLeapYear, &date_like);
|
|
|
|
+ if (auto* exception = vm.exception())
|
|
|
|
+ return throw_completion(exception->value());
|
|
|
|
+ return in_leap_year;
|
|
}
|
|
}
|
|
|
|
|
|
// 15.6.1.2 CalendarEra ( calendar, dateLike ), https://tc39.es/proposal-temporal/#sec-temporal-calendarera
|
|
// 15.6.1.2 CalendarEra ( calendar, dateLike ), https://tc39.es/proposal-temporal/#sec-temporal-calendarera
|
|
-Value calendar_era(GlobalObject& global_object, Object& calendar, Object& date_like)
|
|
|
|
|
|
+ThrowCompletionOr<Value> calendar_era(GlobalObject& global_object, Object& calendar, Object& date_like)
|
|
{
|
|
{
|
|
auto& vm = global_object.vm();
|
|
auto& vm = global_object.vm();
|
|
|
|
|
|
@@ -291,14 +306,14 @@ Value calendar_era(GlobalObject& global_object, Object& calendar, Object& date_l
|
|
|
|
|
|
// 2. Let result be ? Invoke(calendar, "era", « dateLike »).
|
|
// 2. Let result be ? Invoke(calendar, "era", « dateLike »).
|
|
auto result = Value(&calendar).invoke(global_object, vm.names.era, &date_like);
|
|
auto result = Value(&calendar).invoke(global_object, vm.names.era, &date_like);
|
|
- if (vm.exception())
|
|
|
|
- return {};
|
|
|
|
|
|
+ if (auto* exception = vm.exception())
|
|
|
|
+ return throw_completion(exception->value());
|
|
|
|
|
|
// 3. If result is not undefined, set result to ? ToString(result).
|
|
// 3. If result is not undefined, set result to ? ToString(result).
|
|
if (!result.is_undefined()) {
|
|
if (!result.is_undefined()) {
|
|
auto result_string = result.to_string(global_object);
|
|
auto result_string = result.to_string(global_object);
|
|
- if (vm.exception())
|
|
|
|
- return {};
|
|
|
|
|
|
+ if (auto* exception = vm.exception())
|
|
|
|
+ return throw_completion(exception->value());
|
|
result = js_string(vm, move(result_string));
|
|
result = js_string(vm, move(result_string));
|
|
}
|
|
}
|
|
|
|
|
|
@@ -307,7 +322,7 @@ Value calendar_era(GlobalObject& global_object, Object& calendar, Object& date_l
|
|
}
|
|
}
|
|
|
|
|
|
// 15.6.1.3 CalendarEraYear ( calendar, dateLike ), https://tc39.es/proposal-temporal/#sec-temporal-calendarerayear
|
|
// 15.6.1.3 CalendarEraYear ( calendar, dateLike ), https://tc39.es/proposal-temporal/#sec-temporal-calendarerayear
|
|
-Value calendar_era_year(GlobalObject& global_object, Object& calendar, Object& date_like)
|
|
|
|
|
|
+ThrowCompletionOr<Value> calendar_era_year(GlobalObject& global_object, Object& calendar, Object& date_like)
|
|
{
|
|
{
|
|
auto& vm = global_object.vm();
|
|
auto& vm = global_object.vm();
|
|
|
|
|
|
@@ -315,19 +330,19 @@ Value calendar_era_year(GlobalObject& global_object, Object& calendar, Object& d
|
|
|
|
|
|
// 2. Let result be ? Invoke(calendar, "eraYear", « dateLike »).
|
|
// 2. Let result be ? Invoke(calendar, "eraYear", « dateLike »).
|
|
auto result = Value(&calendar).invoke(global_object, vm.names.eraYear, &date_like);
|
|
auto result = Value(&calendar).invoke(global_object, vm.names.eraYear, &date_like);
|
|
- if (vm.exception())
|
|
|
|
- return {};
|
|
|
|
|
|
+ if (auto* exception = vm.exception())
|
|
|
|
+ return throw_completion(exception->value());
|
|
|
|
|
|
// 3. If result is not undefined, set result to ? ToIntegerThrowOnInfinity(result).
|
|
// 3. If result is not undefined, set result to ? ToIntegerThrowOnInfinity(result).
|
|
if (!result.is_undefined())
|
|
if (!result.is_undefined())
|
|
- result = Value(TRY_OR_DISCARD(to_integer_throw_on_infinity(global_object, result, ErrorType::TemporalInvalidCalendarFunctionResult, vm.names.eraYear.as_string(), "Infinity"sv)));
|
|
|
|
|
|
+ result = Value(TRY(to_integer_throw_on_infinity(global_object, result, ErrorType::TemporalInvalidCalendarFunctionResult, vm.names.eraYear.as_string(), "Infinity"sv)));
|
|
|
|
|
|
// 4. Return result.
|
|
// 4. Return result.
|
|
return result;
|
|
return result;
|
|
}
|
|
}
|
|
|
|
|
|
// 12.1.21 ToTemporalCalendar ( temporalCalendarLike ), https://tc39.es/proposal-temporal/#sec-temporal-totemporalcalendar
|
|
// 12.1.21 ToTemporalCalendar ( temporalCalendarLike ), https://tc39.es/proposal-temporal/#sec-temporal-totemporalcalendar
|
|
-Object* to_temporal_calendar(GlobalObject& global_object, Value temporal_calendar_like)
|
|
|
|
|
|
+ThrowCompletionOr<Object*> to_temporal_calendar(GlobalObject& global_object, Value temporal_calendar_like)
|
|
{
|
|
{
|
|
auto& vm = global_object.vm();
|
|
auto& vm = global_object.vm();
|
|
|
|
|
|
@@ -351,20 +366,21 @@ Object* to_temporal_calendar(GlobalObject& global_object, Value temporal_calenda
|
|
|
|
|
|
// b. If ? HasProperty(temporalCalendarLike, "calendar") is false, return temporalCalendarLike.
|
|
// b. If ? HasProperty(temporalCalendarLike, "calendar") is false, return temporalCalendarLike.
|
|
auto has_property = temporal_calendar_like_object.has_property(vm.names.calendar);
|
|
auto has_property = temporal_calendar_like_object.has_property(vm.names.calendar);
|
|
- if (vm.exception())
|
|
|
|
- return {};
|
|
|
|
|
|
+ if (auto* exception = vm.exception())
|
|
|
|
+ return throw_completion(exception->value());
|
|
if (!has_property)
|
|
if (!has_property)
|
|
return &temporal_calendar_like_object;
|
|
return &temporal_calendar_like_object;
|
|
|
|
|
|
// c. Set temporalCalendarLike to ? Get(temporalCalendarLike, "calendar").
|
|
// c. Set temporalCalendarLike to ? Get(temporalCalendarLike, "calendar").
|
|
temporal_calendar_like = temporal_calendar_like_object.get(vm.names.calendar);
|
|
temporal_calendar_like = temporal_calendar_like_object.get(vm.names.calendar);
|
|
- if (vm.exception())
|
|
|
|
- return {};
|
|
|
|
|
|
+ if (auto* exception = vm.exception())
|
|
|
|
+ return throw_completion(exception->value());
|
|
|
|
+
|
|
// d. If Type(temporalCalendarLike) is Object and ? HasProperty(temporalCalendarLike, "calendar") is false, return temporalCalendarLike.
|
|
// d. If Type(temporalCalendarLike) is Object and ? HasProperty(temporalCalendarLike, "calendar") is false, return temporalCalendarLike.
|
|
if (temporal_calendar_like.is_object()) {
|
|
if (temporal_calendar_like.is_object()) {
|
|
has_property = temporal_calendar_like.as_object().has_property(vm.names.calendar);
|
|
has_property = temporal_calendar_like.as_object().has_property(vm.names.calendar);
|
|
- if (vm.exception())
|
|
|
|
- return {};
|
|
|
|
|
|
+ if (auto* exception = vm.exception())
|
|
|
|
+ return throw_completion(exception->value());
|
|
if (!has_property)
|
|
if (!has_property)
|
|
return &temporal_calendar_like.as_object();
|
|
return &temporal_calendar_like.as_object();
|
|
}
|
|
}
|
|
@@ -372,21 +388,21 @@ Object* to_temporal_calendar(GlobalObject& global_object, Value temporal_calenda
|
|
|
|
|
|
// 2. Let identifier be ? ToString(temporalCalendarLike).
|
|
// 2. Let identifier be ? ToString(temporalCalendarLike).
|
|
auto identifier = temporal_calendar_like.to_string(global_object);
|
|
auto identifier = temporal_calendar_like.to_string(global_object);
|
|
- if (vm.exception())
|
|
|
|
- return {};
|
|
|
|
|
|
+ if (auto* exception = vm.exception())
|
|
|
|
+ return throw_completion(exception->value());
|
|
|
|
|
|
// 3. If ! IsBuiltinCalendar(identifier) is false, then
|
|
// 3. If ! IsBuiltinCalendar(identifier) is false, then
|
|
if (!is_builtin_calendar(identifier)) {
|
|
if (!is_builtin_calendar(identifier)) {
|
|
// a. Let identifier be ? ParseTemporalCalendarString(identifier).
|
|
// a. Let identifier be ? ParseTemporalCalendarString(identifier).
|
|
- identifier = TRY_OR_DISCARD(parse_temporal_calendar_string(global_object, identifier));
|
|
|
|
|
|
+ identifier = TRY(parse_temporal_calendar_string(global_object, identifier));
|
|
}
|
|
}
|
|
|
|
|
|
// 4. Return ! CreateTemporalCalendar(identifier).
|
|
// 4. Return ! CreateTemporalCalendar(identifier).
|
|
- return create_temporal_calendar(global_object, identifier);
|
|
|
|
|
|
+ return create_temporal_calendar(global_object, identifier).release_value();
|
|
}
|
|
}
|
|
|
|
|
|
// 12.1.22 ToTemporalCalendarWithISODefault ( temporalCalendarLike ), https://tc39.es/proposal-temporal/#sec-temporal-totemporalcalendarwithisodefault
|
|
// 12.1.22 ToTemporalCalendarWithISODefault ( temporalCalendarLike ), https://tc39.es/proposal-temporal/#sec-temporal-totemporalcalendarwithisodefault
|
|
-Object* to_temporal_calendar_with_iso_default(GlobalObject& global_object, Value temporal_calendar_like)
|
|
|
|
|
|
+ThrowCompletionOr<Object*> to_temporal_calendar_with_iso_default(GlobalObject& global_object, Value temporal_calendar_like)
|
|
{
|
|
{
|
|
// 1. If temporalCalendarLike is undefined, then
|
|
// 1. If temporalCalendarLike is undefined, then
|
|
if (temporal_calendar_like.is_undefined()) {
|
|
if (temporal_calendar_like.is_undefined()) {
|
|
@@ -398,7 +414,7 @@ Object* to_temporal_calendar_with_iso_default(GlobalObject& global_object, Value
|
|
}
|
|
}
|
|
|
|
|
|
// 12.1.23 GetTemporalCalendarWithISODefault ( item ), https://tc39.es/proposal-temporal/#sec-temporal-gettemporalcalendarwithisodefault
|
|
// 12.1.23 GetTemporalCalendarWithISODefault ( item ), https://tc39.es/proposal-temporal/#sec-temporal-gettemporalcalendarwithisodefault
|
|
-Object* get_temporal_calendar_with_iso_default(GlobalObject& global_object, Object& item)
|
|
|
|
|
|
+ThrowCompletionOr<Object*> get_temporal_calendar_with_iso_default(GlobalObject& global_object, Object& item)
|
|
{
|
|
{
|
|
auto& vm = global_object.vm();
|
|
auto& vm = global_object.vm();
|
|
|
|
|
|
@@ -419,15 +435,15 @@ Object* get_temporal_calendar_with_iso_default(GlobalObject& global_object, Obje
|
|
|
|
|
|
// 2. Let calendar be ? Get(item, "calendar").
|
|
// 2. Let calendar be ? Get(item, "calendar").
|
|
auto calendar = item.get(vm.names.calendar);
|
|
auto calendar = item.get(vm.names.calendar);
|
|
- if (vm.exception())
|
|
|
|
- return {};
|
|
|
|
|
|
+ if (auto* exception = vm.exception())
|
|
|
|
+ return throw_completion(exception->value());
|
|
|
|
|
|
// 3. Return ? ToTemporalCalendarWithISODefault(calendar).
|
|
// 3. Return ? ToTemporalCalendarWithISODefault(calendar).
|
|
return to_temporal_calendar_with_iso_default(global_object, calendar);
|
|
return to_temporal_calendar_with_iso_default(global_object, calendar);
|
|
}
|
|
}
|
|
|
|
|
|
// 12.1.24 DateFromFields ( calendar, fields, options ), https://tc39.es/proposal-temporal/#sec-temporal-datefromfields
|
|
// 12.1.24 DateFromFields ( calendar, fields, options ), https://tc39.es/proposal-temporal/#sec-temporal-datefromfields
|
|
-PlainDate* date_from_fields(GlobalObject& global_object, Object& calendar, Object const& fields, Object const& options)
|
|
|
|
|
|
+ThrowCompletionOr<PlainDate*> date_from_fields(GlobalObject& global_object, Object& calendar, Object const& fields, Object const& options)
|
|
{
|
|
{
|
|
auto& vm = global_object.vm();
|
|
auto& vm = global_object.vm();
|
|
|
|
|
|
@@ -436,24 +452,22 @@ PlainDate* date_from_fields(GlobalObject& global_object, Object& calendar, Objec
|
|
|
|
|
|
// 3. Let date be ? Invoke(calendar, "dateFromFields", « fields, options »).
|
|
// 3. Let date be ? Invoke(calendar, "dateFromFields", « fields, options »).
|
|
auto date = Value(&calendar).invoke(global_object, vm.names.dateFromFields, &fields, &options);
|
|
auto date = Value(&calendar).invoke(global_object, vm.names.dateFromFields, &fields, &options);
|
|
- if (vm.exception())
|
|
|
|
- return {};
|
|
|
|
|
|
+ if (auto* exception = vm.exception())
|
|
|
|
+ return throw_completion(exception->value());
|
|
|
|
|
|
// 4. Perform ? RequireInternalSlot(date, [[InitializedTemporalDate]]).
|
|
// 4. Perform ? RequireInternalSlot(date, [[InitializedTemporalDate]]).
|
|
auto* date_object = date.to_object(global_object);
|
|
auto* date_object = date.to_object(global_object);
|
|
- if (!date_object)
|
|
|
|
- return {};
|
|
|
|
- if (!is<PlainDate>(date_object)) {
|
|
|
|
- vm.throw_exception<TypeError>(global_object, ErrorType::NotAnObjectOfType, "Temporal.PlainDate");
|
|
|
|
- return {};
|
|
|
|
- }
|
|
|
|
|
|
+ if (auto* exception = vm.exception())
|
|
|
|
+ return throw_completion(exception->value());
|
|
|
|
+ if (!is<PlainDate>(date_object))
|
|
|
|
+ return vm.throw_completion<TypeError>(global_object, ErrorType::NotAnObjectOfType, "Temporal.PlainDate");
|
|
|
|
|
|
// 5. Return date.
|
|
// 5. Return date.
|
|
return static_cast<PlainDate*>(date_object);
|
|
return static_cast<PlainDate*>(date_object);
|
|
}
|
|
}
|
|
|
|
|
|
// 12.1.25 YearMonthFromFields ( calendar, fields [ , options ] ), https://tc39.es/proposal-temporal/#sec-temporal-yearmonthfromfields
|
|
// 12.1.25 YearMonthFromFields ( calendar, fields [ , options ] ), https://tc39.es/proposal-temporal/#sec-temporal-yearmonthfromfields
|
|
-PlainYearMonth* year_month_from_fields(GlobalObject& global_object, Object& calendar, Object const& fields, Object const* options)
|
|
|
|
|
|
+ThrowCompletionOr<PlainYearMonth*> year_month_from_fields(GlobalObject& global_object, Object& calendar, Object const& fields, Object const* options)
|
|
{
|
|
{
|
|
auto& vm = global_object.vm();
|
|
auto& vm = global_object.vm();
|
|
|
|
|
|
@@ -466,24 +480,22 @@ PlainYearMonth* year_month_from_fields(GlobalObject& global_object, Object& cale
|
|
|
|
|
|
// 5. Let yearMonth be ? Invoke(calendar, "yearMonthFromFields", « fields, options »).
|
|
// 5. Let yearMonth be ? Invoke(calendar, "yearMonthFromFields", « fields, options »).
|
|
auto year_month = Value(&calendar).invoke(global_object, vm.names.yearMonthFromFields, &fields, options ?: js_undefined());
|
|
auto year_month = Value(&calendar).invoke(global_object, vm.names.yearMonthFromFields, &fields, options ?: js_undefined());
|
|
- if (vm.exception())
|
|
|
|
- return {};
|
|
|
|
|
|
+ if (auto* exception = vm.exception())
|
|
|
|
+ return throw_completion(exception->value());
|
|
|
|
|
|
// 6. Perform ? RequireInternalSlot(yearMonth, [[InitializedTemporalYearMonth]]).
|
|
// 6. Perform ? RequireInternalSlot(yearMonth, [[InitializedTemporalYearMonth]]).
|
|
auto* year_month_object = year_month.to_object(global_object);
|
|
auto* year_month_object = year_month.to_object(global_object);
|
|
- if (!year_month_object)
|
|
|
|
- return {};
|
|
|
|
- if (!is<PlainYearMonth>(year_month_object)) {
|
|
|
|
- vm.throw_exception<TypeError>(global_object, ErrorType::NotAnObjectOfType, "Temporal.PlainYearMonth");
|
|
|
|
- return {};
|
|
|
|
- }
|
|
|
|
|
|
+ if (auto* exception = vm.exception())
|
|
|
|
+ return throw_completion(exception->value());
|
|
|
|
+ if (!is<PlainYearMonth>(year_month_object))
|
|
|
|
+ return vm.throw_completion<TypeError>(global_object, ErrorType::NotAnObjectOfType, "Temporal.PlainYearMonth");
|
|
|
|
|
|
// 7. Return yearMonth.
|
|
// 7. Return yearMonth.
|
|
return static_cast<PlainYearMonth*>(year_month_object);
|
|
return static_cast<PlainYearMonth*>(year_month_object);
|
|
}
|
|
}
|
|
|
|
|
|
// 12.1.26 MonthDayFromFields ( calendar, fields [ , options ] ), https://tc39.es/proposal-temporal/#sec-temporal-monthdayfromfields
|
|
// 12.1.26 MonthDayFromFields ( calendar, fields [ , options ] ), https://tc39.es/proposal-temporal/#sec-temporal-monthdayfromfields
|
|
-PlainMonthDay* month_day_from_fields(GlobalObject& global_object, Object& calendar, Object const& fields, Object const* options)
|
|
|
|
|
|
+ThrowCompletionOr<PlainMonthDay*> month_day_from_fields(GlobalObject& global_object, Object& calendar, Object const& fields, Object const* options)
|
|
{
|
|
{
|
|
auto& vm = global_object.vm();
|
|
auto& vm = global_object.vm();
|
|
|
|
|
|
@@ -496,17 +508,15 @@ PlainMonthDay* month_day_from_fields(GlobalObject& global_object, Object& calend
|
|
|
|
|
|
// 5. Let monthDay be ? Invoke(calendar, "monthDayFromFields", « fields, options »).
|
|
// 5. Let monthDay be ? Invoke(calendar, "monthDayFromFields", « fields, options »).
|
|
auto month_day = Value(&calendar).invoke(global_object, vm.names.monthDayFromFields, &fields, options ?: js_undefined());
|
|
auto month_day = Value(&calendar).invoke(global_object, vm.names.monthDayFromFields, &fields, options ?: js_undefined());
|
|
- if (vm.exception())
|
|
|
|
- return {};
|
|
|
|
|
|
+ if (auto* exception = vm.exception())
|
|
|
|
+ return throw_completion(exception->value());
|
|
|
|
|
|
// 6. Perform ? RequireInternalSlot(monthDay, [[InitializedTemporalMonthDay]]).
|
|
// 6. Perform ? RequireInternalSlot(monthDay, [[InitializedTemporalMonthDay]]).
|
|
auto* month_day_object = month_day.to_object(global_object);
|
|
auto* month_day_object = month_day.to_object(global_object);
|
|
- if (!month_day_object)
|
|
|
|
- return {};
|
|
|
|
- if (!is<PlainMonthDay>(month_day_object)) {
|
|
|
|
- vm.throw_exception<TypeError>(global_object, ErrorType::NotAnObjectOfType, "Temporal.PlainMonthDay");
|
|
|
|
- return {};
|
|
|
|
- }
|
|
|
|
|
|
+ if (auto* exception = vm.exception())
|
|
|
|
+ return throw_completion(exception->value());
|
|
|
|
+ if (!is<PlainMonthDay>(month_day_object))
|
|
|
|
+ return vm.throw_completion<TypeError>(global_object, ErrorType::NotAnObjectOfType, "Temporal.PlainMonthDay");
|
|
|
|
|
|
// 7. Return monthDay.
|
|
// 7. Return monthDay.
|
|
return static_cast<PlainMonthDay*>(month_day_object);
|
|
return static_cast<PlainMonthDay*>(month_day_object);
|
|
@@ -531,7 +541,7 @@ String format_calendar_annotation(StringView id, StringView show_calendar)
|
|
}
|
|
}
|
|
|
|
|
|
// 12.1.28 CalendarEquals ( one, two ), https://tc39.es/proposal-temporal/#sec-temporal-calendarequals
|
|
// 12.1.28 CalendarEquals ( one, two ), https://tc39.es/proposal-temporal/#sec-temporal-calendarequals
|
|
-bool calendar_equals(GlobalObject& global_object, Object& one, Object& two)
|
|
|
|
|
|
+ThrowCompletionOr<bool> calendar_equals(GlobalObject& global_object, Object& one, Object& two)
|
|
{
|
|
{
|
|
auto& vm = global_object.vm();
|
|
auto& vm = global_object.vm();
|
|
|
|
|
|
@@ -541,22 +551,24 @@ bool calendar_equals(GlobalObject& global_object, Object& one, Object& two)
|
|
|
|
|
|
// 2. Let calendarOne be ? ToString(one).
|
|
// 2. Let calendarOne be ? ToString(one).
|
|
auto calendar_one = Value(&one).to_string(global_object);
|
|
auto calendar_one = Value(&one).to_string(global_object);
|
|
- if (vm.exception())
|
|
|
|
- return {};
|
|
|
|
|
|
+ if (auto* exception = vm.exception())
|
|
|
|
+ return throw_completion(exception->value());
|
|
|
|
+
|
|
// 3. Let calendarTwo be ? ToString(two).
|
|
// 3. Let calendarTwo be ? ToString(two).
|
|
auto calendar_two = Value(&two).to_string(global_object);
|
|
auto calendar_two = Value(&two).to_string(global_object);
|
|
- if (vm.exception())
|
|
|
|
- return {};
|
|
|
|
|
|
+ if (auto* exception = vm.exception())
|
|
|
|
+ return throw_completion(exception->value());
|
|
|
|
|
|
// 4. If calendarOne is calendarTwo, return true.
|
|
// 4. If calendarOne is calendarTwo, return true.
|
|
if (calendar_one == calendar_two)
|
|
if (calendar_one == calendar_two)
|
|
return true;
|
|
return true;
|
|
|
|
+
|
|
// 5. Return false.
|
|
// 5. Return false.
|
|
return false;
|
|
return false;
|
|
}
|
|
}
|
|
|
|
|
|
// 12.1.29 ConsolidateCalendars ( one, two ), https://tc39.es/proposal-temporal/#sec-temporal-consolidatecalendars
|
|
// 12.1.29 ConsolidateCalendars ( one, two ), https://tc39.es/proposal-temporal/#sec-temporal-consolidatecalendars
|
|
-Object* consolidate_calendars(GlobalObject& global_object, Object& one, Object& two)
|
|
|
|
|
|
+ThrowCompletionOr<Object*> consolidate_calendars(GlobalObject& global_object, Object& one, Object& two)
|
|
{
|
|
{
|
|
auto& vm = global_object.vm();
|
|
auto& vm = global_object.vm();
|
|
// 1. If one and two are the same Object value, return two.
|
|
// 1. If one and two are the same Object value, return two.
|
|
@@ -565,13 +577,13 @@ Object* consolidate_calendars(GlobalObject& global_object, Object& one, Object&
|
|
|
|
|
|
// 2. Let calendarOne be ? ToString(one).
|
|
// 2. Let calendarOne be ? ToString(one).
|
|
auto calendar_one = Value(&one).to_string(global_object);
|
|
auto calendar_one = Value(&one).to_string(global_object);
|
|
- if (vm.exception())
|
|
|
|
- return {};
|
|
|
|
|
|
+ if (auto* exception = vm.exception())
|
|
|
|
+ return throw_completion(exception->value());
|
|
|
|
|
|
// 3. Let calendarTwo be ? ToString(two).
|
|
// 3. Let calendarTwo be ? ToString(two).
|
|
auto calendar_two = Value(&two).to_string(global_object);
|
|
auto calendar_two = Value(&two).to_string(global_object);
|
|
- if (vm.exception())
|
|
|
|
- return {};
|
|
|
|
|
|
+ if (auto* exception = vm.exception())
|
|
|
|
+ return throw_completion(exception->value());
|
|
|
|
|
|
// 4. If calendarOne is calendarTwo, return two.
|
|
// 4. If calendarOne is calendarTwo, return two.
|
|
if (calendar_one == calendar_two)
|
|
if (calendar_one == calendar_two)
|
|
@@ -586,8 +598,7 @@ Object* consolidate_calendars(GlobalObject& global_object, Object& one, Object&
|
|
return &one;
|
|
return &one;
|
|
|
|
|
|
// 7. Throw a RangeError exception.
|
|
// 7. Throw a RangeError exception.
|
|
- vm.throw_exception<RangeError>(global_object, ErrorType::TemporalInvalidCalendar);
|
|
|
|
- return {};
|
|
|
|
|
|
+ return vm.throw_completion<RangeError>(global_object, ErrorType::TemporalInvalidCalendar);
|
|
}
|
|
}
|
|
|
|
|
|
// 12.1.30 IsISOLeapYear ( year ), https://tc39.es/proposal-temporal/#sec-temporal-isisoleapyear
|
|
// 12.1.30 IsISOLeapYear ( year ), https://tc39.es/proposal-temporal/#sec-temporal-isisoleapyear
|
|
@@ -720,27 +731,26 @@ String build_iso_month_code(u8 month)
|
|
}
|
|
}
|
|
|
|
|
|
// 12.1.37 ResolveISOMonth ( fields ), https://tc39.es/proposal-temporal/#sec-temporal-resolveisomonth
|
|
// 12.1.37 ResolveISOMonth ( fields ), https://tc39.es/proposal-temporal/#sec-temporal-resolveisomonth
|
|
-double resolve_iso_month(GlobalObject& global_object, Object const& fields)
|
|
|
|
|
|
+ThrowCompletionOr<double> resolve_iso_month(GlobalObject& global_object, Object const& fields)
|
|
{
|
|
{
|
|
auto& vm = global_object.vm();
|
|
auto& vm = global_object.vm();
|
|
|
|
|
|
// 1. Let month be ? Get(fields, "month").
|
|
// 1. Let month be ? Get(fields, "month").
|
|
auto month = fields.get(vm.names.month);
|
|
auto month = fields.get(vm.names.month);
|
|
- if (vm.exception())
|
|
|
|
- return {};
|
|
|
|
|
|
+ if (auto* exception = vm.exception())
|
|
|
|
+ return throw_completion(exception->value());
|
|
|
|
|
|
// 2. Let monthCode be ? Get(fields, "monthCode").
|
|
// 2. Let monthCode be ? Get(fields, "monthCode").
|
|
auto month_code = fields.get(vm.names.monthCode);
|
|
auto month_code = fields.get(vm.names.monthCode);
|
|
- if (vm.exception())
|
|
|
|
- return {};
|
|
|
|
|
|
+ if (auto* exception = vm.exception())
|
|
|
|
+ return throw_completion(exception->value());
|
|
|
|
|
|
// 3. If monthCode is undefined, then
|
|
// 3. If monthCode is undefined, then
|
|
if (month_code.is_undefined()) {
|
|
if (month_code.is_undefined()) {
|
|
// a. If month is undefined, throw a TypeError exception.
|
|
// a. If month is undefined, throw a TypeError exception.
|
|
- if (month.is_undefined()) {
|
|
|
|
- vm.throw_exception<TypeError>(global_object, ErrorType::TemporalMissingRequiredProperty, vm.names.month.as_string());
|
|
|
|
- return {};
|
|
|
|
- }
|
|
|
|
|
|
+ if (month.is_undefined())
|
|
|
|
+ return vm.throw_completion<TypeError>(global_object, ErrorType::TemporalMissingRequiredProperty, vm.names.month.as_string());
|
|
|
|
+
|
|
// b. Return month.
|
|
// b. Return month.
|
|
return month.as_double();
|
|
return month.as_double();
|
|
}
|
|
}
|
|
@@ -748,168 +758,158 @@ double resolve_iso_month(GlobalObject& global_object, Object const& fields)
|
|
// 4. Assert: Type(monthCode) is String.
|
|
// 4. Assert: Type(monthCode) is String.
|
|
VERIFY(month_code.is_string());
|
|
VERIFY(month_code.is_string());
|
|
auto& month_code_string = month_code.as_string().string();
|
|
auto& month_code_string = month_code.as_string().string();
|
|
|
|
+
|
|
// 5. Let monthLength be the length of monthCode.
|
|
// 5. Let monthLength be the length of monthCode.
|
|
auto month_length = month_code_string.length();
|
|
auto month_length = month_code_string.length();
|
|
|
|
+
|
|
// 6. If monthLength is not 3, throw a RangeError exception.
|
|
// 6. If monthLength is not 3, throw a RangeError exception.
|
|
- if (month_length != 3) {
|
|
|
|
- vm.throw_exception<RangeError>(global_object, ErrorType::TemporalInvalidMonthCode);
|
|
|
|
- return {};
|
|
|
|
- }
|
|
|
|
|
|
+ if (month_length != 3)
|
|
|
|
+ return vm.throw_completion<RangeError>(global_object, ErrorType::TemporalInvalidMonthCode);
|
|
|
|
+
|
|
// 7. Let numberPart be the substring of monthCode from 1.
|
|
// 7. Let numberPart be the substring of monthCode from 1.
|
|
auto number_part = month_code_string.substring(1);
|
|
auto number_part = month_code_string.substring(1);
|
|
|
|
+
|
|
// 8. Set numberPart to ! ToIntegerOrInfinity(numberPart).
|
|
// 8. Set numberPart to ! ToIntegerOrInfinity(numberPart).
|
|
auto number_part_integer = Value(js_string(vm, move(number_part))).to_integer_or_infinity(global_object);
|
|
auto number_part_integer = Value(js_string(vm, move(number_part))).to_integer_or_infinity(global_object);
|
|
|
|
+
|
|
// 9. If numberPart < 1 or numberPart > 12, throw a RangeError exception.
|
|
// 9. If numberPart < 1 or numberPart > 12, throw a RangeError exception.
|
|
- if (number_part_integer < 1 || number_part_integer > 12) {
|
|
|
|
- vm.throw_exception<RangeError>(global_object, ErrorType::TemporalInvalidMonthCode);
|
|
|
|
- return {};
|
|
|
|
- }
|
|
|
|
|
|
+ if (number_part_integer < 1 || number_part_integer > 12)
|
|
|
|
+ return vm.throw_completion<RangeError>(global_object, ErrorType::TemporalInvalidMonthCode);
|
|
|
|
+
|
|
// 10. If month is not undefined, and month ≠ numberPart, then
|
|
// 10. If month is not undefined, and month ≠ numberPart, then
|
|
if (!month.is_undefined() && month.as_double() != number_part_integer) {
|
|
if (!month.is_undefined() && month.as_double() != number_part_integer) {
|
|
// a. Throw a RangeError exception.
|
|
// a. Throw a RangeError exception.
|
|
- vm.throw_exception<RangeError>(global_object, ErrorType::TemporalInvalidMonthCode);
|
|
|
|
- return {};
|
|
|
|
|
|
+ return vm.throw_completion<RangeError>(global_object, ErrorType::TemporalInvalidMonthCode);
|
|
}
|
|
}
|
|
|
|
+
|
|
// 11. If ! SameValueNonNumeric(monthCode, ! BuildISOMonthCode(numberPart)) is false, then
|
|
// 11. If ! SameValueNonNumeric(monthCode, ! BuildISOMonthCode(numberPart)) is false, then
|
|
if (month_code_string != build_iso_month_code(number_part_integer)) {
|
|
if (month_code_string != build_iso_month_code(number_part_integer)) {
|
|
// a. Throw a RangeError exception.
|
|
// a. Throw a RangeError exception.
|
|
- vm.throw_exception<RangeError>(global_object, ErrorType::TemporalInvalidMonthCode);
|
|
|
|
- return {};
|
|
|
|
|
|
+ return vm.throw_completion<RangeError>(global_object, ErrorType::TemporalInvalidMonthCode);
|
|
}
|
|
}
|
|
|
|
+
|
|
// 12. Return numberPart.
|
|
// 12. Return numberPart.
|
|
return number_part_integer;
|
|
return number_part_integer;
|
|
}
|
|
}
|
|
|
|
|
|
// 12.1.38 ISODateFromFields ( fields, options ), https://tc39.es/proposal-temporal/#sec-temporal-isodatefromfields
|
|
// 12.1.38 ISODateFromFields ( fields, options ), https://tc39.es/proposal-temporal/#sec-temporal-isodatefromfields
|
|
-Optional<ISODate> iso_date_from_fields(GlobalObject& global_object, Object const& fields, Object const& options)
|
|
|
|
|
|
+ThrowCompletionOr<ISODate> iso_date_from_fields(GlobalObject& global_object, Object const& fields, Object const& options)
|
|
{
|
|
{
|
|
auto& vm = global_object.vm();
|
|
auto& vm = global_object.vm();
|
|
|
|
|
|
// 1. Assert: Type(fields) is Object.
|
|
// 1. Assert: Type(fields) is Object.
|
|
|
|
|
|
// 2. Let overflow be ? ToTemporalOverflow(options).
|
|
// 2. Let overflow be ? ToTemporalOverflow(options).
|
|
- auto overflow = TRY_OR_DISCARD(to_temporal_overflow(global_object, options));
|
|
|
|
|
|
+ auto overflow = TRY(to_temporal_overflow(global_object, options));
|
|
|
|
|
|
// 3. Set fields to ? PrepareTemporalFields(fields, « "day", "month", "monthCode", "year" », «»).
|
|
// 3. Set fields to ? PrepareTemporalFields(fields, « "day", "month", "monthCode", "year" », «»).
|
|
- auto* prepared_fields = TRY_OR_DISCARD(prepare_temporal_fields(global_object, fields, { "day", "month", "monthCode", "year" }, {}));
|
|
|
|
|
|
+ auto* prepared_fields = TRY(prepare_temporal_fields(global_object, fields, { "day", "month", "monthCode", "year" }, {}));
|
|
|
|
|
|
// 4. Let year be ? Get(fields, "year").
|
|
// 4. Let year be ? Get(fields, "year").
|
|
auto year = prepared_fields->get(vm.names.year);
|
|
auto year = prepared_fields->get(vm.names.year);
|
|
- if (vm.exception())
|
|
|
|
- return {};
|
|
|
|
|
|
+ if (auto* exception = vm.exception())
|
|
|
|
+ return throw_completion(exception->value());
|
|
|
|
|
|
// 5. If year is undefined, throw a TypeError exception.
|
|
// 5. If year is undefined, throw a TypeError exception.
|
|
- if (year.is_undefined()) {
|
|
|
|
- vm.throw_exception<TypeError>(global_object, ErrorType::TemporalMissingRequiredProperty, vm.names.year.as_string());
|
|
|
|
- return {};
|
|
|
|
- }
|
|
|
|
|
|
+ if (year.is_undefined())
|
|
|
|
+ return vm.throw_completion<TypeError>(global_object, ErrorType::TemporalMissingRequiredProperty, vm.names.year.as_string());
|
|
|
|
|
|
// 6. Let month be ? ResolveISOMonth(fields).
|
|
// 6. Let month be ? ResolveISOMonth(fields).
|
|
- auto month = resolve_iso_month(global_object, *prepared_fields);
|
|
|
|
- if (vm.exception())
|
|
|
|
- return {};
|
|
|
|
|
|
+ auto month = TRY(resolve_iso_month(global_object, *prepared_fields));
|
|
|
|
|
|
// 7. Let day be ? Get(fields, "day").
|
|
// 7. Let day be ? Get(fields, "day").
|
|
auto day = prepared_fields->get(vm.names.day);
|
|
auto day = prepared_fields->get(vm.names.day);
|
|
- if (vm.exception())
|
|
|
|
- return {};
|
|
|
|
|
|
+ if (auto* exception = vm.exception())
|
|
|
|
+ return throw_completion(exception->value());
|
|
|
|
|
|
// 8. If day is undefined, throw a TypeError exception.
|
|
// 8. If day is undefined, throw a TypeError exception.
|
|
- if (day.is_undefined()) {
|
|
|
|
- vm.throw_exception<TypeError>(global_object, ErrorType::TemporalMissingRequiredProperty, vm.names.day.as_string());
|
|
|
|
- return {};
|
|
|
|
- }
|
|
|
|
|
|
+ if (day.is_undefined())
|
|
|
|
+ return vm.throw_completion<TypeError>(global_object, ErrorType::TemporalMissingRequiredProperty, vm.names.day.as_string());
|
|
|
|
|
|
// 9. Return ? RegulateISODate(year, month, day, overflow).
|
|
// 9. Return ? RegulateISODate(year, month, day, overflow).
|
|
- return regulate_iso_date(global_object, year.as_double(), month, day.as_double(), overflow);
|
|
|
|
|
|
+ auto iso_date = regulate_iso_date(global_object, year.as_double(), month, day.as_double(), overflow);
|
|
|
|
+ if (auto* exception = vm.exception())
|
|
|
|
+ return throw_completion(exception->value());
|
|
|
|
+ return *iso_date;
|
|
}
|
|
}
|
|
|
|
|
|
// 12.1.39 ISOYearMonthFromFields ( fields, options ), https://tc39.es/proposal-temporal/#sec-temporal-isoyearmonthfromfields
|
|
// 12.1.39 ISOYearMonthFromFields ( fields, options ), https://tc39.es/proposal-temporal/#sec-temporal-isoyearmonthfromfields
|
|
-Optional<ISOYearMonth> iso_year_month_from_fields(GlobalObject& global_object, Object const& fields, Object const& options)
|
|
|
|
|
|
+ThrowCompletionOr<ISOYearMonth> iso_year_month_from_fields(GlobalObject& global_object, Object const& fields, Object const& options)
|
|
{
|
|
{
|
|
auto& vm = global_object.vm();
|
|
auto& vm = global_object.vm();
|
|
|
|
|
|
// 1. Assert: Type(fields) is Object.
|
|
// 1. Assert: Type(fields) is Object.
|
|
|
|
|
|
// 2. Let overflow be ? ToTemporalOverflow(options).
|
|
// 2. Let overflow be ? ToTemporalOverflow(options).
|
|
- auto overflow = TRY_OR_DISCARD(to_temporal_overflow(global_object, options));
|
|
|
|
|
|
+ auto overflow = TRY(to_temporal_overflow(global_object, options));
|
|
|
|
|
|
// 3. Set fields to ? PrepareTemporalFields(fields, « "month", "monthCode", "year" », «»).
|
|
// 3. Set fields to ? PrepareTemporalFields(fields, « "month", "monthCode", "year" », «»).
|
|
- auto* prepared_fields = TRY_OR_DISCARD(prepare_temporal_fields(global_object, fields, { "month"sv, "monthCode"sv, "year"sv }, {}));
|
|
|
|
|
|
+ auto* prepared_fields = TRY(prepare_temporal_fields(global_object, fields, { "month"sv, "monthCode"sv, "year"sv }, {}));
|
|
|
|
|
|
// 4. Let year be ? Get(fields, "year").
|
|
// 4. Let year be ? Get(fields, "year").
|
|
auto year = prepared_fields->get(vm.names.year);
|
|
auto year = prepared_fields->get(vm.names.year);
|
|
- if (vm.exception())
|
|
|
|
- return {};
|
|
|
|
|
|
+ if (auto* exception = vm.exception())
|
|
|
|
+ return throw_completion(exception->value());
|
|
|
|
|
|
// 5. If year is undefined, throw a TypeError exception.
|
|
// 5. If year is undefined, throw a TypeError exception.
|
|
- if (year.is_undefined()) {
|
|
|
|
- vm.throw_exception<TypeError>(global_object, ErrorType::TemporalMissingRequiredProperty, vm.names.year.as_string());
|
|
|
|
- return {};
|
|
|
|
- }
|
|
|
|
|
|
+ if (year.is_undefined())
|
|
|
|
+ return vm.throw_completion<TypeError>(global_object, ErrorType::TemporalMissingRequiredProperty, vm.names.year.as_string());
|
|
|
|
|
|
// 6. Let month be ? ResolveISOMonth(fields).
|
|
// 6. Let month be ? ResolveISOMonth(fields).
|
|
- auto month = resolve_iso_month(global_object, *prepared_fields);
|
|
|
|
- if (vm.exception())
|
|
|
|
- return {};
|
|
|
|
|
|
+ auto month = TRY(resolve_iso_month(global_object, *prepared_fields));
|
|
|
|
|
|
// 7. Let result be ? RegulateISOYearMonth(year, month, overflow).
|
|
// 7. Let result be ? RegulateISOYearMonth(year, month, overflow).
|
|
- auto result = TRY_OR_DISCARD(regulate_iso_year_month(global_object, year.as_double(), month, overflow));
|
|
|
|
|
|
+ auto result = TRY(regulate_iso_year_month(global_object, year.as_double(), month, overflow));
|
|
|
|
|
|
// 8. Return the Record { [[Year]]: result.[[Year]], [[Month]]: result.[[Month]], [[ReferenceISODay]]: 1 }.
|
|
// 8. Return the Record { [[Year]]: result.[[Year]], [[Month]]: result.[[Month]], [[ReferenceISODay]]: 1 }.
|
|
return ISOYearMonth { .year = result.year, .month = result.month, .reference_iso_day = 1 };
|
|
return ISOYearMonth { .year = result.year, .month = result.month, .reference_iso_day = 1 };
|
|
}
|
|
}
|
|
|
|
|
|
// 12.1.40 ISOMonthDayFromFields ( fields, options ), https://tc39.es/proposal-temporal/#sec-temporal-isomonthdayfromfields
|
|
// 12.1.40 ISOMonthDayFromFields ( fields, options ), https://tc39.es/proposal-temporal/#sec-temporal-isomonthdayfromfields
|
|
-Optional<ISOMonthDay> iso_month_day_from_fields(GlobalObject& global_object, Object const& fields, Object const& options)
|
|
|
|
|
|
+ThrowCompletionOr<ISOMonthDay> iso_month_day_from_fields(GlobalObject& global_object, Object const& fields, Object const& options)
|
|
{
|
|
{
|
|
auto& vm = global_object.vm();
|
|
auto& vm = global_object.vm();
|
|
|
|
|
|
// 1. Assert: Type(fields) is Object.
|
|
// 1. Assert: Type(fields) is Object.
|
|
|
|
|
|
// 2. Let overflow be ? ToTemporalOverflow(options).
|
|
// 2. Let overflow be ? ToTemporalOverflow(options).
|
|
- auto overflow = TRY_OR_DISCARD(to_temporal_overflow(global_object, options));
|
|
|
|
|
|
+ auto overflow = TRY(to_temporal_overflow(global_object, options));
|
|
|
|
|
|
// 3. Set fields to ? PrepareTemporalFields(fields, « "day", "month", "monthCode", "year" », «»).
|
|
// 3. Set fields to ? PrepareTemporalFields(fields, « "day", "month", "monthCode", "year" », «»).
|
|
- auto* prepared_fields = TRY_OR_DISCARD(prepare_temporal_fields(global_object, fields, { "day"sv, "month"sv, "monthCode"sv, "year"sv }, {}));
|
|
|
|
|
|
+ auto* prepared_fields = TRY(prepare_temporal_fields(global_object, fields, { "day"sv, "month"sv, "monthCode"sv, "year"sv }, {}));
|
|
|
|
|
|
// 4. Let month be ? Get(fields, "month").
|
|
// 4. Let month be ? Get(fields, "month").
|
|
auto month_value = prepared_fields->get(vm.names.month);
|
|
auto month_value = prepared_fields->get(vm.names.month);
|
|
- if (vm.exception())
|
|
|
|
- return {};
|
|
|
|
|
|
+ if (auto* exception = vm.exception())
|
|
|
|
+ return throw_completion(exception->value());
|
|
|
|
|
|
// 5. Let monthCode be ? Get(fields, "monthCode").
|
|
// 5. Let monthCode be ? Get(fields, "monthCode").
|
|
auto month_code = prepared_fields->get(vm.names.monthCode);
|
|
auto month_code = prepared_fields->get(vm.names.monthCode);
|
|
- if (vm.exception())
|
|
|
|
- return {};
|
|
|
|
|
|
+ if (auto* exception = vm.exception())
|
|
|
|
+ return throw_completion(exception->value());
|
|
|
|
|
|
// 6. Let year be ? Get(fields, "year").
|
|
// 6. Let year be ? Get(fields, "year").
|
|
auto year = prepared_fields->get(vm.names.year);
|
|
auto year = prepared_fields->get(vm.names.year);
|
|
- if (vm.exception())
|
|
|
|
- return {};
|
|
|
|
|
|
+ if (auto* exception = vm.exception())
|
|
|
|
+ return throw_completion(exception->value());
|
|
|
|
|
|
// 7. If month is not undefined, and monthCode and year are both undefined, then
|
|
// 7. If month is not undefined, and monthCode and year are both undefined, then
|
|
if (!month_value.is_undefined() && month_code.is_undefined() && year.is_undefined()) {
|
|
if (!month_value.is_undefined() && month_code.is_undefined() && year.is_undefined()) {
|
|
// a. Throw a TypeError exception.
|
|
// a. Throw a TypeError exception.
|
|
- vm.throw_exception<TypeError>(global_object, ErrorType::TemporalMissingRequiredProperty, "monthCode or year");
|
|
|
|
- return {};
|
|
|
|
|
|
+ return vm.throw_completion<TypeError>(global_object, ErrorType::TemporalMissingRequiredProperty, "monthCode or year");
|
|
}
|
|
}
|
|
|
|
|
|
// 8. Set month to ? ResolveISOMonth(fields).
|
|
// 8. Set month to ? ResolveISOMonth(fields).
|
|
- auto month = resolve_iso_month(global_object, *prepared_fields);
|
|
|
|
- if (vm.exception())
|
|
|
|
- return {};
|
|
|
|
|
|
+ auto month = TRY(resolve_iso_month(global_object, *prepared_fields));
|
|
|
|
|
|
// 9. Let day be ? Get(fields, "day").
|
|
// 9. Let day be ? Get(fields, "day").
|
|
auto day = prepared_fields->get(vm.names.day);
|
|
auto day = prepared_fields->get(vm.names.day);
|
|
- if (vm.exception())
|
|
|
|
- return {};
|
|
|
|
|
|
+ if (auto* exception = vm.exception())
|
|
|
|
+ return throw_completion(exception->value());
|
|
|
|
|
|
// 10. If day is undefined, throw a TypeError exception.
|
|
// 10. If day is undefined, throw a TypeError exception.
|
|
- if (day.is_undefined()) {
|
|
|
|
- vm.throw_exception<TypeError>(global_object, ErrorType::TemporalMissingRequiredProperty, vm.names.day.as_string());
|
|
|
|
- return {};
|
|
|
|
- }
|
|
|
|
|
|
+ if (day.is_undefined())
|
|
|
|
+ return vm.throw_completion<TypeError>(global_object, ErrorType::TemporalMissingRequiredProperty, vm.names.day.as_string());
|
|
|
|
|
|
// 11. Let referenceISOYear be 1972 (the first leap year after the Unix epoch).
|
|
// 11. Let referenceISOYear be 1972 (the first leap year after the Unix epoch).
|
|
i32 reference_iso_year = 1972;
|
|
i32 reference_iso_year = 1972;
|
|
@@ -926,8 +926,8 @@ Optional<ISOMonthDay> iso_month_day_from_fields(GlobalObject& global_object, Obj
|
|
// a. Let result be ? RegulateISODate(referenceISOYear, month, day, overflow).
|
|
// a. Let result be ? RegulateISODate(referenceISOYear, month, day, overflow).
|
|
result = regulate_iso_date(global_object, reference_iso_year, month, day.as_double(), overflow);
|
|
result = regulate_iso_date(global_object, reference_iso_year, month, day.as_double(), overflow);
|
|
}
|
|
}
|
|
- if (vm.exception())
|
|
|
|
- return {};
|
|
|
|
|
|
+ if (auto* exception = vm.exception())
|
|
|
|
+ return throw_completion(exception->value());
|
|
|
|
|
|
// 14. Return the Record { [[Month]]: result.[[Month]], [[Day]]: result.[[Day]], [[ReferenceISOYear]]: referenceISOYear }.
|
|
// 14. Return the Record { [[Month]]: result.[[Month]], [[Day]]: result.[[Day]], [[ReferenceISOYear]]: referenceISOYear }.
|
|
return ISOMonthDay { .month = result->month, .day = result->day, .reference_iso_year = reference_iso_year };
|
|
return ISOMonthDay { .month = result->month, .day = result->day, .reference_iso_year = reference_iso_year };
|
|
@@ -1006,7 +1006,7 @@ u8 iso_day(Object& temporal_object)
|
|
}
|
|
}
|
|
|
|
|
|
// 12.1.45 DefaultMergeFields ( fields, additionalFields ), https://tc39.es/proposal-temporal/#sec-temporal-defaultmergefields
|
|
// 12.1.45 DefaultMergeFields ( fields, additionalFields ), https://tc39.es/proposal-temporal/#sec-temporal-defaultmergefields
|
|
-Object* default_merge_fields(GlobalObject& global_object, Object const& fields, Object const& additional_fields)
|
|
|
|
|
|
+ThrowCompletionOr<Object*> default_merge_fields(GlobalObject& global_object, Object const& fields, Object const& additional_fields)
|
|
{
|
|
{
|
|
auto& vm = global_object.vm();
|
|
auto& vm = global_object.vm();
|
|
|
|
|
|
@@ -1015,8 +1015,8 @@ Object* default_merge_fields(GlobalObject& global_object, Object const& fields,
|
|
|
|
|
|
// 2. Let originalKeys be ? EnumerableOwnPropertyNames(fields, key).
|
|
// 2. Let originalKeys be ? EnumerableOwnPropertyNames(fields, key).
|
|
auto original_keys = fields.enumerable_own_property_names(Object::PropertyKind::Key);
|
|
auto original_keys = fields.enumerable_own_property_names(Object::PropertyKind::Key);
|
|
- if (vm.exception())
|
|
|
|
- return {};
|
|
|
|
|
|
+ if (auto* exception = vm.exception())
|
|
|
|
+ return throw_completion(exception->value());
|
|
|
|
|
|
// 3. For each element nextKey of originalKeys, do
|
|
// 3. For each element nextKey of originalKeys, do
|
|
for (auto& next_key : original_keys) {
|
|
for (auto& next_key : original_keys) {
|
|
@@ -1026,8 +1026,8 @@ Object* default_merge_fields(GlobalObject& global_object, Object const& fields,
|
|
|
|
|
|
// i. Let propValue be ? Get(fields, nextKey).
|
|
// i. Let propValue be ? Get(fields, nextKey).
|
|
auto prop_value = fields.get(property_name);
|
|
auto prop_value = fields.get(property_name);
|
|
- if (vm.exception())
|
|
|
|
- return {};
|
|
|
|
|
|
+ if (auto* exception = vm.exception())
|
|
|
|
+ return throw_completion(exception->value());
|
|
|
|
|
|
// ii. If propValue is not undefined, then
|
|
// ii. If propValue is not undefined, then
|
|
if (!prop_value.is_undefined()) {
|
|
if (!prop_value.is_undefined()) {
|
|
@@ -1039,8 +1039,8 @@ Object* default_merge_fields(GlobalObject& global_object, Object const& fields,
|
|
|
|
|
|
// 4. Let newKeys be ? EnumerableOwnPropertyNames(additionalFields, key).
|
|
// 4. Let newKeys be ? EnumerableOwnPropertyNames(additionalFields, key).
|
|
auto new_keys = additional_fields.enumerable_own_property_names(Object::PropertyKind::Key);
|
|
auto new_keys = additional_fields.enumerable_own_property_names(Object::PropertyKind::Key);
|
|
- if (vm.exception())
|
|
|
|
- return {};
|
|
|
|
|
|
+ if (auto* exception = vm.exception())
|
|
|
|
+ return throw_completion(exception->value());
|
|
|
|
|
|
// IMPLEMENTATION DEFINED: This is an optimization, so we don't have to iterate new_keys three times (worst case), but only once.
|
|
// IMPLEMENTATION DEFINED: This is an optimization, so we don't have to iterate new_keys three times (worst case), but only once.
|
|
bool new_keys_contains_month_or_month_code_property = false;
|
|
bool new_keys_contains_month_or_month_code_property = false;
|
|
@@ -1051,8 +1051,8 @@ Object* default_merge_fields(GlobalObject& global_object, Object const& fields,
|
|
|
|
|
|
// a. Let propValue be ? Get(additionalFields, nextKey).
|
|
// a. Let propValue be ? Get(additionalFields, nextKey).
|
|
auto prop_value = additional_fields.get(property_name);
|
|
auto prop_value = additional_fields.get(property_name);
|
|
- if (vm.exception())
|
|
|
|
- return {};
|
|
|
|
|
|
+ if (auto* exception = vm.exception())
|
|
|
|
+ return throw_completion(exception->value());
|
|
|
|
|
|
// b. If propValue is not undefined, then
|
|
// b. If propValue is not undefined, then
|
|
if (!prop_value.is_undefined()) {
|
|
if (!prop_value.is_undefined()) {
|
|
@@ -1068,8 +1068,8 @@ Object* default_merge_fields(GlobalObject& global_object, Object const& fields,
|
|
if (!new_keys_contains_month_or_month_code_property) {
|
|
if (!new_keys_contains_month_or_month_code_property) {
|
|
// a. Let month be ? Get(fields, "month").
|
|
// a. Let month be ? Get(fields, "month").
|
|
auto month = fields.get(vm.names.month);
|
|
auto month = fields.get(vm.names.month);
|
|
- if (vm.exception())
|
|
|
|
- return {};
|
|
|
|
|
|
+ if (auto* exception = vm.exception())
|
|
|
|
+ return throw_completion(exception->value());
|
|
|
|
|
|
// b. If month is not undefined, then
|
|
// b. If month is not undefined, then
|
|
if (!month.is_undefined()) {
|
|
if (!month.is_undefined()) {
|
|
@@ -1079,8 +1079,8 @@ Object* default_merge_fields(GlobalObject& global_object, Object const& fields,
|
|
|
|
|
|
// c. Let monthCode be ? Get(fields, "monthCode").
|
|
// c. Let monthCode be ? Get(fields, "monthCode").
|
|
auto month_code = fields.get(vm.names.monthCode);
|
|
auto month_code = fields.get(vm.names.monthCode);
|
|
- if (vm.exception())
|
|
|
|
- return {};
|
|
|
|
|
|
+ if (auto* exception = vm.exception())
|
|
|
|
+ return throw_completion(exception->value());
|
|
|
|
|
|
// d. If monthCode is not undefined, then
|
|
// d. If monthCode is not undefined, then
|
|
if (!month_code.is_undefined()) {
|
|
if (!month_code.is_undefined()) {
|