Skip to content
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

Change napi_callback to return napi_value instead of void #196

Conversation

boingoing
Copy link

Change napi_callback to return napi_value instead of requiring the callback to manually call napi_set_return_value.

When we invoke the callback, we will check the return value and call SetReturnValue ourselves. If the callback returns NULL, we don't set the return value in v8 which would have the same effect as previously if the callback didn't call napi_set_return_value. Seems to be a more natural way to handle return values from callbacks. As a consequence, remove napi_set_return_value.

Add a napi_value to napi_property_descriptor to support string values which couldn't be passed in the utf8name parameter or symbols as property names. Class names, however, cannot be symbols so this napi_value must be a string type in that case.

Remove all of the napi_callback_info helpers except for napi_get_cb_info and make all the parameters to napi_get_cb_info optional except for argc.

Update all the test collateral according to these changes.

@boingoing
Copy link
Author

@digitalinfinity @jasongin

Please take a look, I'll push a further commit to fix lint bugs found via CI.

@boingoing
Copy link
Author

jasongin

This comment was marked as off-topic.

jasongin

This comment was marked as off-topic.

@jasongin
Copy link
Member

all the parameters to napi_get_cb_info optional except for argc

Why isn't argc optional also? Maybe methods which don't expect (or ignore) any parameters shouldn't need to supply that.

@boingoing
Copy link
Author

This is a little disruptive, yes, waiting for the PR to land is probably fine. I don't want it to get stale, though, since there are so many invasive changes to the test code. Most of the change is in the test code, which is probably not getting as much attention over in the PR.

@boingoing
Copy link
Author

Why isn't argc optional also? Maybe methods which don't expect (or ignore) any parameters shouldn't need to supply that.

I thought about it but figured it didn't make sense because argc is both an in and an out parameter so it's required if argv is provided. That might be fine, though, to say if argv is provided that argc becomes non-optional.

jasongin

This comment was marked as off-topic.

@jasongin
Copy link
Member

argv is provided that argc becomes non-optional

Yes. While updating leveldown code I encountered several places where it would be more convenient to pass nullptr for both argc and argv.

…ng napi_set_return_value

When we invoke the callback, we will check the return value and call ```SetReturnValue``` ourselves. If the callback returns ```NULL```, we don't set the return value in v8 which would have the same effect as previously if the callback didn't call ```napi_set_return_value```. Seems to be a more natural way to handle return values from callbacks. As a consequence, remove ```napi_set_return_value```.

Add a ```napi_value``` to ```napi_property_descriptor``` to support string values which couldn't be passed in the ```utf8name``` parameter or symbols as property names. Class names, however, cannot be symbols so this ```napi_value``` must be a string type in that case.

Remove all of the ```napi_callback_info``` helpers except for ```napi_get_cb_info``` and make all the parameters to ```napi_get_cb_info``` optional except for argc.

Update all the test collateral according to these changes.
@boingoing
Copy link
Author

Another CI job after rebasing
https://ci.nodejs.org/job/node-test-commit-linux-abi/96/

@mhdawson
Copy link
Member

landed in main repo closing.

@mhdawson mhdawson closed this Apr 11, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants