summaryrefslogtreecommitdiff
path: root/test/addons-napi/test_properties/test_properties.c
diff options
context:
space:
mode:
Diffstat (limited to 'test/addons-napi/test_properties/test_properties.c')
-rw-r--r--test/addons-napi/test_properties/test_properties.c91
1 files changed, 31 insertions, 60 deletions
diff --git a/test/addons-napi/test_properties/test_properties.c b/test/addons-napi/test_properties/test_properties.c
index de6b39ba02..67e6b1a0d5 100644
--- a/test/addons-napi/test_properties/test_properties.c
+++ b/test/addons-napi/test_properties/test_properties.c
@@ -1,88 +1,59 @@
#include <node_api.h>
+#include "../common.h"
static double value_ = 1;
-void GetValue(napi_env env, napi_callback_info info) {
- napi_status status;
+napi_value GetValue(napi_env env, napi_callback_info info) {
+ size_t argc = 0;
+ NAPI_CALL(env, napi_get_cb_info(env, info, &argc, NULL, NULL, NULL));
- size_t argc;
- status = napi_get_cb_args_length(env, info, &argc);
- if (status != napi_ok) return;
-
- if (argc != 0) {
- napi_throw_type_error(env, "Wrong number of arguments");
- return;
- }
+ NAPI_ASSERT(env, argc == 0, "Wrong number of arguments");
napi_value number;
- status = napi_create_number(env, value_, &number);
- if (status != napi_ok) return;
+ NAPI_CALL(env, napi_create_number(env, value_, &number));
- status = napi_set_return_value(env, info, number);
- if (status != napi_ok) return;
+ return number;
}
-void SetValue(napi_env env, napi_callback_info info) {
- napi_status status;
-
- size_t argc;
- status = napi_get_cb_args_length(env, info, &argc);
- if (status != napi_ok) return;
+napi_value SetValue(napi_env env, napi_callback_info info) {
+ size_t argc = 1;
+ napi_value args[1];
+ NAPI_CALL(env, napi_get_cb_info(env, info, &argc, args, NULL, NULL));
- if (argc != 1) {
- napi_throw_type_error(env, "Wrong number of arguments");
- return;
- }
+ NAPI_ASSERT(env, argc == 1, "Wrong number of arguments");
- napi_value arg;
- status = napi_get_cb_args(env, info, &arg, 1);
- if (status != napi_ok) return;
+ NAPI_CALL(env, napi_get_value_double(env, args[0], &value_));
- status = napi_get_value_double(env, arg, &value_);
- if (status != napi_ok) return;
+ return NULL;
}
-void Echo(napi_env env, napi_callback_info info) {
- napi_status status;
-
- size_t argc;
- status = napi_get_cb_args_length(env, info, &argc);
- if (status != napi_ok) return;
+napi_value Echo(napi_env env, napi_callback_info info) {
+ size_t argc = 1;
+ napi_value args[1];
+ NAPI_CALL(env, napi_get_cb_info(env, info, &argc, args, NULL, NULL));
- if (argc != 1) {
- napi_throw_type_error(env, "Wrong number of arguments");
- return;
- }
+ NAPI_ASSERT(env, argc == 1, "Wrong number of arguments");
- napi_value arg;
- status = napi_get_cb_args(env, info, &arg, 1);
- if (status != napi_ok) return;
-
- status = napi_set_return_value(env, info, arg);
- if (status != napi_ok) return;
+ return args[0];
}
void Init(napi_env env, napi_value exports, napi_value module, void* priv) {
- napi_status status;
-
napi_value number;
- status = napi_create_number(env, value_, &number);
- if (status != napi_ok) return;
+ NAPI_CALL_RETURN_VOID(env, napi_create_number(env, value_, &number));
napi_property_descriptor properties[] = {
- { "echo", Echo, 0, 0, 0, napi_enumerable, 0 },
- { "readwriteValue", 0, 0, 0, number, napi_enumerable | napi_writable, 0 },
- { "readonlyValue", 0, 0, 0, number, napi_enumerable, 0},
- { "hiddenValue", 0, 0, 0, number, napi_default, 0},
- { "readwriteAccessor1", 0, GetValue, SetValue, 0, napi_default, 0},
- { "readwriteAccessor2", 0, GetValue, SetValue, 0, napi_writable, 0},
- { "readonlyAccessor1", 0, GetValue, NULL, 0, napi_default, 0},
- { "readonlyAccessor2", 0, GetValue, NULL, 0, napi_writable, 0},
+ { "echo", 0, Echo, 0, 0, 0, napi_enumerable, 0 },
+ { "readwriteValue", 0, 0, 0, 0, number, napi_enumerable | napi_writable, 0 },
+ { "readonlyValue", 0, 0, 0, 0, number, napi_enumerable, 0},
+ { "hiddenValue", 0, 0, 0, 0, number, napi_default, 0},
+ { "readwriteAccessor1", 0, 0, GetValue, SetValue, 0, napi_default, 0},
+ { "readwriteAccessor2", 0, 0, GetValue, SetValue, 0, napi_writable, 0},
+ { "readonlyAccessor1", 0, 0, GetValue, NULL, 0, napi_default, 0},
+ { "readonlyAccessor2", 0, 0, GetValue, NULL, 0, napi_writable, 0},
};
- status = napi_define_properties(
- env, exports, sizeof(properties) / sizeof(*properties), properties);
- if (status != napi_ok) return;
+ NAPI_CALL_RETURN_VOID(env, napi_define_properties(
+ env, exports, sizeof(properties) / sizeof(*properties), properties));
}
NAPI_MODULE(addon, Init)