11cb0ef41Sopenharmony_ci#include <js_native_api.h> 21cb0ef41Sopenharmony_ci 31cb0ef41Sopenharmony_ci#include "../common.h" 41cb0ef41Sopenharmony_ci 51cb0ef41Sopenharmony_ci// Unifies the way the macros declare values. 61cb0ef41Sopenharmony_citypedef double double_t; 71cb0ef41Sopenharmony_ci 81cb0ef41Sopenharmony_ci#define BINDING_FOR_CREATE(initial_capital, lowercase) \ 91cb0ef41Sopenharmony_ci static napi_value Create##initial_capital(napi_env env, \ 101cb0ef41Sopenharmony_ci napi_callback_info info) { \ 111cb0ef41Sopenharmony_ci napi_value return_value, call_result; \ 121cb0ef41Sopenharmony_ci lowercase##_t value = 42; \ 131cb0ef41Sopenharmony_ci NODE_API_CALL(env, napi_create_object(env, &return_value)); \ 141cb0ef41Sopenharmony_ci add_returned_status(env, \ 151cb0ef41Sopenharmony_ci "envIsNull", \ 161cb0ef41Sopenharmony_ci return_value, \ 171cb0ef41Sopenharmony_ci "Invalid argument", \ 181cb0ef41Sopenharmony_ci napi_invalid_arg, \ 191cb0ef41Sopenharmony_ci napi_create_##lowercase(NULL, value, &call_result)); \ 201cb0ef41Sopenharmony_ci napi_create_##lowercase(env, value, NULL); \ 211cb0ef41Sopenharmony_ci add_last_status(env, "resultIsNull", return_value); \ 221cb0ef41Sopenharmony_ci return return_value; \ 231cb0ef41Sopenharmony_ci } 241cb0ef41Sopenharmony_ci 251cb0ef41Sopenharmony_ci#define BINDING_FOR_GET_VALUE(initial_capital, lowercase) \ 261cb0ef41Sopenharmony_ci static napi_value GetValue##initial_capital(napi_env env, \ 271cb0ef41Sopenharmony_ci napi_callback_info info) { \ 281cb0ef41Sopenharmony_ci napi_value return_value, call_result; \ 291cb0ef41Sopenharmony_ci lowercase##_t value = 42; \ 301cb0ef41Sopenharmony_ci NODE_API_CALL(env, napi_create_object(env, &return_value)); \ 311cb0ef41Sopenharmony_ci NODE_API_CALL(env, napi_create_##lowercase(env, value, &call_result)); \ 321cb0ef41Sopenharmony_ci add_returned_status( \ 331cb0ef41Sopenharmony_ci env, \ 341cb0ef41Sopenharmony_ci "envIsNull", \ 351cb0ef41Sopenharmony_ci return_value, \ 361cb0ef41Sopenharmony_ci "Invalid argument", \ 371cb0ef41Sopenharmony_ci napi_invalid_arg, \ 381cb0ef41Sopenharmony_ci napi_get_value_##lowercase(NULL, call_result, &value)); \ 391cb0ef41Sopenharmony_ci napi_get_value_##lowercase(env, NULL, &value); \ 401cb0ef41Sopenharmony_ci add_last_status(env, "valueIsNull", return_value); \ 411cb0ef41Sopenharmony_ci napi_get_value_##lowercase(env, call_result, NULL); \ 421cb0ef41Sopenharmony_ci add_last_status(env, "resultIsNull", return_value); \ 431cb0ef41Sopenharmony_ci return return_value; \ 441cb0ef41Sopenharmony_ci } 451cb0ef41Sopenharmony_ci 461cb0ef41Sopenharmony_ciBINDING_FOR_CREATE(Double, double) 471cb0ef41Sopenharmony_ciBINDING_FOR_CREATE(Int32, int32) 481cb0ef41Sopenharmony_ciBINDING_FOR_CREATE(Uint32, uint32) 491cb0ef41Sopenharmony_ciBINDING_FOR_CREATE(Int64, int64) 501cb0ef41Sopenharmony_ciBINDING_FOR_GET_VALUE(Double, double) 511cb0ef41Sopenharmony_ciBINDING_FOR_GET_VALUE(Int32, int32) 521cb0ef41Sopenharmony_ciBINDING_FOR_GET_VALUE(Uint32, uint32) 531cb0ef41Sopenharmony_ciBINDING_FOR_GET_VALUE(Int64, int64) 541cb0ef41Sopenharmony_ci 551cb0ef41Sopenharmony_civoid init_test_null(napi_env env, napi_value exports) { 561cb0ef41Sopenharmony_ci const napi_property_descriptor test_null_props[] = { 571cb0ef41Sopenharmony_ci DECLARE_NODE_API_PROPERTY("createDouble", CreateDouble), 581cb0ef41Sopenharmony_ci DECLARE_NODE_API_PROPERTY("createInt32", CreateInt32), 591cb0ef41Sopenharmony_ci DECLARE_NODE_API_PROPERTY("createUint32", CreateUint32), 601cb0ef41Sopenharmony_ci DECLARE_NODE_API_PROPERTY("createInt64", CreateInt64), 611cb0ef41Sopenharmony_ci DECLARE_NODE_API_PROPERTY("getValueDouble", GetValueDouble), 621cb0ef41Sopenharmony_ci DECLARE_NODE_API_PROPERTY("getValueInt32", GetValueInt32), 631cb0ef41Sopenharmony_ci DECLARE_NODE_API_PROPERTY("getValueUint32", GetValueUint32), 641cb0ef41Sopenharmony_ci DECLARE_NODE_API_PROPERTY("getValueInt64", GetValueInt64), 651cb0ef41Sopenharmony_ci }; 661cb0ef41Sopenharmony_ci napi_value test_null; 671cb0ef41Sopenharmony_ci 681cb0ef41Sopenharmony_ci NODE_API_CALL_RETURN_VOID(env, napi_create_object(env, &test_null)); 691cb0ef41Sopenharmony_ci NODE_API_CALL_RETURN_VOID( 701cb0ef41Sopenharmony_ci env, 711cb0ef41Sopenharmony_ci napi_define_properties(env, 721cb0ef41Sopenharmony_ci test_null, 731cb0ef41Sopenharmony_ci sizeof(test_null_props) / sizeof(*test_null_props), 741cb0ef41Sopenharmony_ci test_null_props)); 751cb0ef41Sopenharmony_ci NODE_API_CALL_RETURN_VOID( 761cb0ef41Sopenharmony_ci env, napi_set_named_property(env, exports, "testNull", test_null)); 771cb0ef41Sopenharmony_ci} 78