Skip to content

Commit

Permalink
src: use NAPI_NOEXCEPT macro instead of noexcept
Browse files Browse the repository at this point in the history
PR-URL: nodejs/node-addon-api#864
Reviewed-By: Michael Dawson <[email protected]>
  • Loading branch information
kevindavies8 committed Jan 8, 2021
1 parent b9b545b commit 468bac0
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 12 deletions.
16 changes: 10 additions & 6 deletions napi-inl.h
Original file line number Diff line number Diff line change
Expand Up @@ -179,17 +179,19 @@ TemplatedInstanceVoidCallback(napi_env env,

template <typename T, typename Finalizer, typename Hint = void>
struct FinalizeData {
static inline
void Wrapper(napi_env env, void* data, void* finalizeHint) noexcept {
static inline void Wrapper(napi_env env,
void* data,
void* finalizeHint) NAPI_NOEXCEPT {
WrapVoidCallback([&] {
FinalizeData* finalizeData = static_cast<FinalizeData*>(finalizeHint);
finalizeData->callback(Env(env), static_cast<T*>(data));
delete finalizeData;
});
}

static inline
void WrapperWithHint(napi_env env, void* data, void* finalizeHint) noexcept {
static inline void WrapperWithHint(napi_env env,
void* data,
void* finalizeHint) NAPI_NOEXCEPT {
WrapVoidCallback([&] {
FinalizeData* finalizeData = static_cast<FinalizeData*>(finalizeHint);
finalizeData->callback(Env(env), static_cast<T*>(data), finalizeData->hint);
Expand Down Expand Up @@ -3562,7 +3564,8 @@ inline napi_value InstanceWrap<T>::InstanceSetterCallbackWrapper(

template <typename T>
template <typename InstanceWrap<T>::InstanceSetterCallback method>
inline napi_value InstanceWrap<T>::WrappedMethod(napi_env env, napi_callback_info info) noexcept {
inline napi_value InstanceWrap<T>::WrappedMethod(
napi_env env, napi_callback_info info) NAPI_NOEXCEPT {
return details::WrapCallback([&] {
const CallbackInfo cbInfo(env, info);
T* instance = T::Unwrap(cbInfo.This().As<Object>());
Expand Down Expand Up @@ -4024,7 +4027,8 @@ inline void ObjectWrap<T>::FinalizeCallback(napi_env env, void* data, void* /*hi

template <typename T>
template <typename ObjectWrap<T>::StaticSetterCallback method>
inline napi_value ObjectWrap<T>::WrappedMethod(napi_env env, napi_callback_info info) noexcept {
inline napi_value ObjectWrap<T>::WrappedMethod(
napi_env env, napi_callback_info info) NAPI_NOEXCEPT {
return details::WrapCallback([&] {
const CallbackInfo cbInfo(env, info);
method(cbInfo, cbInfo[0]);
Expand Down
24 changes: 18 additions & 6 deletions napi.h
Original file line number Diff line number Diff line change
Expand Up @@ -1747,13 +1747,18 @@ namespace Napi {
static napi_value InstanceSetterCallbackWrapper(napi_env env, napi_callback_info info);

template <InstanceSetterCallback method>
static napi_value WrappedMethod(napi_env env, napi_callback_info info) noexcept;
static napi_value WrappedMethod(napi_env env,
napi_callback_info info) NAPI_NOEXCEPT;

template <InstanceSetterCallback setter> struct SetterTag {};

template <InstanceSetterCallback setter>
static napi_callback WrapSetter(SetterTag<setter>) noexcept { return &This::WrappedMethod<setter>; }
static napi_callback WrapSetter(SetterTag<nullptr>) noexcept { return nullptr; }
static napi_callback WrapSetter(SetterTag<setter>) NAPI_NOEXCEPT {
return &This::WrappedMethod<setter>;
}
static napi_callback WrapSetter(SetterTag<nullptr>) NAPI_NOEXCEPT {
return nullptr;
}
};

/// Base class to be extended by C++ classes exposed to JavaScript; each C++ class instance gets
Expand Down Expand Up @@ -1886,13 +1891,20 @@ namespace Napi {
StaticSetterCallback> StaticAccessorCallbackData;

template <StaticSetterCallback method>
static napi_value WrappedMethod(napi_env env, napi_callback_info info) noexcept;
static napi_value WrappedMethod(napi_env env,
napi_callback_info info) NAPI_NOEXCEPT;

template <StaticSetterCallback setter> struct StaticSetterTag {};

template <StaticSetterCallback setter>
static napi_callback WrapStaticSetter(StaticSetterTag<setter>) noexcept { return &This::WrappedMethod<setter>; }
static napi_callback WrapStaticSetter(StaticSetterTag<nullptr>) noexcept { return nullptr; }
static napi_callback WrapStaticSetter(StaticSetterTag<setter>)
NAPI_NOEXCEPT {
return &This::WrappedMethod<setter>;
}
static napi_callback WrapStaticSetter(StaticSetterTag<nullptr>)
NAPI_NOEXCEPT {
return nullptr;
}

bool _construction_failed = true;
};
Expand Down

0 comments on commit 468bac0

Please sign in to comment.