-
Notifications
You must be signed in to change notification settings - Fork 504
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
Pass Holder instead of This to ObjectWrap::Unwrap #524
Conversation
On Node 0.10.40, the test case will now fail with SIGABRT due to a failed assertion: node: ../../nan_object_wrap.h:33: static T* Nan::ObjectWrap::Unwrap(v8::Local<v8::Object>) [with T = MyObject]: Assertion `object->InternalFieldCount() > 0' failed. This is because This is not an instance of the type in question. Node >=0.12 seem to report a TypeError: Illegal invocation instead.
This is neccessary on Node 0.10.40 at least, where the Signature is not sufficient to ensure that This is actually an instance created from the instance template of this ObjectWrap-derived class.
To ensure that the Holder of an accessor is indeed an instance of the corret type, we can't attach the holders to the prototype but have to attach them to the object itself.
I know there is a difference between So, I'm happy with the added test case and the fix to make it pass, but I am unsure about all of the other changes. |
Nah, this PR also changes documentation. More so since my latest commit. The rest of the changes are just for the sake of consistency, but without these I hadn't spotted the issue about accessors which I had to address to make the whole test suite pass again, and which I included in my doc changes. |
I wonder whether |
Doesn't Anyway, I think that documentation update was worth the price of the rest of the changes, so I'm happy to merge this. |
|
IIRC it is explicitly built with |
Pass Holder instead of This to ObjectWrap::Unwrap
This is after reading Christian 'Little Jim' Plesner's answer to “What is the difference between Arguments::Holder() and Arguments::This()?” in the context of my Stack Overflow question “This vs. Holder for ObjectWrap::Unwrap”. Without the fix in my second commit, the test case from my first commit can lead to a failed assertion on Node 0.10. The change is also in line with the
node::ObjectWrap
documentation.