Przeglądaj źródła

LibJS: Port Value::get_method() to GCPtr

Linus Groh 2 lat temu
rodzic
commit
b33b0d60e6

+ 2 - 2
Meta/Lagom/Tools/CodeGenerators/LibWeb/BindingsGenerator/IDLGenerators.cpp

@@ -887,7 +887,7 @@ static void generate_to_cpp(SourceGenerator& generator, ParameterType& parameter
     if (!@js_name@@js_suffix@.is_object())
         return vm.throw_completion<JS::TypeError>(JS::ErrorType::NotAnObject, TRY_OR_THROW_OOM(vm, @js_name@@js_suffix@.to_string_without_side_effects()));
 
-    auto* iterator_method@recursion_depth@ = TRY(@js_name@@js_suffix@.get_method(vm, vm.well_known_symbol_iterator()));
+    auto iterator_method@recursion_depth@ = TRY(@js_name@@js_suffix@.get_method(vm, vm.well_known_symbol_iterator()));
     if (!iterator_method@recursion_depth@)
         return vm.throw_completion<JS::TypeError>(JS::ErrorType::NotIterable, TRY_OR_THROW_OOM(vm, @js_name@@js_suffix@.to_string_without_side_effects()));
 )~~~");
@@ -1169,7 +1169,7 @@ static void generate_to_cpp(SourceGenerator& generator, ParameterType& parameter
         if (sequence_type) {
             // 1. Let method be ? GetMethod(V, @@iterator).
             union_generator.append(R"~~~(
-        auto* method = TRY(@js_name@@js_suffix@.get_method(vm, vm.well_known_symbol_iterator()));
+        auto method = TRY(@js_name@@js_suffix@.get_method(vm, vm.well_known_symbol_iterator()));
 )~~~");
 
             // 2. If method is not undefined, return the result of creating a sequence of that type from V and method.

+ 1 - 1
Userland/Libraries/LibJS/Bytecode/Op.cpp

@@ -894,7 +894,7 @@ ThrowCompletionOr<void> GetMethod::execute_impl(Bytecode::Interpreter& interpret
 {
     auto& vm = interpreter.vm();
     auto identifier = interpreter.current_executable().get_identifier(m_property);
-    auto* method = TRY(interpreter.accumulator().get_method(vm, identifier));
+    auto method = TRY(interpreter.accumulator().get_method(vm, identifier));
     interpreter.accumulator() = method ?: js_undefined();
     return {};
 }

+ 1 - 1
Userland/Libraries/LibJS/Runtime/AbstractOperations.cpp

@@ -1401,7 +1401,7 @@ ThrowCompletionOr<GCPtr<FunctionObject>> get_dispose_method(VM& vm, Value value,
 
     // 2. Else,
     // a. Let method be ? GetMethod(V, @@dispose).
-    return GCPtr<FunctionObject> { TRY(value.get_method(vm, vm.well_known_symbol_dispose())) };
+    return TRY(value.get_method(vm, vm.well_known_symbol_dispose()));
 }
 
 // 2.1.5 Dispose ( V, hint, method ), https://tc39.es/proposal-explicit-resource-management/#sec-dispose

+ 2 - 2
Userland/Libraries/LibJS/Runtime/AsyncFromSyncIteratorPrototype.cpp

@@ -112,7 +112,7 @@ JS_DEFINE_NATIVE_FUNCTION(AsyncFromSyncIteratorPrototype::return_)
 
     // 5. Let return be Completion(GetMethod(syncIterator, "return")).
     // 6. IfAbruptRejectPromise(return, promiseCapability).
-    auto* return_method = TRY_OR_REJECT(vm, promise_capability, Value(sync_iterator).get_method(vm, vm.names.return_));
+    auto return_method = TRY_OR_REJECT(vm, promise_capability, Value(sync_iterator).get_method(vm, vm.names.return_));
 
     // 7. If return is undefined, then
     if (return_method == nullptr) {
@@ -165,7 +165,7 @@ JS_DEFINE_NATIVE_FUNCTION(AsyncFromSyncIteratorPrototype::throw_)
 
     // 5. Let throw be Completion(GetMethod(syncIterator, "throw")).
     // 6. IfAbruptRejectPromise(throw, promiseCapability).
-    auto* throw_method = TRY_OR_REJECT(vm, promise_capability, Value(sync_iterator).get_method(vm, vm.names.throw_));
+    auto throw_method = TRY_OR_REJECT(vm, promise_capability, Value(sync_iterator).get_method(vm, vm.names.throw_));
 
     // 7. If throw is undefined, then
     if (throw_method == nullptr) {

+ 3 - 3
Userland/Libraries/LibJS/Runtime/IteratorOperations.cpp

@@ -24,12 +24,12 @@ ThrowCompletionOr<Iterator> get_iterator(VM& vm, Value value, IteratorHint hint,
         // a. If hint is async, then
         if (hint == IteratorHint::Async) {
             // i. Set method to ? GetMethod(obj, @@asyncIterator).
-            auto* async_method = TRY(value.get_method(vm, vm.well_known_symbol_async_iterator()));
+            auto async_method = TRY(value.get_method(vm, vm.well_known_symbol_async_iterator()));
 
             // ii. If method is undefined, then
             if (async_method == nullptr) {
                 // 1. Let syncMethod be ? GetMethod(obj, @@iterator).
-                auto* sync_method = TRY(value.get_method(vm, vm.well_known_symbol_iterator()));
+                auto sync_method = TRY(value.get_method(vm, vm.well_known_symbol_iterator()));
 
                 // 2. Let syncIteratorRecord be ? GetIterator(obj, sync, syncMethod).
                 auto sync_iterator_record = TRY(get_iterator(vm, value, IteratorHint::Sync, sync_method));
@@ -139,7 +139,7 @@ static Completion iterator_close_impl(VM& vm, Iterator const& iterator_record, C
     // 4. If innerResult.[[Type]] is normal, then
     if (!inner_result.is_error()) {
         // a. Let return be innerResult.[[Value]].
-        auto* return_method = get_method_result.value();
+        auto return_method = get_method_result.value();
 
         // b. If return is undefined, return ? completion.
         if (!return_method)

+ 5 - 5
Userland/Libraries/LibJS/Runtime/StringPrototype.cpp

@@ -464,7 +464,7 @@ JS_DEFINE_NATIVE_FUNCTION(StringPrototype::match)
     auto this_object = TRY(require_object_coercible(vm, vm.this_value()));
     auto regexp = vm.argument(0);
     if (!regexp.is_nullish()) {
-        if (auto* matcher = TRY(regexp.get_method(vm, vm.well_known_symbol_match())))
+        if (auto matcher = TRY(regexp.get_method(vm, vm.well_known_symbol_match())))
             return TRY(call(vm, *matcher, regexp, this_object));
     }
 
@@ -488,7 +488,7 @@ JS_DEFINE_NATIVE_FUNCTION(StringPrototype::match_all)
             if (!flags_string.contains('g'))
                 return vm.throw_completion<TypeError>(ErrorType::StringNonGlobalRegExp);
         }
-        if (auto* matcher = TRY(regexp.get_method(vm, vm.well_known_symbol_match_all())))
+        if (auto matcher = TRY(regexp.get_method(vm, vm.well_known_symbol_match_all())))
             return TRY(call(vm, *matcher, regexp, this_object));
     }
 
@@ -613,7 +613,7 @@ JS_DEFINE_NATIVE_FUNCTION(StringPrototype::replace)
     auto replace_value = vm.argument(1);
 
     if (!search_value.is_nullish()) {
-        if (auto* replacer = TRY(search_value.get_method(vm, vm.well_known_symbol_replace())))
+        if (auto replacer = TRY(search_value.get_method(vm, vm.well_known_symbol_replace())))
             return TRY(call(vm, *replacer, search_value, this_object, replace_value));
     }
 
@@ -665,7 +665,7 @@ JS_DEFINE_NATIVE_FUNCTION(StringPrototype::replace_all)
                 return vm.throw_completion<TypeError>(ErrorType::StringNonGlobalRegExp);
         }
 
-        auto* replacer = TRY(search_value.get_method(vm, vm.well_known_symbol_replace()));
+        auto replacer = TRY(search_value.get_method(vm, vm.well_known_symbol_replace()));
         if (replacer)
             return TRY(call(vm, *replacer, search_value, this_object, replace_value));
     }
@@ -722,7 +722,7 @@ JS_DEFINE_NATIVE_FUNCTION(StringPrototype::search)
     auto this_object = TRY(require_object_coercible(vm, vm.this_value()));
     auto regexp = vm.argument(0);
     if (!regexp.is_nullish()) {
-        if (auto* searcher = TRY(regexp.get_method(vm, vm.well_known_symbol_search())))
+        if (auto searcher = TRY(regexp.get_method(vm, vm.well_known_symbol_search())))
             return TRY(call(vm, *searcher, regexp, this_object));
     }
 

+ 1 - 1
Userland/Libraries/LibJS/Runtime/Temporal/Calendar.cpp

@@ -139,7 +139,7 @@ ThrowCompletionOr<Vector<String>> calendar_fields(VM& vm, Object& calendar, Vect
 ThrowCompletionOr<Object*> calendar_merge_fields(VM& vm, Object& calendar, Object& fields, Object& additional_fields)
 {
     // 1. Let mergeFields be ? GetMethod(calendar, "mergeFields").
-    auto* merge_fields = TRY(Value(&calendar).get_method(vm, vm.names.mergeFields));
+    auto merge_fields = TRY(Value(&calendar).get_method(vm, vm.names.mergeFields));
 
     // 2. If mergeFields is undefined, then
     if (!merge_fields) {

+ 13 - 13
Userland/Libraries/LibJS/Runtime/Temporal/Duration.cpp

@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2021-2022, Linus Groh <linusg@serenityos.org>
+ * Copyright (c) 2021-2023, Linus Groh <linusg@serenityos.org>
  * Copyright (c) 2021, Luke Wilde <lukew@serenityos.org>
  *
  * SPDX-License-Identifier: BSD-2-Clause
@@ -678,10 +678,10 @@ ThrowCompletionOr<DateDurationRecord> unbalance_duration_relative(VM& vm, double
         }
 
         // b. Let dateAdd be ? GetMethod(calendar, "dateAdd").
-        auto* date_add = TRY(Value(calendar).get_method(vm, vm.names.dateAdd));
+        auto date_add = TRY(Value(calendar).get_method(vm, vm.names.dateAdd));
 
         // c. Let dateUntil be ? GetMethod(calendar, "dateUntil").
-        auto* date_until = TRY(Value(calendar).get_method(vm, vm.names.dateUntil));
+        auto date_until = TRY(Value(calendar).get_method(vm, vm.names.dateUntil));
 
         // d. Repeat, while years ≠ 0,
         while (years != 0) {
@@ -719,7 +719,7 @@ ThrowCompletionOr<DateDurationRecord> unbalance_duration_relative(VM& vm, double
         }
 
         // b. Let dateAdd be ? GetMethod(calendar, "dateAdd").
-        auto* date_add = TRY(Value(calendar).get_method(vm, vm.names.dateAdd));
+        auto date_add = TRY(Value(calendar).get_method(vm, vm.names.dateAdd));
 
         // c. Repeat, while years ≠ 0,
         while (years != 0) {
@@ -762,7 +762,7 @@ ThrowCompletionOr<DateDurationRecord> unbalance_duration_relative(VM& vm, double
             }
 
             // ii. Let dateAdd be ? GetMethod(calendar, "dateAdd").
-            auto* date_add = TRY(Value(calendar).get_method(vm, vm.names.dateAdd));
+            auto date_add = TRY(Value(calendar).get_method(vm, vm.names.dateAdd));
 
             // iii. Repeat, while years ≠ 0,
             while (years != 0) {
@@ -856,7 +856,7 @@ ThrowCompletionOr<DateDurationRecord> balance_duration_relative(VM& vm, double y
     // 10. If largestUnit is "year", then
     if (largest_unit == "year"sv) {
         // a. Let dateAdd be ? GetMethod(calendar, "dateAdd").
-        auto* date_add = TRY(Value(&calendar).get_method(vm, vm.names.dateAdd));
+        auto date_add = TRY(Value(&calendar).get_method(vm, vm.names.dateAdd));
 
         // b. Let moveResult be ? MoveRelativeDate(calendar, relativeTo, oneYear, dateAdd).
         auto move_result = TRY(move_relative_date(vm, calendar, *relative_to, *one_year, date_add));
@@ -922,7 +922,7 @@ ThrowCompletionOr<DateDurationRecord> balance_duration_relative(VM& vm, double y
         new_relative_to = TRY(calendar_date_add(vm, calendar, relative_to, *one_year, nullptr, date_add));
 
         // k. Let dateUntil be ? GetMethod(calendar, "dateUntil").
-        auto* date_until = TRY(Value(&calendar).get_method(vm, vm.names.dateUntil));
+        auto date_until = TRY(Value(&calendar).get_method(vm, vm.names.dateUntil));
 
         // l. Let untilOptions be OrdinaryObjectCreate(null).
         auto until_options = Object::create(realm, nullptr);
@@ -966,7 +966,7 @@ ThrowCompletionOr<DateDurationRecord> balance_duration_relative(VM& vm, double y
     // 11. Else if largestUnit is "month", then
     else if (largest_unit == "month"sv) {
         // a. Let dateAdd be ? GetMethod(calendar, "dateAdd").
-        auto* date_add = TRY(Value(&calendar).get_method(vm, vm.names.dateAdd));
+        auto date_add = TRY(Value(&calendar).get_method(vm, vm.names.dateAdd));
 
         // b. Let moveResult be ? MoveRelativeDate(calendar, relativeTo, oneMonth, dateAdd).
         auto move_result = TRY(move_relative_date(vm, calendar, *relative_to, *one_month, date_add));
@@ -1004,7 +1004,7 @@ ThrowCompletionOr<DateDurationRecord> balance_duration_relative(VM& vm, double y
         VERIFY(largest_unit == "week"sv);
 
         // b. Let dateAdd be ? GetMethod(calendar, "dateAdd").
-        auto* date_add = TRY(Value(&calendar).get_method(vm, vm.names.dateAdd));
+        auto date_add = TRY(Value(&calendar).get_method(vm, vm.names.dateAdd));
 
         // c. Let moveResult be ? MoveRelativeDate(calendar, relativeTo, oneWeek, dateAdd).
         auto move_result = TRY(move_relative_date(vm, calendar, *relative_to, *one_week, date_add));
@@ -1094,7 +1094,7 @@ ThrowCompletionOr<DurationRecord> add_duration(VM& vm, double years1, double mon
         auto* date_duration2 = MUST(create_temporal_duration(vm, years2, months2, weeks2, days2, 0, 0, 0, 0, 0, 0));
 
         // d. Let dateAdd be ? GetMethod(calendar, "dateAdd").
-        auto* date_add = TRY(Value(&calendar).get_method(vm, vm.names.dateAdd));
+        auto date_add = TRY(Value(&calendar).get_method(vm, vm.names.dateAdd));
 
         // e. Let intermediate be ? CalendarDateAdd(calendar, relativeTo, dateDuration1, undefined, dateAdd).
         auto* intermediate = TRY(calendar_date_add(vm, calendar, &relative_to, *date_duration1, nullptr, date_add));
@@ -1282,7 +1282,7 @@ ThrowCompletionOr<RoundedDuration> round_duration(VM& vm, double years, double m
         auto* years_duration = MUST(create_temporal_duration(vm, years, 0, 0, 0, 0, 0, 0, 0, 0, 0));
 
         // b. Let dateAdd be ? GetMethod(calendar, "dateAdd").
-        auto* date_add = TRY(Value(calendar).get_method(vm, vm.names.dateAdd));
+        auto date_add = TRY(Value(calendar).get_method(vm, vm.names.dateAdd));
 
         // c. Let yearsLater be ? CalendarDateAdd(calendar, relativeTo, yearsDuration, undefined, dateAdd).
         auto* years_later = TRY(calendar_date_add(vm, *calendar, relative_to, *years_duration, nullptr, date_add));
@@ -1372,7 +1372,7 @@ ThrowCompletionOr<RoundedDuration> round_duration(VM& vm, double years, double m
         auto* years_months = MUST(create_temporal_duration(vm, years, months, 0, 0, 0, 0, 0, 0, 0, 0));
 
         // b. Let dateAdd be ? GetMethod(calendar, "dateAdd").
-        auto* date_add = TRY(Value(calendar).get_method(vm, vm.names.dateAdd));
+        auto date_add = TRY(Value(calendar).get_method(vm, vm.names.dateAdd));
 
         // c. Let yearsMonthsLater be ? CalendarDateAdd(calendar, relativeTo, yearsMonths, undefined, dateAdd).
         auto* years_months_later = TRY(calendar_date_add(vm, *calendar, relative_to, *years_months, nullptr, date_add));
@@ -1449,7 +1449,7 @@ ThrowCompletionOr<RoundedDuration> round_duration(VM& vm, double years, double m
         auto* one_week = MUST(create_temporal_duration(vm, 0, 0, sign, 0, 0, 0, 0, 0, 0, 0));
 
         // c. Let dateAdd be ? GetMethod(calendar, "dateAdd").
-        auto* date_add = TRY(Value(calendar).get_method(vm, vm.names.dateAdd));
+        auto date_add = TRY(Value(calendar).get_method(vm, vm.names.dateAdd));
 
         // d. Let moveResult be ? MoveRelativeDate(calendar, relativeTo, oneWeek, dateAdd).
         auto move_result = TRY(move_relative_date(vm, *calendar, *relative_to, *one_week, date_add));

+ 1 - 1
Userland/Libraries/LibJS/Runtime/Temporal/TimeZone.cpp

@@ -329,7 +329,7 @@ ThrowCompletionOr<Object*> to_temporal_time_zone(VM& vm, Value temporal_time_zon
 ThrowCompletionOr<double> get_offset_nanoseconds_for(VM& vm, Value time_zone, Instant& instant)
 {
     // 1. Let getOffsetNanosecondsFor be ? GetMethod(timeZone, "getOffsetNanosecondsFor").
-    auto* get_offset_nanoseconds_for = TRY(time_zone.get_method(vm, vm.names.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(vm, get_offset_nanoseconds_for, time_zone, &instant));

+ 1 - 1
Userland/Libraries/LibJS/Runtime/TypedArrayConstructor.cpp

@@ -81,7 +81,7 @@ JS_DEFINE_NATIVE_FUNCTION(TypedArrayConstructor::from)
     }
 
     // 5. Let usingIterator be ? GetMethod(source, @@iterator).
-    auto* using_iterator = TRY(source.get_method(vm, vm.well_known_symbol_iterator()));
+    auto using_iterator = TRY(source.get_method(vm, vm.well_known_symbol_iterator()));
 
     // 6. If usingIterator is not undefined, then
     if (using_iterator) {

+ 4 - 4
Userland/Libraries/LibJS/Runtime/Value.cpp

@@ -508,7 +508,7 @@ ThrowCompletionOr<Value> Value::to_primitive(VM& vm, PreferredType preferred_typ
     // 1. If input is an Object, then
     if (is_object()) {
         // a. Let exoticToPrim be ? GetMethod(input, @@toPrimitive).
-        auto* exotic_to_primitive = TRY(get_method(vm, vm.well_known_symbol_to_primitive()));
+        auto exotic_to_primitive = TRY(get_method(vm, vm.well_known_symbol_to_primitive()));
 
         // b. If exoticToPrim is not undefined, then
         if (exotic_to_primitive) {
@@ -1228,7 +1228,7 @@ ThrowCompletionOr<Value> Value::get(VM& vm, PropertyKey const& property_key) con
 }
 
 // 7.3.11 GetMethod ( V, P ), https://tc39.es/ecma262/#sec-getmethod
-ThrowCompletionOr<FunctionObject*> Value::get_method(VM& vm, PropertyKey const& property_key) const
+ThrowCompletionOr<GCPtr<FunctionObject>> Value::get_method(VM& vm, PropertyKey const& property_key) const
 {
     // 1. Assert: IsPropertyKey(P) is true.
     VERIFY(property_key.is_valid());
@@ -1245,7 +1245,7 @@ ThrowCompletionOr<FunctionObject*> Value::get_method(VM& vm, PropertyKey const&
         return vm.throw_completion<TypeError>(ErrorType::NotAFunction, TRY_OR_THROW_OOM(vm, function.to_string_without_side_effects()));
 
     // 5. Return func.
-    return &function.as_function();
+    return function.as_function();
 }
 
 // 13.10 Relational Operators, https://tc39.es/ecma262/#sec-relational-operators
@@ -2062,7 +2062,7 @@ ThrowCompletionOr<Value> instance_of(VM& vm, Value value, Value target)
         return vm.throw_completion<TypeError>(ErrorType::NotAnObject, TRY_OR_THROW_OOM(vm, target.to_string_without_side_effects()));
 
     // 2. Let instOfHandler be ? GetMethod(target, @@hasInstance).
-    auto* instance_of_handler = TRY(target.get_method(vm, vm.well_known_symbol_has_instance()));
+    auto instance_of_handler = TRY(target.get_method(vm, vm.well_known_symbol_has_instance()));
 
     // 3. If instOfHandler is not undefined, then
     if (instance_of_handler) {

+ 1 - 1
Userland/Libraries/LibJS/Runtime/Value.h

@@ -392,7 +392,7 @@ public:
     bool to_boolean() const;
 
     ThrowCompletionOr<Value> get(VM&, PropertyKey const&) const;
-    ThrowCompletionOr<FunctionObject*> get_method(VM&, PropertyKey const&) const;
+    ThrowCompletionOr<GCPtr<FunctionObject>> get_method(VM&, PropertyKey const&) const;
 
     ErrorOr<String> to_string_without_side_effects() const;
 

+ 1 - 1
Userland/Libraries/LibWeb/HTML/CustomElements/CustomElementRegistry.cpp

@@ -55,7 +55,7 @@ static JS::ThrowCompletionOr<Vector<String>> convert_value_to_sequence_of_string
         return vm.throw_completion<JS::TypeError>(JS::ErrorType::NotAnObject, TRY_OR_THROW_OOM(vm, value.to_string_without_side_effects()));
 
     // 2. Let method be ? GetMethod(V, @@iterator).
-    auto* method = TRY(value.get_method(vm, vm.well_known_symbol_iterator()));
+    auto method = TRY(value.get_method(vm, vm.well_known_symbol_iterator()));
 
     // 3. If method is undefined, throw a TypeError.
     if (!method)