133eb0b6dSopenharmony_ci/* 233eb0b6dSopenharmony_ci * Copyright (c) 2021 Huawei Device Co., Ltd. 333eb0b6dSopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License"); 433eb0b6dSopenharmony_ci * you may not use this file except in compliance with the License. 533eb0b6dSopenharmony_ci * You may obtain a copy of the License at 633eb0b6dSopenharmony_ci * 733eb0b6dSopenharmony_ci * http://www.apache.org/licenses/LICENSE-2.0 833eb0b6dSopenharmony_ci * 933eb0b6dSopenharmony_ci * Unless required by applicable law or agreed to in writing, software 1033eb0b6dSopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS, 1133eb0b6dSopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 1233eb0b6dSopenharmony_ci * See the License for the specific language governing permissions and 1333eb0b6dSopenharmony_ci * limitations under the License. 1433eb0b6dSopenharmony_ci */ 1533eb0b6dSopenharmony_ci 1633eb0b6dSopenharmony_ci#include <string> 1733eb0b6dSopenharmony_ci 1833eb0b6dSopenharmony_ci#include "napi/native_api.h" 1933eb0b6dSopenharmony_ci#include "napi/native_common.h" 2033eb0b6dSopenharmony_ci 2133eb0b6dSopenharmony_cienum TestEnum { 2233eb0b6dSopenharmony_ci ONE = 1, 2333eb0b6dSopenharmony_ci TWO, 2433eb0b6dSopenharmony_ci THREE, 2533eb0b6dSopenharmony_ci FOUR 2633eb0b6dSopenharmony_ci}; 2733eb0b6dSopenharmony_ci 2833eb0b6dSopenharmony_ci/* 2933eb0b6dSopenharmony_ci * Constructor 3033eb0b6dSopenharmony_ci */ 3133eb0b6dSopenharmony_cistatic napi_value NumberConstructor(napi_env env, napi_callback_info info) 3233eb0b6dSopenharmony_ci{ 3333eb0b6dSopenharmony_ci napi_value thisArg = nullptr; 3433eb0b6dSopenharmony_ci void* data = nullptr; 3533eb0b6dSopenharmony_ci napi_get_cb_info(env, info, nullptr, nullptr, &thisArg, &data); 3633eb0b6dSopenharmony_ci // Do nothing 3733eb0b6dSopenharmony_ci return thisArg; 3833eb0b6dSopenharmony_ci} 3933eb0b6dSopenharmony_ci 4033eb0b6dSopenharmony_cistatic napi_value Export(napi_env env, napi_value exports) 4133eb0b6dSopenharmony_ci{ 4233eb0b6dSopenharmony_ci napi_value one = nullptr; 4333eb0b6dSopenharmony_ci napi_value two = nullptr; 4433eb0b6dSopenharmony_ci napi_value three = nullptr; 4533eb0b6dSopenharmony_ci napi_value four = nullptr; 4633eb0b6dSopenharmony_ci 4733eb0b6dSopenharmony_ci napi_create_int32(env, TestEnum::ONE, &one); 4833eb0b6dSopenharmony_ci napi_create_int32(env, TestEnum::TWO, &two); 4933eb0b6dSopenharmony_ci napi_create_int32(env, TestEnum::THREE, &three); 5033eb0b6dSopenharmony_ci napi_create_int32(env, TestEnum::FOUR, &four); 5133eb0b6dSopenharmony_ci 5233eb0b6dSopenharmony_ci napi_property_descriptor descriptors[] = { 5333eb0b6dSopenharmony_ci DECLARE_NAPI_STATIC_PROPERTY("ONE", one), 5433eb0b6dSopenharmony_ci DECLARE_NAPI_STATIC_PROPERTY("TWO", two), 5533eb0b6dSopenharmony_ci DECLARE_NAPI_STATIC_PROPERTY("THREE", three), 5633eb0b6dSopenharmony_ci DECLARE_NAPI_STATIC_PROPERTY("FOUR", four), 5733eb0b6dSopenharmony_ci }; 5833eb0b6dSopenharmony_ci 5933eb0b6dSopenharmony_ci napi_value result = nullptr; 6033eb0b6dSopenharmony_ci napi_define_class(env, "Number", NAPI_AUTO_LENGTH, NumberConstructor, nullptr, 6133eb0b6dSopenharmony_ci sizeof(descriptors) / sizeof(*descriptors), descriptors, &result); 6233eb0b6dSopenharmony_ci 6333eb0b6dSopenharmony_ci napi_set_named_property(env, exports, "Number", result); 6433eb0b6dSopenharmony_ci return exports; 6533eb0b6dSopenharmony_ci} 6633eb0b6dSopenharmony_ci 6733eb0b6dSopenharmony_cistatic napi_module numberModule = { 6833eb0b6dSopenharmony_ci .nm_version = 1, 6933eb0b6dSopenharmony_ci .nm_flags = 0, 7033eb0b6dSopenharmony_ci .nm_filename = nullptr, 7133eb0b6dSopenharmony_ci .nm_register_func = Export, 7233eb0b6dSopenharmony_ci .nm_modname = "number", 7333eb0b6dSopenharmony_ci .nm_priv = ((void*)0), 7433eb0b6dSopenharmony_ci .reserved = { 0 }, 7533eb0b6dSopenharmony_ci}; 7633eb0b6dSopenharmony_ci 7733eb0b6dSopenharmony_ciextern "C" __attribute__((constructor)) void NumberRegister() 7833eb0b6dSopenharmony_ci{ 7933eb0b6dSopenharmony_ci napi_module_register(&numberModule); 8033eb0b6dSopenharmony_ci} 81