Skip to content

Commit

Permalink
add throw_ex() helpers
Browse files Browse the repository at this point in the history
like `throw_error()`, `throw_range_error()`

see #205
  • Loading branch information
pmed committed Feb 17, 2024
1 parent 5759d79 commit e9ae074
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 0 deletions.
15 changes: 15 additions & 0 deletions v8pp/throw_ex.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,21 @@ constexpr bool exception_ctor_with_options = V8_MAJOR_VERSION > 11 || (V8_MAJOR_
v8::Local<v8::Value> throw_ex(v8::Isolate* isolate, std::string_view message,
exception_ctor ctor = v8::Exception::Error, v8::Local<v8::Value> exception_options = {});

v8::Local<v8::Value> throw_error(v8::Isolate* isolate, std::string_view message,
v8::Local<v8::Value> exception_options = {});

v8::Local<v8::Value> throw_range_error(v8::Isolate* isolate, std::string_view message,
v8::Local<v8::Value> exception_options = {});

v8::Local<v8::Value> throw_reference_error(v8::Isolate* isolate, std::string_view message,
v8::Local<v8::Value> exception_options = {});

v8::Local<v8::Value> throw_syntax_error(v8::Isolate* isolate, std::string_view message,
v8::Local<v8::Value> exception_options = {});

v8::Local<v8::Value> throw_type_error(v8::Isolate* isolate, std::string_view message,
v8::Local<v8::Value> exception_options = {});

} // namespace v8pp

#if V8PP_HEADER_ONLY
Expand Down
25 changes: 25 additions & 0 deletions v8pp/throw_ex.ipp
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,29 @@ V8PP_IMPL v8::Local<v8::Value> throw_ex(v8::Isolate* isolate, std::string_view m
return isolate->ThrowException(ex);
}

V8PP_IMPL v8::Local<v8::Value> throw_error(v8::Isolate* isolate, std::string_view message, v8::Local<v8::Value> exception_options)
{
return throw_ex(isolate, message, v8::Exception::Error, exception_options);
}

V8PP_IMPL v8::Local<v8::Value> throw_range_error(v8::Isolate* isolate, std::string_view message, v8::Local<v8::Value> exception_options)
{
return throw_ex(isolate, message, v8::Exception::RangeError, exception_options);
}

V8PP_IMPL v8::Local<v8::Value> throw_reference_error(v8::Isolate* isolate, std::string_view message, v8::Local<v8::Value> exception_options)
{
return throw_ex(isolate, message, v8::Exception::ReferenceError, exception_options);
}

V8PP_IMPL v8::Local<v8::Value> throw_syntax_error(v8::Isolate* isolate, std::string_view message, v8::Local<v8::Value> exception_options)
{
return throw_ex(isolate, message, v8::Exception::SyntaxError, exception_options);
}

V8PP_IMPL v8::Local<v8::Value> throw_type_error(v8::Isolate* isolate, std::string_view message, v8::Local<v8::Value> exception_options)
{
return throw_ex(isolate, message, v8::Exception::TypeError, exception_options);
}

} // namespace v8pp

0 comments on commit e9ae074

Please sign in to comment.