1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-27 08:47:44 +00:00

LibJS: Remove GlobalObject parameter from native functions

This commit is contained in:
Linus Groh 2022-08-22 11:48:08 +01:00
parent 7b990c27a1
commit b465f46e00
77 changed files with 240 additions and 215 deletions

View file

@ -34,7 +34,7 @@ void CollatorPrototype::initialize(Realm& realm)
// 10.3.3 get Intl.Collator.prototype.compare, https://tc39.es/ecma402/#sec-intl.collator.prototype.compare
JS_DEFINE_NATIVE_FUNCTION(CollatorPrototype::compare_getter)
{
auto& realm = *global_object.associated_realm();
auto& realm = *vm.current_realm();
// 1. Let collator be the this value.
// 2. Perform ? RequireInternalSlot(collator, [[InitializedCollator]]).
@ -57,14 +57,14 @@ JS_DEFINE_NATIVE_FUNCTION(CollatorPrototype::compare_getter)
// 10.3.4 Intl.Collator.prototype.resolvedOptions ( ), https://tc39.es/ecma402/#sec-intl.collator.prototype.resolvedoptions
JS_DEFINE_NATIVE_FUNCTION(CollatorPrototype::resolved_options)
{
auto& realm = *global_object.associated_realm();
auto& realm = *vm.current_realm();
// 1. Let collator be the this value.
// 2. Perform ? RequireInternalSlot(collator, [[InitializedCollator]]).
auto* collator = TRY(typed_this_object(vm));
// 3. Let options be OrdinaryObjectCreate(%Object.prototype%).
auto* options = Object::create(realm, global_object.object_prototype());
auto* options = Object::create(realm, realm.global_object().object_prototype());
// 4. For each row of Table 3, except the header row, in table order, do
// a. Let p be the Property value of the current row.

View file

@ -40,7 +40,7 @@ void DateTimeFormatPrototype::initialize(Realm& realm)
// 11.3.3 get Intl.DateTimeFormat.prototype.format, https://tc39.es/ecma402/#sec-intl.datetimeformat.prototype.format
JS_DEFINE_NATIVE_FUNCTION(DateTimeFormatPrototype::format)
{
auto& realm = *global_object.associated_realm();
auto& realm = *vm.current_realm();
// 1. Let dtf be the this value.
// 2. If the implementation supports the normative optional constructor mode of 4.3 Note 1, then
@ -65,6 +65,8 @@ JS_DEFINE_NATIVE_FUNCTION(DateTimeFormatPrototype::format)
// 11.3.4 Intl.DateTimeFormat.prototype.formatToParts ( date ), https://tc39.es/ecma402/#sec-Intl.DateTimeFormat.prototype.formatToParts
JS_DEFINE_NATIVE_FUNCTION(DateTimeFormatPrototype::format_to_parts)
{
auto& realm = *vm.current_realm();
auto date = vm.argument(0);
// 1. Let dtf be the this value.
@ -76,7 +78,7 @@ JS_DEFINE_NATIVE_FUNCTION(DateTimeFormatPrototype::format_to_parts)
// 3. If date is undefined, then
if (date.is_undefined()) {
// a. Let x be ! Call(%Date.now%, undefined).
date_value = MUST(call(vm, global_object.date_constructor_now_function(), js_undefined())).as_double();
date_value = MUST(call(vm, realm.global_object().date_constructor_now_function(), js_undefined())).as_double();
}
// 4. Else,
else {
@ -144,7 +146,7 @@ JS_DEFINE_NATIVE_FUNCTION(DateTimeFormatPrototype::format_range_to_parts)
// 11.3.7 Intl.DateTimeFormat.prototype.resolvedOptions ( ), https://tc39.es/ecma402/#sec-intl.datetimeformat.prototype.resolvedoptions
JS_DEFINE_NATIVE_FUNCTION(DateTimeFormatPrototype::resolved_options)
{
auto& realm = *global_object.associated_realm();
auto& realm = *vm.current_realm();
// 1. Let dtf be the this value.
// 2. If the implementation supports the normative optional constructor mode of 4.3 Note 1, then
@ -153,7 +155,7 @@ JS_DEFINE_NATIVE_FUNCTION(DateTimeFormatPrototype::resolved_options)
auto* date_time_format = TRY(typed_this_object(vm));
// 4. Let options be OrdinaryObjectCreate(%Object.prototype%).
auto* options = Object::create(realm, global_object.object_prototype());
auto* options = Object::create(realm, realm.global_object().object_prototype());
// 5. For each row of Table 5, except the header row, in table order, do
// a. Let p be the Property value of the current row.

View file

@ -124,14 +124,14 @@ JS_DEFINE_NATIVE_FUNCTION(DisplayNamesPrototype::of)
// 12.3.4 Intl.DisplayNames.prototype.resolvedOptions ( ), https://tc39.es/ecma402/#sec-Intl.DisplayNames.prototype.resolvedOptions
JS_DEFINE_NATIVE_FUNCTION(DisplayNamesPrototype::resolved_options)
{
auto& realm = *global_object.associated_realm();
auto& realm = *vm.current_realm();
// 1. Let displayNames be this value.
// 2. Perform ? RequireInternalSlot(displayNames, [[InitializedDisplayNames]]).
auto* display_names = TRY(typed_this_object(vm));
// 3. Let options be OrdinaryObjectCreate(%Object.prototype%).
auto* options = Object::create(realm, global_object.object_prototype());
auto* options = Object::create(realm, realm.global_object().object_prototype());
// 4. For each row of Table 8, except the header row, in table order, do
// a. Let p be the Property value of the current row.

View file

@ -64,7 +64,7 @@ JS_DEFINE_NATIVE_FUNCTION(DurationFormatPrototype::format)
// 1.4.4 Intl.DurationFormat.prototype.formatToParts ( duration ), https://tc39.es/proposal-intl-duration-format/#sec-Intl.DurationFormat.prototype.formatToParts
JS_DEFINE_NATIVE_FUNCTION(DurationFormatPrototype::format_to_parts)
{
auto& realm = *global_object.associated_realm();
auto& realm = *vm.current_realm();
// 1. Let df be this value.
// 2. Perform ? RequireInternalSlot(df, [[InitializedDurationFormat]]).
@ -89,7 +89,7 @@ JS_DEFINE_NATIVE_FUNCTION(DurationFormatPrototype::format_to_parts)
auto const& part = formatted[n];
// a. Let obj be ! OrdinaryObjectCreate(%ObjectPrototype%).
auto* object = Object::create(realm, global_object.object_prototype());
auto* object = Object::create(realm, realm.global_object().object_prototype());
// b. Perform ! CreateDataPropertyOrThrow(obj, "type", part.[[Type]]).
MUST(object->create_data_property_or_throw(vm.names.type, js_string(vm, part.type)));
@ -110,14 +110,14 @@ JS_DEFINE_NATIVE_FUNCTION(DurationFormatPrototype::format_to_parts)
// 1.4.5 Intl.DurationFormat.prototype.resolvedOptions ( ), https://tc39.es/proposal-intl-duration-format/#sec-Intl.DurationFormat.prototype.resolvedOptions
JS_DEFINE_NATIVE_FUNCTION(DurationFormatPrototype::resolved_options)
{
auto& realm = *global_object.associated_realm();
auto& realm = *vm.current_realm();
// 1. Let df be the this value.
// 2. Perform ? RequireInternalSlot(df, [[InitializedDurationFormat]]).
auto* duration_format = TRY(typed_this_object(vm));
// 3. Let options be ! OrdinaryObjectCreate(%Object.prototype%).
auto* options = Object::create(realm, global_object.object_prototype());
auto* options = Object::create(realm, realm.global_object().object_prototype());
// 4. For each row of Table 2, except the header row, in table order, do
// a. Let p be the Property value of the current row.

View file

@ -61,7 +61,7 @@ void Intl::initialize(Realm& realm)
// 8.3.1 Intl.getCanonicalLocales ( locales ), https://tc39.es/ecma402/#sec-intl.getcanonicallocales
JS_DEFINE_NATIVE_FUNCTION(Intl::get_canonical_locales)
{
auto& realm = *global_object.associated_realm();
auto& realm = *vm.current_realm();
auto locales = vm.argument(0);
@ -109,7 +109,7 @@ static Vector<StringView> available_time_zones()
// 2.2.2 Intl.supportedValuesOf ( key ), https://tc39.es/proposal-intl-enumeration/#sec-intl.supportedvaluesof
JS_DEFINE_NATIVE_FUNCTION(Intl::supported_values_of)
{
auto& realm = *global_object.associated_realm();
auto& realm = *vm.current_realm();
// 1. Let key be ? ToString(key).
auto key = TRY(vm.argument(0).to_string(vm));

View file

@ -69,14 +69,14 @@ JS_DEFINE_NATIVE_FUNCTION(ListFormatPrototype::format_to_parts)
// 13.3.5 Intl.ListFormat.prototype.resolvedOptions ( ), https://tc39.es/ecma402/#sec-Intl.ListFormat.prototype.resolvedoptions
JS_DEFINE_NATIVE_FUNCTION(ListFormatPrototype::resolved_options)
{
auto& realm = *global_object.associated_realm();
auto& realm = *vm.current_realm();
// 1. Let lf be the this value.
// 2. Perform ? RequireInternalSlot(lf, [[InitializedListFormat]]).
auto* list_format = TRY(typed_this_object(vm));
// 3. Let options be OrdinaryObjectCreate(%Object.prototype%).
auto* options = Object::create(realm, global_object.object_prototype());
auto* options = Object::create(realm, realm.global_object().object_prototype());
// 4. For each row of Table 10, except the header row, in table order, do
// a. Let p be the Property value of the current row.

View file

@ -55,7 +55,7 @@ void LocalePrototype::initialize(Realm& realm)
// 14.3.3 Intl.Locale.prototype.maximize ( ), https://tc39.es/ecma402/#sec-Intl.Locale.prototype.maximize
JS_DEFINE_NATIVE_FUNCTION(LocalePrototype::maximize)
{
auto& realm = *global_object.associated_realm();
auto& realm = *vm.current_realm();
// 1. Let loc be the this value.
// 2. Perform ? RequireInternalSlot(loc, [[InitializedLocale]]).
@ -75,7 +75,7 @@ JS_DEFINE_NATIVE_FUNCTION(LocalePrototype::maximize)
// 14.3.4 Intl.Locale.prototype.minimize ( ), https://tc39.es/ecma402/#sec-Intl.Locale.prototype.minimize
JS_DEFINE_NATIVE_FUNCTION(LocalePrototype::minimize)
{
auto& realm = *global_object.associated_realm();
auto& realm = *vm.current_realm();
// 1. Let loc be the this value.
// 2. Perform ? RequireInternalSlot(loc, [[InitializedLocale]]).
@ -251,14 +251,14 @@ JS_DEFINE_NATIVE_FUNCTION(LocalePrototype::time_zones)
// 1.4.21 get Intl.Locale.prototype.textInfo, https://tc39.es/proposal-intl-locale-info/#sec-Intl.Locale.prototype.textInfo
JS_DEFINE_NATIVE_FUNCTION(LocalePrototype::text_info)
{
auto& realm = *global_object.associated_realm();
auto& realm = *vm.current_realm();
// 1. Let loc be the this value.
// 2. Perform ? RequireInternalSlot(loc, [[InitializedLocale]]).
auto* locale_object = TRY(typed_this_object(vm));
// 3. Let info be ! ObjectCreate(%Object.prototype%).
auto* info = Object::create(realm, global_object.object_prototype());
auto* info = Object::create(realm, realm.global_object().object_prototype());
// 4. Let dir be ! CharacterDirectionOfLocale(loc).
auto direction = character_direction_of_locale(*locale_object);
@ -273,14 +273,14 @@ JS_DEFINE_NATIVE_FUNCTION(LocalePrototype::text_info)
// 1.4.22 get Intl.Locale.prototype.weekInfo, https://tc39.es/proposal-intl-locale-info/#sec-Intl.Locale.prototype.weekInfo
JS_DEFINE_NATIVE_FUNCTION(LocalePrototype::week_info)
{
auto& realm = *global_object.associated_realm();
auto& realm = *vm.current_realm();
// 1. Let loc be the this value.
// 2. Perform ? RequireInternalSlot(loc, [[InitializedLocale]]).
[[maybe_unused]] auto* locale_object = TRY(typed_this_object(vm));
// 3. Let info be ! ObjectCreate(%Object.prototype%).
auto* info = Object::create(realm, global_object.object_prototype());
auto* info = Object::create(realm, realm.global_object().object_prototype());
// 4. Let wi be ! WeekInfoOfLocale(loc).
auto week_info = week_info_of_locale(*locale_object);

View file

@ -40,7 +40,7 @@ void NumberFormatPrototype::initialize(Realm& realm)
// 15.3.3 get Intl.NumberFormat.prototype.format, https://tc39.es/ecma402/#sec-intl.numberformat.prototype.format
JS_DEFINE_NATIVE_FUNCTION(NumberFormatPrototype::format)
{
auto& realm = *global_object.associated_realm();
auto& realm = *vm.current_realm();
// 1. Let nf be the this value.
// 2. If the implementation supports the normative optional constructor mode of 4.3 Note 1, then
@ -136,7 +136,7 @@ JS_DEFINE_NATIVE_FUNCTION(NumberFormatPrototype::format_range_to_parts)
// 15.3.5 Intl.NumberFormat.prototype.resolvedOptions ( ), https://tc39.es/ecma402/#sec-intl.numberformat.prototype.resolvedoptions
JS_DEFINE_NATIVE_FUNCTION(NumberFormatPrototype::resolved_options)
{
auto& realm = *global_object.associated_realm();
auto& realm = *vm.current_realm();
// 1. Let nf be the this value.
// 2. If the implementation supports the normative optional constructor mode of 4.3 Note 1, then
@ -145,7 +145,7 @@ JS_DEFINE_NATIVE_FUNCTION(NumberFormatPrototype::resolved_options)
auto* number_format = TRY(typed_this_object(vm));
// 4. Let options be OrdinaryObjectCreate(%Object.prototype%).
auto* options = Object::create(realm, global_object.object_prototype());
auto* options = Object::create(realm, realm.global_object().object_prototype());
// 5. For each row of Table 11, except the header row, in table order, do
// a. Let p be the Property value of the current row.

View file

@ -79,14 +79,14 @@ JS_DEFINE_NATIVE_FUNCTION(PluralRulesPrototype::select_range)
// 1.4.5 Intl.PluralRules.prototype.resolvedOptions ( ), https://tc39.es/proposal-intl-numberformat-v3/out/pluralrules/proposed.html#sec-intl.pluralrules.prototype.resolvedoptions
JS_DEFINE_NATIVE_FUNCTION(PluralRulesPrototype::resolved_options)
{
auto& realm = *global_object.associated_realm();
auto& realm = *vm.current_realm();
// 1. Let pr be the this value.
// 2. Perform ? RequireInternalSlot(pr, [[InitializedPluralRules]]).
auto* plural_rules = TRY(typed_this_object(vm));
// 3. Let options be OrdinaryObjectCreate(%Object.prototype%).
auto* options = Object::create(realm, global_object.object_prototype());
auto* options = Object::create(realm, realm.global_object().object_prototype());
// 4. For each row of Table 13, except the header row, in table order, do
// a. Let p be the Property value of the current row.

View file

@ -69,14 +69,14 @@ JS_DEFINE_NATIVE_FUNCTION(RelativeTimeFormatPrototype::format_to_parts)
// 17.3.5 Intl.RelativeTimeFormat.prototype.resolvedOptions ( ), https://tc39.es/ecma402/#sec-intl.relativetimeformat.prototype.resolvedoptions
JS_DEFINE_NATIVE_FUNCTION(RelativeTimeFormatPrototype::resolved_options)
{
auto& realm = *global_object.associated_realm();
auto& realm = *vm.current_realm();
// 1. Let relativeTimeFormat be the this value.
// 2. Perform ? RequireInternalSlot(relativeTimeFormat, [[InitializedRelativeTimeFormat]]).
auto* relative_time_format = TRY(typed_this_object(vm));
// 3. Let options be OrdinaryObjectCreate(%Object.prototype%).
auto* options = Object::create(realm, global_object.object_prototype());
auto* options = Object::create(realm, realm.global_object().object_prototype());
// 4. For each row of Table 15, except the header row, in table order, do
// a. Let p be the Property value of the current row.

View file

@ -34,14 +34,14 @@ void SegmenterPrototype::initialize(Realm& realm)
// 18.3.4 Intl.Segmenter.prototype.resolvedOptions ( ), https://tc39.es/ecma402/#sec-intl.segmenter.prototype.resolvedoptions
JS_DEFINE_NATIVE_FUNCTION(SegmenterPrototype::resolved_options)
{
auto& realm = *global_object.associated_realm();
auto& realm = *vm.current_realm();
// 1. Let segmenter be the this value.
// 2. Perform ? RequireInternalSlot(segmenter, [[InitializedSegmenter]]).
auto* segmenter = TRY(typed_this_object(vm));
// 3. Let options be OrdinaryObjectCreate(%Object.prototype%).
auto* options = Object::create(realm, global_object.object_prototype());
auto* options = Object::create(realm, realm.global_object().object_prototype());
// 4. For each row of Table 16, except the header row, in table order, do
// a. Let p be the Property value of the current row.
@ -58,7 +58,7 @@ JS_DEFINE_NATIVE_FUNCTION(SegmenterPrototype::resolved_options)
// 18.3.3 Intl.Segmenter.prototype.segment ( string ), https://tc39.es/ecma402/#sec-intl.segmenter.prototype.segment
JS_DEFINE_NATIVE_FUNCTION(SegmenterPrototype::segment)
{
auto& realm = *global_object.associated_realm();
auto& realm = *vm.current_realm();
// 1. Let segmenter be the this value.
// 2. Perform ? RequireInternalSlot(segmenter, [[InitializedSegmenter]]).

View file

@ -64,7 +64,7 @@ JS_DEFINE_NATIVE_FUNCTION(SegmentsPrototype::containing)
// 18.5.2.2 %SegmentsPrototype% [ @@iterator ] ( ), https://tc39.es/ecma402/#sec-%segmentsprototype%-@@iterator
JS_DEFINE_NATIVE_FUNCTION(SegmentsPrototype::symbol_iterator)
{
auto& realm = *global_object.associated_realm();
auto& realm = *vm.current_realm();
// 1. Let segments be the this value.
// 2. Perform ? RequireInternalSlot(segments, [[SegmentsSegmenter]]).