Преглед изворни кода

LibWeb: Ensure dom_exception_to_throw_completion() always takes a VM

The combination of template + auto&& parameter + constexpr if statements
allowed one caller to pass in a GlobalObject, without the compiler
complaining.
Linus Groh пре 2 година
родитељ
комит
de3e6cc75c

+ 2 - 2
Userland/Libraries/LibWeb/Bindings/ExceptionOrUtils.h

@@ -57,7 +57,7 @@ struct ExtractExceptionOrValueType<WebIDL::ExceptionOr<void>> {
     using Type = JS::Value;
     using Type = JS::Value;
 };
 };
 
 
-ALWAYS_INLINE JS::Completion dom_exception_to_throw_completion(auto&& vm, auto&& exception)
+ALWAYS_INLINE JS::Completion dom_exception_to_throw_completion(JS::VM& vm, auto&& exception)
 {
 {
     return exception.visit(
     return exception.visit(
         [&](WebIDL::SimpleException const& exception) {
         [&](WebIDL::SimpleException const& exception) {
@@ -91,7 +91,7 @@ using ExtractExceptionOrValueType = typename Detail::ExtractExceptionOrValueType
 // ExceptionOr<T>: JS::ThrowCompletionOr<T>
 // ExceptionOr<T>: JS::ThrowCompletionOr<T>
 // T: JS::ThrowCompletionOr<T>
 // T: JS::ThrowCompletionOr<T>
 template<typename F, typename T = decltype(declval<F>()()), typename Ret = Conditional<!IsExceptionOr<T> && !IsVoid<T> && !IsThrowCompletionOr<T>, T, ExtractExceptionOrValueType<T>>>
 template<typename F, typename T = decltype(declval<F>()()), typename Ret = Conditional<!IsExceptionOr<T> && !IsVoid<T> && !IsThrowCompletionOr<T>, T, ExtractExceptionOrValueType<T>>>
-JS::ThrowCompletionOr<Ret> throw_dom_exception_if_needed(auto&& vm, F&& fn)
+JS::ThrowCompletionOr<Ret> throw_dom_exception_if_needed(JS::VM& vm, F&& fn)
 {
 {
     if constexpr (IsExceptionOr<T>) {
     if constexpr (IsExceptionOr<T>) {
         auto&& result = fn();
         auto&& result = fn();

+ 3 - 4
Userland/Libraries/LibWeb/Bindings/LegacyPlatformObject.cpp

@@ -64,8 +64,7 @@ JS::ThrowCompletionOr<bool> LegacyPlatformObject::is_named_property_exposed_on_o
 
 
 JS::ThrowCompletionOr<Optional<JS::PropertyDescriptor>> LegacyPlatformObject::legacy_platform_object_get_own_property_for_get_own_property_slot(JS::PropertyKey const& property_name) const
 JS::ThrowCompletionOr<Optional<JS::PropertyDescriptor>> LegacyPlatformObject::legacy_platform_object_get_own_property_for_get_own_property_slot(JS::PropertyKey const& property_name) const
 {
 {
-
-    [[maybe_unused]] auto& global_object = this->global_object();
+    auto& vm = this->vm();
 
 
     if (property_name.is_number()) {
     if (property_name.is_number()) {
         // 1. Let index be the result of calling ToUint32(P).
         // 1. Let index be the result of calling ToUint32(P).
@@ -75,7 +74,7 @@ JS::ThrowCompletionOr<Optional<JS::PropertyDescriptor>> LegacyPlatformObject::le
         // FIXME: Can this throw?
         // FIXME: Can this throw?
         if (is_supported_property_index(index)) {
         if (is_supported_property_index(index)) {
 
 
-            auto value = TRY(throw_dom_exception_if_needed(global_object, [&] { return item_value(index); }));
+            auto value = TRY(throw_dom_exception_if_needed(vm, [&] { return item_value(index); }));
 
 
             // 5. Let desc be a newly created Property Descriptor with no fields.
             // 5. Let desc be a newly created Property Descriptor with no fields.
             JS::PropertyDescriptor descriptor;
             JS::PropertyDescriptor descriptor;
@@ -102,7 +101,7 @@ JS::ThrowCompletionOr<Optional<JS::PropertyDescriptor>> LegacyPlatformObject::le
         // FIXME: It's unfortunate that this is done twice, once in is_named_property_exposed_on_object and here.
         // FIXME: It's unfortunate that this is done twice, once in is_named_property_exposed_on_object and here.
         auto property_name_string = property_name.to_string();
         auto property_name_string = property_name.to_string();
 
 
-        auto value = TRY(throw_dom_exception_if_needed(global_object, [&] { return named_item_value(property_name_string); }));
+        auto value = TRY(throw_dom_exception_if_needed(vm, [&] { return named_item_value(property_name_string); }));
 
 
         // 5. Let desc be a newly created Property Descriptor with no fields.
         // 5. Let desc be a newly created Property Descriptor with no fields.
         JS::PropertyDescriptor descriptor;
         JS::PropertyDescriptor descriptor;