-
-
Notifications
You must be signed in to change notification settings - Fork 498
fixes v8 GC access violation for zombie objects #638
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
Changes from 1 commit
7c59fab
beb4920
80d6607
41c7a89
253a9e1
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
…zombie state by exception in its constructor
- Loading branch information
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -3120,7 +3120,7 @@ inline ObjectWrap<T>::ObjectWrap(const Napi::CallbackInfo& callbackInfo) { | |||||||||||||||
| napi_status status; | ||||||||||||||||
| napi_ref ref; | ||||||||||||||||
| T* instance = static_cast<T*>(this); | ||||||||||||||||
| status = napi_wrap(env, wrapper, instance, FinalizeCallback, nullptr, &ref); | ||||||||||||||||
| status = napi_wrap(env, wrapper, instance, FinalizeCallback, (void*)callbackInfo.zombie, &ref); | ||||||||||||||||
| NAPI_THROW_IF_FAILED_VOID(env, status); | ||||||||||||||||
|
gabrielschulhof marked this conversation as resolved.
|
||||||||||||||||
|
|
||||||||||||||||
| Reference<Object>* instanceRef = instance; | ||||||||||||||||
|
|
@@ -3699,8 +3699,15 @@ inline napi_value ObjectWrap<T>::ConstructorCallbackWrapper( | |||||||||||||||
| T* instance; | ||||||||||||||||
| napi_value wrapper = details::WrapCallback([&] { | ||||||||||||||||
| CallbackInfo callbackInfo(env, info); | ||||||||||||||||
| instance = new T(callbackInfo); | ||||||||||||||||
| return callbackInfo.This(); | ||||||||||||||||
| callbackInfo.zombie = new Zombie(); | ||||||||||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||||
| try { | ||||||||||||||||
| instance = new T(callbackInfo); | ||||||||||||||||
| return callbackInfo.This(); | ||||||||||||||||
| } | ||||||||||||||||
| catch (...) { | ||||||||||||||||
| callbackInfo.zombie->isZombie = true; | ||||||||||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||||
| throw; | ||||||||||||||||
| } | ||||||||||||||||
| }); | ||||||||||||||||
|
|
||||||||||||||||
| return wrapper; | ||||||||||||||||
|
|
@@ -3823,7 +3830,16 @@ inline napi_value ObjectWrap<T>::InstanceSetterCallbackWrapper( | |||||||||||||||
| } | ||||||||||||||||
|
|
||||||||||||||||
| template <typename T> | ||||||||||||||||
| inline void ObjectWrap<T>::FinalizeCallback(napi_env env, void* data, void* /*hint*/) { | ||||||||||||||||
| inline void ObjectWrap<T>::FinalizeCallback(napi_env env, void* data, void* hint) { | ||||||||||||||||
| if (hint != nullptr) { | ||||||||||||||||
| Zombie* zombie = (Zombie*)hint; | ||||||||||||||||
| bool isZombie = zombie->isZombie; | ||||||||||||||||
| delete zombie; | ||||||||||||||||
| if (isZombie) { | ||||||||||||||||
| return; | ||||||||||||||||
| } | ||||||||||||||||
| } | ||||||||||||||||
|
|
||||||||||||||||
|
Comment on lines
-3826
to
+3882
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This becomes unnecessary. |
||||||||||||||||
| T* instance = reinterpret_cast<T*>(data); | ||||||||||||||||
| instance->Finalize(Napi::Env(env)); | ||||||||||||||||
| delete instance; | ||||||||||||||||
|
|
||||||||||||||||
| Original file line number | Diff line number | Diff line change | ||
|---|---|---|---|---|
|
|
@@ -1396,6 +1396,10 @@ namespace Napi { | |||
| RangeError(napi_env env, napi_value value); | ||||
| }; | ||||
|
|
||||
| struct Zombie { | ||||
| bool isZombie = false; | ||||
| }; | ||||
|
|
||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This becomes unnecessary. |
||||
| class CallbackInfo { | ||||
| public: | ||||
| CallbackInfo(napi_env env, napi_callback_info info); | ||||
|
|
@@ -1414,6 +1418,8 @@ namespace Napi { | |||
| void* Data() const; | ||||
| void SetData(void* data); | ||||
|
|
||||
| Zombie* zombie; | ||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
Let's not expose more public fields. We can do a ping-pong with |
||||
|
|
||||
| private: | ||||
| const size_t _staticArgCount = 6; | ||||
| napi_env _env; | ||||
|
|
||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can declare
in the private section of
ObjectWrap<T>.