Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add throw_ex() helpers #212

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading