Browse Source

LibJS: Add VM::throw_completion helper for throwing custom Strings

Idan Horowitz 3 years ago
parent
commit
e24d4c346d
1 changed files with 8 additions and 2 deletions
  1. 8 2
      Userland/Libraries/LibJS/Runtime/VM.h

+ 8 - 2
Userland/Libraries/LibJS/Runtime/VM.h

@@ -234,14 +234,20 @@ public:
 
     // 5.2.3.2 Throw an Exception, https://tc39.es/ecma262/#sec-throw-an-exception
     template<typename T, typename... Args>
-    Completion throw_completion(GlobalObject& global_object, ErrorType type, Args&&... args)
+    Completion throw_completion(GlobalObject& global_object, Args&&... args)
     {
-        auto* error = T::create(global_object, String::formatted(type.message(), forward<Args>(args)...));
+        auto* error = T::create(global_object, forward<Args>(args)...);
         // NOTE: This is temporary until we remove VM::exception().
         throw_exception(global_object, error);
         return JS::throw_completion(error);
     }
 
+    template<typename T, typename... Args>
+    Completion throw_completion(GlobalObject& global_object, ErrorType type, Args&&... args)
+    {
+        return throw_completion<T>(global_object, String::formatted(type.message(), forward<Args>(args)...));
+    }
+
     Value construct(FunctionObject&, FunctionObject& new_target, Optional<MarkedValueList> arguments);
 
     String join_arguments(size_t start_index = 0) const;