Fix TODOs to address memory leaks#343
Conversation
d65616c to
96665dd
Compare
|
Finally, I chose to attach the data by creating a property whose key is an anonymous symbol and whose value is an external containing the data. This leaves the |
|
Testing to make sure that the finalizer gets called could be done using assertions made about the output of a coverage tool. Basically, we have to make sure that the line where the data gets deleted gets hit a certain number of times in response to the I manually verified this by adding an To test this on the CI, we need a code coverage build followed by a code coverage run, followed by parsing of the code coverage output so we can make assertions about when the finalizer gets called. |
c55522e to
3aac9eb
Compare
3b36403 to
d7143a5
Compare
|
@mhdawson I've added back the deprecated stuff such that it's behind the new build flag |
a5e4e04 to
791d161
Compare
|
@mhdawson I had forgotten to update the PR to update the documentation. That's done now. |
791d161 to
7f0a628
Compare
| 'dependencies': ["<!(node -p \"require('../').gyp\")"], | ||
| 'cflags': [ '-Werror', '-Wall', '-Wextra', '-Wpedantic', '-Wunused-parameter' ], | ||
| 'cflags_cc': [ '-Werror', '-Wall', '-Wextra', '-Wpedantic', '-Wunused-parameter' ], | ||
| 'defines': ['NODE_ADDON_API_DISABLE_DEPRECATED'] |
There was a problem hiding this comment.
Does this mean we won't test the deprecated functions?
There was a problem hiding this comment.
Yes, it does mean that.
|
@gabrielschulhof this is big enough it would probably be good to spend a few minutes together going through it. Maybe after the N-API meeting on Thursday. |
| // After defining the class we iterate once more over the property descriptors | ||
| // and attach the data associated with accessors and instance methods to the | ||
| // newly created JavaScript class. | ||
| for (size_t idx = 0; idx < props_count; idx++) { |
There was a problem hiding this comment.
@mhdawson I realized that it's OK to always attach this data to the JS class. We do not need to afterwards retrieve the instance method and attach the data to it, because we do not need to worry about the scenario where someone "detaches" an instance method from the class' .prototype property. The reason we do not need to worry is that in our implementation of instance methods, we attempt to napi_unwrap() the this parameter in order to retrieve the instance of the native class, so we can then call the corresponding instance method on the native instance. Since the JavaScript class is garbage-collected, no new JavaScript instances can be created, and so no JavaScript objects can arrive via the this property that will successfully napi_unwrap() to give us the native instance. This fails nicely with a napi_object_expected or a napi_invalid_arg status that gets propagated back into JavaScript as an exception.
Coverage can be skipped by adding --disable-deprecated to the npm command line.
66f9586 to
b2a76ab
Compare
| PropertyDescriptor::Function(str7, TestFunction), | ||
| #else // NODE_ADDON_API_DISABLE_DEPRECATED | ||
| PropertyDescriptor::Function(env, str7, TestFunction), | ||
| #endif // !NODE_ADDON_API_DISABLE_DEPRECATED |
There was a problem hiding this comment.
I think we want to test both the deprecated and non-deprecated so this should just be #ifndef, #endif as opposed to using #else ? Same goes to all of the other places as well.
|
@mhdawson I split the deprecated tests into their own test at |
bdf90ad to
dcb33cd
Compare
|
Looks good other than the comment about testing should test both deprecated and non-deprecated versions as opposed to one or the other. Looks like all of the other issues we discussed in person are addressed and I'll sign of land once the test ifdefs are fixed up. |
|
@mhdawson I fixed that. Now, when you run |
|
Landed as 917bd60 |
PR-URL: nodejs/node-addon-api#343 Fixes: nodejs/node-addon-api#333 Reviewed-By: Michael Dawson <michael_dawson@ca.ibm.com>
PR-URL: nodejs/node-addon-api#343 Fixes: nodejs/node-addon-api#333 Reviewed-By: Michael Dawson <michael_dawson@ca.ibm.com>
PR-URL: nodejs/node-addon-api#343 Fixes: nodejs/node-addon-api#333 Reviewed-By: Michael Dawson <michael_dawson@ca.ibm.com>
PR-URL: nodejs/node-addon-api#343 Fixes: nodejs/node-addon-api#333 Reviewed-By: Michael Dawson <michael_dawson@ca.ibm.com>
Fixes: #333