11cb0ef41Sopenharmony_ci#define NAPI_VERSION 9 21cb0ef41Sopenharmony_ci// we define NODE_API_NO_EXTERNAL_BUFFERS_ALLOWED here to validate that it can 31cb0ef41Sopenharmony_ci// be used as a form of test itself. It is 41cb0ef41Sopenharmony_ci// not related to any of the other tests 51cb0ef41Sopenharmony_ci// defined in the file 61cb0ef41Sopenharmony_ci#define NODE_API_NO_EXTERNAL_BUFFERS_ALLOWED 71cb0ef41Sopenharmony_ci#include <node_api.h> 81cb0ef41Sopenharmony_ci#include <stdlib.h> 91cb0ef41Sopenharmony_ci#include "../../js-native-api/common.h" 101cb0ef41Sopenharmony_ci 111cb0ef41Sopenharmony_cistatic napi_value testGetNodeVersion(napi_env env, napi_callback_info info) { 121cb0ef41Sopenharmony_ci const napi_node_version* node_version; 131cb0ef41Sopenharmony_ci napi_value result, major, minor, patch, release; 141cb0ef41Sopenharmony_ci NODE_API_CALL(env, napi_get_node_version(env, &node_version)); 151cb0ef41Sopenharmony_ci NODE_API_CALL(env, napi_create_uint32(env, node_version->major, &major)); 161cb0ef41Sopenharmony_ci NODE_API_CALL(env, napi_create_uint32(env, node_version->minor, &minor)); 171cb0ef41Sopenharmony_ci NODE_API_CALL(env, napi_create_uint32(env, node_version->patch, &patch)); 181cb0ef41Sopenharmony_ci NODE_API_CALL(env, 191cb0ef41Sopenharmony_ci napi_create_string_utf8( 201cb0ef41Sopenharmony_ci env, node_version->release, NAPI_AUTO_LENGTH, &release)); 211cb0ef41Sopenharmony_ci NODE_API_CALL(env, napi_create_array_with_length(env, 4, &result)); 221cb0ef41Sopenharmony_ci NODE_API_CALL(env, napi_set_element(env, result, 0, major)); 231cb0ef41Sopenharmony_ci NODE_API_CALL(env, napi_set_element(env, result, 1, minor)); 241cb0ef41Sopenharmony_ci NODE_API_CALL(env, napi_set_element(env, result, 2, patch)); 251cb0ef41Sopenharmony_ci NODE_API_CALL(env, napi_set_element(env, result, 3, release)); 261cb0ef41Sopenharmony_ci return result; 271cb0ef41Sopenharmony_ci} 281cb0ef41Sopenharmony_ci 291cb0ef41Sopenharmony_cistatic napi_value GetFilename(napi_env env, napi_callback_info info) { 301cb0ef41Sopenharmony_ci const char* filename; 311cb0ef41Sopenharmony_ci napi_value result; 321cb0ef41Sopenharmony_ci 331cb0ef41Sopenharmony_ci NODE_API_CALL(env, node_api_get_module_file_name(env, &filename)); 341cb0ef41Sopenharmony_ci NODE_API_CALL(env, 351cb0ef41Sopenharmony_ci napi_create_string_utf8(env, filename, NAPI_AUTO_LENGTH, &result)); 361cb0ef41Sopenharmony_ci 371cb0ef41Sopenharmony_ci return result; 381cb0ef41Sopenharmony_ci} 391cb0ef41Sopenharmony_ci 401cb0ef41Sopenharmony_cistatic napi_value Init(napi_env env, napi_value exports) { 411cb0ef41Sopenharmony_ci napi_property_descriptor descriptors[] = { 421cb0ef41Sopenharmony_ci DECLARE_NODE_API_PROPERTY("testGetNodeVersion", testGetNodeVersion), 431cb0ef41Sopenharmony_ci DECLARE_NODE_API_GETTER("filename", GetFilename), 441cb0ef41Sopenharmony_ci }; 451cb0ef41Sopenharmony_ci 461cb0ef41Sopenharmony_ci NODE_API_CALL(env, napi_define_properties( 471cb0ef41Sopenharmony_ci env, exports, sizeof(descriptors) / sizeof(*descriptors), descriptors)); 481cb0ef41Sopenharmony_ci 491cb0ef41Sopenharmony_ci return exports; 501cb0ef41Sopenharmony_ci} 511cb0ef41Sopenharmony_ci 521cb0ef41Sopenharmony_ciNAPI_MODULE(NODE_GYP_MODULE_NAME, Init) 53