From e24d4c346d2b921af3ee6bcffe441758a93385ce Mon Sep 17 00:00:00 2001 From: Idan Horowitz Date: Tue, 21 Sep 2021 22:08:38 +0300 Subject: [PATCH] LibJS: Add VM::throw_completion helper for throwing custom Strings --- Userland/Libraries/LibJS/Runtime/VM.h | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/Userland/Libraries/LibJS/Runtime/VM.h b/Userland/Libraries/LibJS/Runtime/VM.h index 47cf627dac..f666344b7c 100644 --- a/Userland/Libraries/LibJS/Runtime/VM.h +++ b/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 - 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)...)); + auto* error = T::create(global_object, forward(args)...); // NOTE: This is temporary until we remove VM::exception(). throw_exception(global_object, error); return JS::throw_completion(error); } + template + Completion throw_completion(GlobalObject& global_object, ErrorType type, Args&&... args) + { + return throw_completion(global_object, String::formatted(type.message(), forward(args)...)); + } + Value construct(FunctionObject&, FunctionObject& new_target, Optional arguments); String join_arguments(size_t start_index = 0) const;