MCPcopy Index your code
hub / github.com/nodejs/node-addon-api / ConstructorCallbackWrapper

Method ConstructorCallbackWrapper

napi-inl.h:5269–5300  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

5267
5268template <typename T>
5269inline 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
5302template <typename T>
5303inline napi_value ObjectWrap<T>::StaticVoidMethodCallbackWrapper(

Callers

nothing calls this directly

Calls 5

WrapCallbackFunction · 0.85
CallbackInfoClass · 0.85
EnvMethod · 0.80
ThisMethod · 0.80

Tested by

no test coverage detected