11cb0ef41Sopenharmony_ci#include <js_native_api.h> 21cb0ef41Sopenharmony_ci#include "../common.h" 31cb0ef41Sopenharmony_ci#include "../entry_point.h" 41cb0ef41Sopenharmony_ci#include "test_null.h" 51cb0ef41Sopenharmony_ci 61cb0ef41Sopenharmony_cistatic napi_value AsBool(napi_env env, napi_callback_info info) { 71cb0ef41Sopenharmony_ci size_t argc = 1; 81cb0ef41Sopenharmony_ci napi_value args[1]; 91cb0ef41Sopenharmony_ci NODE_API_CALL(env, napi_get_cb_info(env, info, &argc, args, NULL, NULL)); 101cb0ef41Sopenharmony_ci 111cb0ef41Sopenharmony_ci bool value; 121cb0ef41Sopenharmony_ci NODE_API_CALL(env, napi_get_value_bool(env, args[0], &value)); 131cb0ef41Sopenharmony_ci 141cb0ef41Sopenharmony_ci napi_value output; 151cb0ef41Sopenharmony_ci NODE_API_CALL(env, napi_get_boolean(env, value, &output)); 161cb0ef41Sopenharmony_ci 171cb0ef41Sopenharmony_ci return output; 181cb0ef41Sopenharmony_ci} 191cb0ef41Sopenharmony_ci 201cb0ef41Sopenharmony_cistatic napi_value AsInt32(napi_env env, napi_callback_info info) { 211cb0ef41Sopenharmony_ci size_t argc = 1; 221cb0ef41Sopenharmony_ci napi_value args[1]; 231cb0ef41Sopenharmony_ci NODE_API_CALL(env, napi_get_cb_info(env, info, &argc, args, NULL, NULL)); 241cb0ef41Sopenharmony_ci 251cb0ef41Sopenharmony_ci int32_t value; 261cb0ef41Sopenharmony_ci NODE_API_CALL(env, napi_get_value_int32(env, args[0], &value)); 271cb0ef41Sopenharmony_ci 281cb0ef41Sopenharmony_ci napi_value output; 291cb0ef41Sopenharmony_ci NODE_API_CALL(env, napi_create_int32(env, value, &output)); 301cb0ef41Sopenharmony_ci 311cb0ef41Sopenharmony_ci return output; 321cb0ef41Sopenharmony_ci} 331cb0ef41Sopenharmony_ci 341cb0ef41Sopenharmony_cistatic napi_value AsUInt32(napi_env env, napi_callback_info info) { 351cb0ef41Sopenharmony_ci size_t argc = 1; 361cb0ef41Sopenharmony_ci napi_value args[1]; 371cb0ef41Sopenharmony_ci NODE_API_CALL(env, napi_get_cb_info(env, info, &argc, args, NULL, NULL)); 381cb0ef41Sopenharmony_ci 391cb0ef41Sopenharmony_ci uint32_t value; 401cb0ef41Sopenharmony_ci NODE_API_CALL(env, napi_get_value_uint32(env, args[0], &value)); 411cb0ef41Sopenharmony_ci 421cb0ef41Sopenharmony_ci napi_value output; 431cb0ef41Sopenharmony_ci NODE_API_CALL(env, napi_create_uint32(env, value, &output)); 441cb0ef41Sopenharmony_ci 451cb0ef41Sopenharmony_ci return output; 461cb0ef41Sopenharmony_ci} 471cb0ef41Sopenharmony_ci 481cb0ef41Sopenharmony_cistatic napi_value AsInt64(napi_env env, napi_callback_info info) { 491cb0ef41Sopenharmony_ci size_t argc = 1; 501cb0ef41Sopenharmony_ci napi_value args[1]; 511cb0ef41Sopenharmony_ci NODE_API_CALL(env, napi_get_cb_info(env, info, &argc, args, NULL, NULL)); 521cb0ef41Sopenharmony_ci 531cb0ef41Sopenharmony_ci int64_t value; 541cb0ef41Sopenharmony_ci NODE_API_CALL(env, napi_get_value_int64(env, args[0], &value)); 551cb0ef41Sopenharmony_ci 561cb0ef41Sopenharmony_ci napi_value output; 571cb0ef41Sopenharmony_ci NODE_API_CALL(env, napi_create_int64(env, (double)value, &output)); 581cb0ef41Sopenharmony_ci 591cb0ef41Sopenharmony_ci return output; 601cb0ef41Sopenharmony_ci} 611cb0ef41Sopenharmony_ci 621cb0ef41Sopenharmony_cistatic napi_value AsDouble(napi_env env, napi_callback_info info) { 631cb0ef41Sopenharmony_ci size_t argc = 1; 641cb0ef41Sopenharmony_ci napi_value args[1]; 651cb0ef41Sopenharmony_ci NODE_API_CALL(env, napi_get_cb_info(env, info, &argc, args, NULL, NULL)); 661cb0ef41Sopenharmony_ci 671cb0ef41Sopenharmony_ci double value; 681cb0ef41Sopenharmony_ci NODE_API_CALL(env, napi_get_value_double(env, args[0], &value)); 691cb0ef41Sopenharmony_ci 701cb0ef41Sopenharmony_ci napi_value output; 711cb0ef41Sopenharmony_ci NODE_API_CALL(env, napi_create_double(env, value, &output)); 721cb0ef41Sopenharmony_ci 731cb0ef41Sopenharmony_ci return output; 741cb0ef41Sopenharmony_ci} 751cb0ef41Sopenharmony_ci 761cb0ef41Sopenharmony_cistatic napi_value AsString(napi_env env, napi_callback_info info) { 771cb0ef41Sopenharmony_ci size_t argc = 1; 781cb0ef41Sopenharmony_ci napi_value args[1]; 791cb0ef41Sopenharmony_ci NODE_API_CALL(env, napi_get_cb_info(env, info, &argc, args, NULL, NULL)); 801cb0ef41Sopenharmony_ci 811cb0ef41Sopenharmony_ci char value[100]; 821cb0ef41Sopenharmony_ci NODE_API_CALL(env, 831cb0ef41Sopenharmony_ci napi_get_value_string_utf8(env, args[0], value, sizeof(value), NULL)); 841cb0ef41Sopenharmony_ci 851cb0ef41Sopenharmony_ci napi_value output; 861cb0ef41Sopenharmony_ci NODE_API_CALL(env, napi_create_string_utf8( 871cb0ef41Sopenharmony_ci env, value, NAPI_AUTO_LENGTH, &output)); 881cb0ef41Sopenharmony_ci 891cb0ef41Sopenharmony_ci return output; 901cb0ef41Sopenharmony_ci} 911cb0ef41Sopenharmony_ci 921cb0ef41Sopenharmony_cistatic napi_value ToBool(napi_env env, napi_callback_info info) { 931cb0ef41Sopenharmony_ci size_t argc = 1; 941cb0ef41Sopenharmony_ci napi_value args[1]; 951cb0ef41Sopenharmony_ci NODE_API_CALL(env, napi_get_cb_info(env, info, &argc, args, NULL, NULL)); 961cb0ef41Sopenharmony_ci 971cb0ef41Sopenharmony_ci napi_value output; 981cb0ef41Sopenharmony_ci NODE_API_CALL(env, napi_coerce_to_bool(env, args[0], &output)); 991cb0ef41Sopenharmony_ci 1001cb0ef41Sopenharmony_ci return output; 1011cb0ef41Sopenharmony_ci} 1021cb0ef41Sopenharmony_ci 1031cb0ef41Sopenharmony_cistatic napi_value ToNumber(napi_env env, napi_callback_info info) { 1041cb0ef41Sopenharmony_ci size_t argc = 1; 1051cb0ef41Sopenharmony_ci napi_value args[1]; 1061cb0ef41Sopenharmony_ci NODE_API_CALL(env, napi_get_cb_info(env, info, &argc, args, NULL, NULL)); 1071cb0ef41Sopenharmony_ci 1081cb0ef41Sopenharmony_ci napi_value output; 1091cb0ef41Sopenharmony_ci NODE_API_CALL(env, napi_coerce_to_number(env, args[0], &output)); 1101cb0ef41Sopenharmony_ci 1111cb0ef41Sopenharmony_ci return output; 1121cb0ef41Sopenharmony_ci} 1131cb0ef41Sopenharmony_ci 1141cb0ef41Sopenharmony_cistatic napi_value ToObject(napi_env env, napi_callback_info info) { 1151cb0ef41Sopenharmony_ci size_t argc = 1; 1161cb0ef41Sopenharmony_ci napi_value args[1]; 1171cb0ef41Sopenharmony_ci NODE_API_CALL(env, napi_get_cb_info(env, info, &argc, args, NULL, NULL)); 1181cb0ef41Sopenharmony_ci 1191cb0ef41Sopenharmony_ci napi_value output; 1201cb0ef41Sopenharmony_ci NODE_API_CALL(env, napi_coerce_to_object(env, args[0], &output)); 1211cb0ef41Sopenharmony_ci 1221cb0ef41Sopenharmony_ci return output; 1231cb0ef41Sopenharmony_ci} 1241cb0ef41Sopenharmony_ci 1251cb0ef41Sopenharmony_cistatic napi_value ToString(napi_env env, napi_callback_info info) { 1261cb0ef41Sopenharmony_ci size_t argc = 1; 1271cb0ef41Sopenharmony_ci napi_value args[1]; 1281cb0ef41Sopenharmony_ci NODE_API_CALL(env, napi_get_cb_info(env, info, &argc, args, NULL, NULL)); 1291cb0ef41Sopenharmony_ci 1301cb0ef41Sopenharmony_ci napi_value output; 1311cb0ef41Sopenharmony_ci NODE_API_CALL(env, napi_coerce_to_string(env, args[0], &output)); 1321cb0ef41Sopenharmony_ci 1331cb0ef41Sopenharmony_ci return output; 1341cb0ef41Sopenharmony_ci} 1351cb0ef41Sopenharmony_ci 1361cb0ef41Sopenharmony_ciEXTERN_C_START 1371cb0ef41Sopenharmony_cinapi_value Init(napi_env env, napi_value exports) { 1381cb0ef41Sopenharmony_ci napi_property_descriptor descriptors[] = { 1391cb0ef41Sopenharmony_ci DECLARE_NODE_API_PROPERTY("asBool", AsBool), 1401cb0ef41Sopenharmony_ci DECLARE_NODE_API_PROPERTY("asInt32", AsInt32), 1411cb0ef41Sopenharmony_ci DECLARE_NODE_API_PROPERTY("asUInt32", AsUInt32), 1421cb0ef41Sopenharmony_ci DECLARE_NODE_API_PROPERTY("asInt64", AsInt64), 1431cb0ef41Sopenharmony_ci DECLARE_NODE_API_PROPERTY("asDouble", AsDouble), 1441cb0ef41Sopenharmony_ci DECLARE_NODE_API_PROPERTY("asString", AsString), 1451cb0ef41Sopenharmony_ci DECLARE_NODE_API_PROPERTY("toBool", ToBool), 1461cb0ef41Sopenharmony_ci DECLARE_NODE_API_PROPERTY("toNumber", ToNumber), 1471cb0ef41Sopenharmony_ci DECLARE_NODE_API_PROPERTY("toObject", ToObject), 1481cb0ef41Sopenharmony_ci DECLARE_NODE_API_PROPERTY("toString", ToString), 1491cb0ef41Sopenharmony_ci }; 1501cb0ef41Sopenharmony_ci 1511cb0ef41Sopenharmony_ci NODE_API_CALL(env, napi_define_properties( 1521cb0ef41Sopenharmony_ci env, exports, sizeof(descriptors) / sizeof(*descriptors), descriptors)); 1531cb0ef41Sopenharmony_ci 1541cb0ef41Sopenharmony_ci init_test_null(env, exports); 1551cb0ef41Sopenharmony_ci 1561cb0ef41Sopenharmony_ci return exports; 1571cb0ef41Sopenharmony_ci} 1581cb0ef41Sopenharmony_ciEXTERN_C_END 159