mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 22:37:35 +00:00
LibJS: Replace GlobalObject with VM in common AOs [Part 18/19]
This commit is contained in:
parent
7856886ed5
commit
25849f8a6d
95 changed files with 536 additions and 677 deletions
|
@ -75,7 +75,7 @@ ThrowCompletionOr<Calendar*> create_temporal_calendar(VM& vm, String const& iden
|
|||
|
||||
// 3. Let object be ? OrdinaryCreateFromConstructor(newTarget, "%Temporal.Calendar.prototype%", « [[InitializedTemporalCalendar]], [[Identifier]] »).
|
||||
// 4. Set object.[[Identifier]] to identifier.
|
||||
auto* object = TRY(ordinary_create_from_constructor<Calendar>(global_object, *new_target, &GlobalObject::temporal_calendar_prototype, identifier));
|
||||
auto* object = TRY(ordinary_create_from_constructor<Calendar>(vm, *new_target, &GlobalObject::temporal_calendar_prototype, identifier));
|
||||
|
||||
// 5. Return object.
|
||||
return object;
|
||||
|
@ -103,7 +103,6 @@ Calendar* get_iso8601_calendar(VM& vm)
|
|||
ThrowCompletionOr<Vector<String>> calendar_fields(VM& vm, Object& calendar, Vector<StringView> const& field_names)
|
||||
{
|
||||
auto& realm = *vm.current_realm();
|
||||
auto& global_object = realm.global_object();
|
||||
|
||||
// 1. Let fields be ? GetMethod(calendar, "fields").
|
||||
auto fields = TRY(Value(&calendar).get_method(vm, vm.names.fields));
|
||||
|
@ -117,7 +116,7 @@ ThrowCompletionOr<Vector<String>> calendar_fields(VM& vm, Object& calendar, Vect
|
|||
// 3. If fields is not undefined, then
|
||||
if (fields) {
|
||||
// a. Set fieldsArray to ? Call(fields, calendar, « fieldsArray »).
|
||||
fields_array = TRY(call(global_object, *fields, &calendar, fields_array));
|
||||
fields_array = TRY(call(vm, *fields, &calendar, fields_array));
|
||||
}
|
||||
|
||||
// 4. Return ? IterableToListOfType(fieldsArray, « String »).
|
||||
|
@ -132,9 +131,6 @@ ThrowCompletionOr<Vector<String>> calendar_fields(VM& vm, Object& calendar, Vect
|
|||
// 12.2.5 CalendarMergeFields ( calendar, fields, additionalFields ), https://tc39.es/proposal-temporal/#sec-temporal-calendarmergefields
|
||||
ThrowCompletionOr<Object*> calendar_merge_fields(VM& vm, Object& calendar, Object& fields, Object& additional_fields)
|
||||
{
|
||||
auto& realm = *vm.current_realm();
|
||||
auto& global_object = realm.global_object();
|
||||
|
||||
// 1. Let mergeFields be ? GetMethod(calendar, "mergeFields").
|
||||
auto* merge_fields = TRY(Value(&calendar).get_method(vm, vm.names.mergeFields));
|
||||
|
||||
|
@ -145,7 +141,7 @@ ThrowCompletionOr<Object*> calendar_merge_fields(VM& vm, Object& calendar, Objec
|
|||
}
|
||||
|
||||
// 3. Let result be ? Call(mergeFields, calendar, « fields, additionalFields »).
|
||||
auto result = TRY(call(global_object, merge_fields, &calendar, &fields, &additional_fields));
|
||||
auto result = TRY(call(vm, merge_fields, &calendar, &fields, &additional_fields));
|
||||
|
||||
// 4. If Type(result) is not Object, throw a TypeError exception.
|
||||
if (!result.is_object())
|
||||
|
@ -159,8 +155,6 @@ ThrowCompletionOr<Object*> calendar_merge_fields(VM& vm, Object& calendar, Objec
|
|||
ThrowCompletionOr<PlainDate*> calendar_date_add(VM& vm, Object& calendar, Value date, Duration& duration, Object* options, FunctionObject* date_add)
|
||||
{
|
||||
// NOTE: `date` is a `Value` because we sometimes need to pass a PlainDate, sometimes a PlainDateTime, and sometimes undefined.
|
||||
auto& realm = *vm.current_realm();
|
||||
auto& global_object = realm.global_object();
|
||||
|
||||
// 1. Assert: Type(calendar) is Object.
|
||||
// 2. If options is not present, set options to undefined.
|
||||
|
@ -171,7 +165,7 @@ ThrowCompletionOr<PlainDate*> calendar_date_add(VM& vm, Object& calendar, Value
|
|||
date_add = TRY(Value(&calendar).get_method(vm, vm.names.dateAdd));
|
||||
|
||||
// 5. Let addedDate be ? Call(dateAdd, calendar, « date, duration, options »).
|
||||
auto added_date = TRY(call(global_object, date_add ?: js_undefined(), &calendar, date, &duration, options ?: js_undefined()));
|
||||
auto added_date = TRY(call(vm, date_add ?: js_undefined(), &calendar, date, &duration, options ?: js_undefined()));
|
||||
|
||||
// 6. Perform ? RequireInternalSlot(addedDate, [[InitializedTemporalDate]]).
|
||||
auto* added_date_object = TRY(added_date.to_object(vm));
|
||||
|
@ -185,9 +179,6 @@ ThrowCompletionOr<PlainDate*> calendar_date_add(VM& vm, Object& calendar, Value
|
|||
// 12.2.7 CalendarDateUntil ( calendar, one, two, options [ , dateUntil ] ), https://tc39.es/proposal-temporal/#sec-temporal-calendardateuntil
|
||||
ThrowCompletionOr<Duration*> calendar_date_until(VM& vm, Object& calendar, Value one, Value two, Object& options, FunctionObject* date_until)
|
||||
{
|
||||
auto& realm = *vm.current_realm();
|
||||
auto& global_object = realm.global_object();
|
||||
|
||||
// 1. Assert: Type(calendar) is Object.
|
||||
|
||||
// 2. If dateUntil is not present, set dateUntil to ? GetMethod(calendar, "dateUntil").
|
||||
|
@ -195,7 +186,7 @@ ThrowCompletionOr<Duration*> calendar_date_until(VM& vm, Object& calendar, Value
|
|||
date_until = TRY(Value(&calendar).get_method(vm, vm.names.dateUntil));
|
||||
|
||||
// 3. Let duration be ? Call(dateUntil, calendar, « one, two, options »).
|
||||
auto duration = TRY(call(global_object, date_until ?: js_undefined(), &calendar, one, two, &options));
|
||||
auto duration = TRY(call(vm, date_until ?: js_undefined(), &calendar, one, two, &options));
|
||||
|
||||
// 4. Perform ? RequireInternalSlot(duration, [[InitializedTemporalDuration]]).
|
||||
auto* duration_object = TRY(duration.to_object(vm));
|
||||
|
|
|
@ -348,7 +348,7 @@ ThrowCompletionOr<Duration*> create_temporal_duration(VM& vm, double years, doub
|
|||
// 11. Set object.[[Milliseconds]] to ℝ(𝔽(milliseconds)).
|
||||
// 12. Set object.[[Microseconds]] to ℝ(𝔽(microseconds)).
|
||||
// 13. Set object.[[Nanoseconds]] to ℝ(𝔽(nanoseconds)).
|
||||
auto* object = TRY(ordinary_create_from_constructor<Duration>(global_object, *new_target, &GlobalObject::temporal_duration_prototype, years, months, weeks, days, hours, minutes, seconds, milliseconds, microseconds, nanoseconds));
|
||||
auto* object = TRY(ordinary_create_from_constructor<Duration>(vm, *new_target, &GlobalObject::temporal_duration_prototype, years, months, weeks, days, hours, minutes, seconds, milliseconds, microseconds, nanoseconds));
|
||||
|
||||
// 14. Return object.
|
||||
return object;
|
||||
|
|
|
@ -66,7 +66,7 @@ ThrowCompletionOr<Instant*> create_temporal_instant(VM& vm, BigInt const& epoch_
|
|||
|
||||
// 4. Let object be ? OrdinaryCreateFromConstructor(newTarget, "%Temporal.Instant.prototype%", « [[InitializedTemporalInstant]], [[Nanoseconds]] »).
|
||||
// 5. Set object.[[Nanoseconds]] to epochNanoseconds.
|
||||
auto* object = TRY(ordinary_create_from_constructor<Instant>(global_object, *new_target, &GlobalObject::temporal_instant_prototype, epoch_nanoseconds));
|
||||
auto* object = TRY(ordinary_create_from_constructor<Instant>(vm, *new_target, &GlobalObject::temporal_instant_prototype, epoch_nanoseconds));
|
||||
|
||||
// 6. Return object.
|
||||
return object;
|
||||
|
|
|
@ -75,7 +75,7 @@ ThrowCompletionOr<PlainDate*> create_temporal_date(VM& vm, i32 iso_year, u8 iso_
|
|||
// 10. Set object.[[ISOMonth]] to isoMonth.
|
||||
// 11. Set object.[[ISODay]] to isoDay.
|
||||
// 12. Set object.[[Calendar]] to calendar.
|
||||
auto* object = TRY(ordinary_create_from_constructor<PlainDate>(global_object, *new_target, &GlobalObject::temporal_plain_date_prototype, iso_year, iso_month, iso_day, calendar));
|
||||
auto* object = TRY(ordinary_create_from_constructor<PlainDate>(vm, *new_target, &GlobalObject::temporal_plain_date_prototype, iso_year, iso_month, iso_day, calendar));
|
||||
|
||||
return object;
|
||||
}
|
||||
|
|
|
@ -262,7 +262,7 @@ ThrowCompletionOr<PlainDateTime*> create_temporal_date_time(VM& vm, i32 iso_year
|
|||
// 15. Set object.[[ISOMicrosecond]] to microsecond.
|
||||
// 16. Set object.[[ISONanosecond]] to nanosecond.
|
||||
// 17. Set object.[[Calendar]] to calendar.
|
||||
auto* object = TRY(ordinary_create_from_constructor<PlainDateTime>(global_object, *new_target, &GlobalObject::temporal_plain_date_prototype, iso_year, iso_month, iso_day, hour, minute, second, millisecond, microsecond, nanosecond, calendar));
|
||||
auto* object = TRY(ordinary_create_from_constructor<PlainDateTime>(vm, *new_target, &GlobalObject::temporal_plain_date_prototype, iso_year, iso_month, iso_day, hour, minute, second, millisecond, microsecond, nanosecond, calendar));
|
||||
|
||||
// 18. Return object.
|
||||
return object;
|
||||
|
|
|
@ -167,7 +167,7 @@ ThrowCompletionOr<PlainMonthDay*> create_temporal_month_day(VM& vm, u8 iso_month
|
|||
// 8. Set object.[[ISODay]] to isoDay.
|
||||
// 9. Set object.[[Calendar]] to calendar.
|
||||
// 10. Set object.[[ISOYear]] to referenceISOYear.
|
||||
auto* object = TRY(ordinary_create_from_constructor<PlainMonthDay>(global_object, *new_target, &GlobalObject::temporal_plain_month_day_prototype, iso_month, iso_day, reference_iso_year, calendar));
|
||||
auto* object = TRY(ordinary_create_from_constructor<PlainMonthDay>(vm, *new_target, &GlobalObject::temporal_plain_month_day_prototype, iso_month, iso_day, reference_iso_year, calendar));
|
||||
|
||||
// 11. Return object.
|
||||
return object;
|
||||
|
|
|
@ -331,7 +331,7 @@ ThrowCompletionOr<PlainTime*> create_temporal_time(VM& vm, u8 hour, u8 minute, u
|
|||
// 9. Set object.[[ISOMicrosecond]] to microsecond.
|
||||
// 10. Set object.[[ISONanosecond]] to nanosecond.
|
||||
// 11. Set object.[[Calendar]] to ! GetISO8601Calendar().
|
||||
auto* object = TRY(ordinary_create_from_constructor<PlainTime>(global_object, *new_target, &GlobalObject::temporal_plain_time_prototype, hour, minute, second, millisecond, microsecond, nanosecond, *get_iso8601_calendar(vm)));
|
||||
auto* object = TRY(ordinary_create_from_constructor<PlainTime>(vm, *new_target, &GlobalObject::temporal_plain_time_prototype, hour, minute, second, millisecond, microsecond, nanosecond, *get_iso8601_calendar(vm)));
|
||||
|
||||
// 12. Return object.
|
||||
return object;
|
||||
|
|
|
@ -208,7 +208,7 @@ ThrowCompletionOr<PlainYearMonth*> create_temporal_year_month(VM& vm, i32 iso_ye
|
|||
// 8. Set object.[[ISOMonth]] to isoMonth.
|
||||
// 9. Set object.[[Calendar]] to calendar.
|
||||
// 10. Set object.[[ISODay]] to referenceISODay.
|
||||
auto* object = TRY(ordinary_create_from_constructor<PlainYearMonth>(global_object, *new_target, &GlobalObject::temporal_plain_year_month_prototype, iso_year, iso_month, reference_iso_day, calendar));
|
||||
auto* object = TRY(ordinary_create_from_constructor<PlainYearMonth>(vm, *new_target, &GlobalObject::temporal_plain_year_month_prototype, iso_year, iso_month, reference_iso_day, calendar));
|
||||
|
||||
// 11. Return object.
|
||||
return object;
|
||||
|
|
|
@ -73,7 +73,7 @@ ThrowCompletionOr<TimeZone*> create_temporal_time_zone(VM& vm, String const& ide
|
|||
new_target = global_object.temporal_time_zone_constructor();
|
||||
|
||||
// 2. Let object be ? OrdinaryCreateFromConstructor(newTarget, "%Temporal.TimeZone.prototype%", « [[InitializedTemporalTimeZone]], [[Identifier]], [[OffsetNanoseconds]] »).
|
||||
auto* object = TRY(ordinary_create_from_constructor<TimeZone>(global_object, *new_target, &GlobalObject::temporal_time_zone_prototype));
|
||||
auto* object = TRY(ordinary_create_from_constructor<TimeZone>(vm, *new_target, &GlobalObject::temporal_time_zone_prototype));
|
||||
|
||||
// 3. Let offsetNanosecondsResult be Completion(ParseTimeZoneOffsetString(identifier)).
|
||||
auto offset_nanoseconds_result = parse_time_zone_offset_string(vm, identifier);
|
||||
|
@ -476,14 +476,11 @@ ThrowCompletionOr<Object*> to_temporal_time_zone(VM& vm, Value temporal_time_zon
|
|||
// 11.6.11 GetOffsetNanosecondsFor ( timeZone, instant ), https://tc39.es/proposal-temporal/#sec-temporal-getoffsetnanosecondsfor
|
||||
ThrowCompletionOr<double> get_offset_nanoseconds_for(VM& vm, Value time_zone, Instant& instant)
|
||||
{
|
||||
auto& realm = *vm.current_realm();
|
||||
auto& global_object = realm.global_object();
|
||||
|
||||
// 1. Let getOffsetNanosecondsFor be ? GetMethod(timeZone, "getOffsetNanosecondsFor").
|
||||
auto* get_offset_nanoseconds_for = TRY(time_zone.get_method(vm, vm.names.getOffsetNanosecondsFor));
|
||||
|
||||
// 2. Let offsetNanoseconds be ? Call(getOffsetNanosecondsFor, timeZone, « instant »).
|
||||
auto offset_nanoseconds_value = TRY(call(global_object, get_offset_nanoseconds_for, time_zone, &instant));
|
||||
auto offset_nanoseconds_value = TRY(call(vm, get_offset_nanoseconds_for, time_zone, &instant));
|
||||
|
||||
// 3. If Type(offsetNanoseconds) is not Number, throw a TypeError exception.
|
||||
if (!offset_nanoseconds_value.is_number())
|
||||
|
|
|
@ -281,7 +281,7 @@ ThrowCompletionOr<ZonedDateTime*> create_temporal_zoned_date_time(VM& vm, BigInt
|
|||
// 4. Set object.[[Nanoseconds]] to epochNanoseconds.
|
||||
// 5. Set object.[[TimeZone]] to timeZone.
|
||||
// 6. Set object.[[Calendar]] to calendar.
|
||||
auto* object = TRY(ordinary_create_from_constructor<ZonedDateTime>(global_object, *new_target, &GlobalObject::temporal_time_zone_prototype, epoch_nanoseconds, time_zone, calendar));
|
||||
auto* object = TRY(ordinary_create_from_constructor<ZonedDateTime>(vm, *new_target, &GlobalObject::temporal_time_zone_prototype, epoch_nanoseconds, time_zone, calendar));
|
||||
|
||||
// 7. Return object.
|
||||
return object;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue