From e9ae0743bffcae981d47c8d907441d8f7b8e6bf8 Mon Sep 17 00:00:00 2001 From: Pavel Medvedev Date: Sat, 17 Feb 2024 20:11:27 +0100 Subject: [PATCH] add `throw_ex()` helpers like `throw_error()`, `throw_range_error()` see #205 --- v8pp/throw_ex.hpp | 15 +++++++++++++++ v8pp/throw_ex.ipp | 25 +++++++++++++++++++++++++ 2 files changed, 40 insertions(+) diff --git a/v8pp/throw_ex.hpp b/v8pp/throw_ex.hpp index 20675f05..08c4fc1c 100644 --- a/v8pp/throw_ex.hpp +++ b/v8pp/throw_ex.hpp @@ -15,6 +15,21 @@ constexpr bool exception_ctor_with_options = V8_MAJOR_VERSION > 11 || (V8_MAJOR_ v8::Local throw_ex(v8::Isolate* isolate, std::string_view message, exception_ctor ctor = v8::Exception::Error, v8::Local exception_options = {}); +v8::Local throw_error(v8::Isolate* isolate, std::string_view message, + v8::Local exception_options = {}); + +v8::Local throw_range_error(v8::Isolate* isolate, std::string_view message, + v8::Local exception_options = {}); + +v8::Local throw_reference_error(v8::Isolate* isolate, std::string_view message, + v8::Local exception_options = {}); + +v8::Local throw_syntax_error(v8::Isolate* isolate, std::string_view message, + v8::Local exception_options = {}); + +v8::Local throw_type_error(v8::Isolate* isolate, std::string_view message, + v8::Local exception_options = {}); + } // namespace v8pp #if V8PP_HEADER_ONLY diff --git a/v8pp/throw_ex.ipp b/v8pp/throw_ex.ipp index f3db52da..3eb7386d 100644 --- a/v8pp/throw_ex.ipp +++ b/v8pp/throw_ex.ipp @@ -18,4 +18,29 @@ V8PP_IMPL v8::Local throw_ex(v8::Isolate* isolate, std::string_view m return isolate->ThrowException(ex); } +V8PP_IMPL v8::Local throw_error(v8::Isolate* isolate, std::string_view message, v8::Local exception_options) +{ + return throw_ex(isolate, message, v8::Exception::Error, exception_options); +} + +V8PP_IMPL v8::Local throw_range_error(v8::Isolate* isolate, std::string_view message, v8::Local exception_options) +{ + return throw_ex(isolate, message, v8::Exception::RangeError, exception_options); +} + +V8PP_IMPL v8::Local throw_reference_error(v8::Isolate* isolate, std::string_view message, v8::Local exception_options) +{ + return throw_ex(isolate, message, v8::Exception::ReferenceError, exception_options); +} + +V8PP_IMPL v8::Local throw_syntax_error(v8::Isolate* isolate, std::string_view message, v8::Local exception_options) +{ + return throw_ex(isolate, message, v8::Exception::SyntaxError, exception_options); +} + +V8PP_IMPL v8::Local throw_type_error(v8::Isolate* isolate, std::string_view message, v8::Local exception_options) +{ + return throw_ex(isolate, message, v8::Exception::TypeError, exception_options); +} + } // namespace v8pp