napi: change napi_callback to return napi_value
Change napi_callback
to return napi_value
directly instead of
requiring module code to 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. If argv
is provided, argc
will become non-optional.
Update all the test collateral according to these changes. Also add
test/addons-napi/common.h
to house some common macros for wrapping
N-API calls and error handling.
Checklist
-
make -j4 test
(UNIX), orvcbuild test
(Windows) passes -
tests and/or benchmarks are included -
commit message follows commit guidelines
Affected core subsystem(s)
napi