summaryrefslogtreecommitdiff
path: root/src/node_api_types.h
diff options
context:
space:
mode:
authorTaylor Woll <taylor.woll@microsoft.com>2017-03-24 01:26:09 -0700
committerAnna Henningsen <anna@addaleax.net>2017-04-10 23:30:03 +0200
commitca786c3734f6e23e34cd60f13e6bdaab033c5739 (patch)
tree9970670cdf28340cb262388e80ba4dd38d222255 /src/node_api_types.h
parentb470a85f071ccdde0e24b48a6fe8389b0a54750d (diff)
downloadandroid-node-v8-ca786c3734f6e23e34cd60f13e6bdaab033c5739.tar.gz
android-node-v8-ca786c3734f6e23e34cd60f13e6bdaab033c5739.tar.bz2
android-node-v8-ca786c3734f6e23e34cd60f13e6bdaab033c5739.zip
n-api: change napi_callback to return napi_value
Change `napi_callback` to return `napi_value` directly instead of requiring `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. Also add `test/addons-napi/common.h` to house some common macros for wrapping N-API calls and error handling. PR-URL: https://github.com/nodejs/node/pull/12248 Reviewed-By: Michael Dawson <michael_dawson@ca.ibm.com> Reviewed-By: Anna Henningsen <anna@addaleax.net>
Diffstat (limited to 'src/node_api_types.h')
-rw-r--r--src/node_api_types.h7
1 files changed, 5 insertions, 2 deletions
diff --git a/src/node_api_types.h b/src/node_api_types.h
index f3f3faaa64..f439cce1f9 100644
--- a/src/node_api_types.h
+++ b/src/node_api_types.h
@@ -17,8 +17,8 @@ typedef struct napi_handle_scope__ *napi_handle_scope;
typedef struct napi_escapable_handle_scope__ *napi_escapable_handle_scope;
typedef struct napi_callback_info__ *napi_callback_info;
-typedef void (*napi_callback)(napi_env env,
- napi_callback_info info);
+typedef napi_value (*napi_callback)(napi_env env,
+ napi_callback_info info);
typedef void (*napi_finalize)(napi_env env,
void* finalize_data,
void* finalize_hint);
@@ -35,7 +35,9 @@ typedef enum {
} napi_property_attributes;
typedef struct {
+ // One of utf8name or name should be NULL.
const char* utf8name;
+ napi_value name;
napi_callback method;
napi_callback getter;
@@ -76,6 +78,7 @@ typedef enum {
napi_invalid_arg,
napi_object_expected,
napi_string_expected,
+ napi_name_expected,
napi_function_expected,
napi_number_expected,
napi_boolean_expected,