Skip to content
Closed
Changes from 1 commit
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
Prev Previous commit
Next Next commit
remove static cast in constructor
  • Loading branch information
Gabriel Schulhof committed Jan 7, 2020
commit b00638cf428cd6dd0bea7a4076cb98d3c25e3452
7 changes: 3 additions & 4 deletions napi-inl.h
Original file line number Diff line number Diff line change
Expand Up @@ -3137,12 +3137,11 @@ inline ObjectWrap<T>::ObjectWrap(const Napi::CallbackInfo& callbackInfo) {
napi_value wrapper = callbackInfo.This();
napi_status status;
napi_ref ref;
T* instance = static_cast<T*>(this);
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@dmitryash it's actually possible to avoid this cast, because this works just fine in the code below.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@gabrielschulhof While I agree that this is nicer this way, it also requires updating the cast in FinalizeCallback like #475 does

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@addaleax I think #475 will mostly supersede this PR.

status = napi_wrap(env, wrapper, instance, FinalizeCallback, nullptr, &ref);
status = napi_wrap(env, wrapper, this, FinalizeCallback, nullptr, &ref);
NAPI_THROW_IF_FAILED_VOID(env, status);

ObjectWrapCleanup::MarkWrapOK(callbackInfo);
Reference<Object>* instanceRef = instance;
Reference<Object>* instanceRef = this;
*instanceRef = Reference<Object>(env, ref);
}

Expand Down Expand Up @@ -3722,7 +3721,7 @@ inline napi_value ObjectWrap<T>::ConstructorCallbackWrapper(
try {
new T(callbackInfo);
} catch (const Error& e) {
// re-throw the error after removing the failed wrap.
// Re-throw the error after removing the failed wrap.
cleanup.RemoveWrap(callbackInfo);
throw e;
}
Expand Down