| 5267 | |
| 5268 | template <typename T> |
| 5269 | inline napi_value ObjectWrap<T>::ConstructorCallbackWrapper( |
| 5270 | napi_env env, napi_callback_info info) { |
| 5271 | napi_value new_target; |
| 5272 | napi_status status = napi_get_new_target(env, info, &new_target); |
| 5273 | if (status != napi_ok) return nullptr; |
| 5274 | |
| 5275 | bool isConstructCall = (new_target != nullptr); |
| 5276 | if (!isConstructCall) { |
| 5277 | return details::WrapCallback( |
| 5278 | env, [&] { return T::OnCalledAsFunction(CallbackInfo(env, info)); }); |
| 5279 | } |
| 5280 | |
| 5281 | napi_value wrapper = details::WrapCallback(env, [&] { |
| 5282 | CallbackInfo callbackInfo(env, info); |
| 5283 | T* instance = new T(callbackInfo); |
| 5284 | #ifdef NODE_ADDON_API_CPP_EXCEPTIONS |
| 5285 | instance->_construction_failed = false; |
| 5286 | #else |
| 5287 | if (callbackInfo.Env().IsExceptionPending()) { |
| 5288 | // We need to clear the exception so that removing the wrap might work. |
| 5289 | Error e = callbackInfo.Env().GetAndClearPendingException(); |
| 5290 | delete instance; |
| 5291 | e.ThrowAsJavaScriptException(); |
| 5292 | } else { |
| 5293 | instance->_construction_failed = false; |
| 5294 | } |
| 5295 | #endif // NODE_ADDON_API_CPP_EXCEPTIONS |
| 5296 | return callbackInfo.This(); |
| 5297 | }); |
| 5298 | |
| 5299 | return wrapper; |
| 5300 | } |
| 5301 | |
| 5302 | template <typename T> |
| 5303 | inline napi_value ObjectWrap<T>::StaticVoidMethodCallbackWrapper( |
nothing calls this directly
no test coverage detected