diff --git a/ets2panda/bindings/native/CMakeLists.txt b/ets2panda/bindings/native/CMakeLists.txt index 60dcbb51deb07e07eb70997d893412ccc8075766..a0fcf63d60aa6ba07ba3549c4fb33f79f5f69af1 100644 --- a/ets2panda/bindings/native/CMakeLists.txt +++ b/ets2panda/bindings/native/CMakeLists.txt @@ -67,7 +67,6 @@ set(NAPI_BINDINGS_LIB "ts_bindings") set(BINDINGS_NAPI_SRC ./src/common-interop.cpp ./src/convertors-napi.cpp - ./src/callback-resource.cpp ./src/lsp.cpp ) diff --git a/ets2panda/bindings/native/include/callback-resource.h b/ets2panda/bindings/native/include/callback-resource.h deleted file mode 100644 index 5f8346fa78938505b8d5961a989ce90a8f34b834..0000000000000000000000000000000000000000 --- a/ets2panda/bindings/native/include/callback-resource.h +++ /dev/null @@ -1,64 +0,0 @@ -/* - * Copyright (c) 2025 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef INTEROP_CALLBACK_RESOURCE_H -#define INTEROP_CALLBACK_RESOURCE_H - -#include -#include "interop-types.h" - -// NOLINTBEGIN - -class CallbackResourceHolder { -private: - std::vector heldResources; - -public: - void holdCallbackResource(const InteropCallbackResource *resource) - { - resource->hold(resource->resourceId); - this->heldResources.push_back(*resource); - } - void release() - { - for (auto resource : this->heldResources) { - resource.release(resource.resourceId); - } - this->heldResources.clear(); - } -}; - -struct CallbackBuffer { - InteropInt32 kind; - uint8_t buffer[60 * 4]; - CallbackResourceHolder resourceHolder; -}; - -enum CallbackEventKind { - EVENT_CALL_CALLBACK = 0, - EVENT_HOLD_MANAGED_RESOURCE = 1, - EVENT_RELEASE_MANAGED_RESOURCE = 2, -}; - -// CC-OFFNXT(G.NAM.01) false positive -void EnqueueCallback(const CallbackBuffer *event); -// CC-OFFNXT(G.NAM.01) false positive -void HoldManagedCallbackResource(InteropInt32 resourceId); -// CC-OFFNXT(G.NAM.01) false positive -void ReleaseManagedCallbackResource(InteropInt32 resourceId); - -// NOLINTEND - -#endif diff --git a/ets2panda/bindings/native/include/common-interop.h b/ets2panda/bindings/native/include/common-interop.h index 6f6ed61b60fb6cec9c527b86a7144e1d63500873..f179684dcbf6c3e8aa3e089682a7c3a580aaad3a 100644 --- a/ets2panda/bindings/native/include/common-interop.h +++ b/ets2panda/bindings/native/include/common-interop.h @@ -20,11 +20,15 @@ #include "panda_types.h" -// NOLINTBEGIN +// NOLINTBEGIN(cppcoreguidelines-macro-usage) +// CC-OFFNXT(G.PRE.02) code gen #define TS_INTEROP_PROFILER 0 +// CC-OFFNXT(G.PRE.02) code gen #define TS_INTEROP_TRACER 0 +// NOLINTEND(cppcoreguidelines-macro-usage) + #if TS_INTEROP_PROFILER #include "profiler.h" // CC-OFFNXT(G.PRE.09) code gen @@ -45,20 +49,18 @@ #define TS_MAYBE_LOG(name) #endif -typedef void (*CallbackCallert)(KInt callbackKind, KByte *argsData, KInt argsLength); -typedef void (*CallbackCallerSynct)(KVMContext vmContext, KInt callbackKind, KByte *argsData, KInt argsLength); +using CallbackCallert = void (*)(KInt callbackKind, KByte *argsData, KInt argsLength); +using CallbackCallerSynct = void (*)(KVMContext vmContext, KInt callbackKind, KByte *argsData, KInt argsLength); void SetCallbackCaller(CallbackCallert caller); void SetCallbackCallerSync(CallbackCallerSynct callerSync); KVMDeferred *CreateDeferred(KVMContext context, KVMObjectHandle *promise); -// CC-OFFNXT(G.NAM.01) false positive +// CC-OFFNXT(G.NAM.01, G.NAM.03-CPP) project code style std::vector MakeStringVector(KStringArray strArray); -// CC-OFFNXT(G.NAM.01) false positive -std::vector MakeStringVector(KNativePointerArray arr, KInt size); +// CC-OFFNXT(G.NAM.01, G.NAM.03-CPP) project code style +std::vector MakeStringVector(KNativePointerArray arr, KInt length); #include "convertors-napi.h" -// NOLINTEND - #endif // COMMON_INTEROP_BASE_H diff --git a/ets2panda/bindings/native/include/convertors-napi.h b/ets2panda/bindings/native/include/convertors-napi.h index 053f2d9834bfabf785daad6b5994cfc5e4b81798..faf795adb374f02d802eea278efdc4fd6f4c4fae 100644 --- a/ets2panda/bindings/native/include/convertors-napi.h +++ b/ets2panda/bindings/native/include/convertors-napi.h @@ -19,6 +19,8 @@ #include #include #include +#include +#include #ifndef TS_NAPI_OHOS #include @@ -28,69 +30,69 @@ #endif #include "panda_types.h" -// NOLINTBEGIN template struct InteropTypeConverter { using InteropType = T; - static T convertFrom([[maybe_unused]] napi_env env, InteropType value) + static T ConvertFrom([[maybe_unused]] napi_env env, InteropType value) { return value; } - static InteropType convertTo([[maybe_unused]] napi_env env, T value) + static InteropType ConvertTo([[maybe_unused]] napi_env env, T value) { return value; } - static void release([[maybe_unused]] napi_env env, [[maybe_unused]] InteropType value, [[maybe_unused]] T converted) + static void Release([[maybe_unused]] napi_env env, [[maybe_unused]] InteropType value, [[maybe_unused]] T converted) { } }; template -inline typename InteropTypeConverter::InteropType makeResult(napi_env env, Type value) +inline typename InteropTypeConverter::InteropType MakeResult(napi_env env, Type value) { - return InteropTypeConverter::convertTo(env, value); + return InteropTypeConverter::ConvertTo(env, value); } template -inline Type getArgument(napi_env env, typename InteropTypeConverter::InteropType arg) +inline Type GetArgument(napi_env env, typename InteropTypeConverter::InteropType arg) { - return InteropTypeConverter::convertFrom(env, arg); + return InteropTypeConverter::ConvertFrom(env, arg); } template -inline void releaseArgument(napi_env env, typename InteropTypeConverter::InteropType arg, Type data) +inline void ReleaseArgument(napi_env env, typename InteropTypeConverter::InteropType arg, Type data) { - InteropTypeConverter::release(env, arg, data); + InteropTypeConverter::Release(env, arg, data); } template <> struct InteropTypeConverter { using InteropType = napi_value; - static KInteropBuffer convertFrom(napi_env env, InteropType value) + static KInteropBuffer ConvertFrom(napi_env env, InteropType value) { auto placeholder = 0; KInteropBuffer result = {placeholder, nullptr, 0, nullptr}; bool isArrayBuffer = false; napi_is_arraybuffer(env, value, &isArrayBuffer); if (isArrayBuffer) { - napi_get_arraybuffer_info(env, value, &result.data, (size_t *)&result.length); + napi_get_arraybuffer_info(env, value, &result.data, reinterpret_cast(&result.length)); } else { bool isDataView = false; napi_is_dataview(env, value, &isDataView); if (isDataView) { - napi_get_dataview_info(env, value, (size_t *)&result.length, &result.data, nullptr, nullptr); + napi_get_dataview_info(env, value, reinterpret_cast(&result.length), &result.data, nullptr, + nullptr); } } return result; } - static InteropType convertTo(napi_env env, KInteropBuffer value) + static InteropType ConvertTo(napi_env env, KInteropBuffer value) { - KInteropBuffer *copy = new KInteropBuffer(value); + auto *copy = new KInteropBuffer(value); napi_value result; napi_status status = napi_create_external_arraybuffer( env, value.data, value.length, - []([[maybe_unused]] napi_env env_, [[maybe_unused]] void *finalize_data, void *finalize_hint) { - KInteropBuffer *buffer = reinterpret_cast(finalize_hint); + []([[maybe_unused]] napi_env envArg, [[maybe_unused]] void *finalizeData, void *finalizeHint) { + auto *buffer = reinterpret_cast(finalizeHint); buffer->dispose(buffer->resourceId); delete buffer; }, @@ -100,7 +102,7 @@ struct InteropTypeConverter { } return result; }; - static void release([[maybe_unused]] napi_env env, [[maybe_unused]] InteropType value, + static void Release([[maybe_unused]] napi_env env, [[maybe_unused]] InteropType value, [[maybe_unused]] KInteropBuffer converted) { } @@ -109,26 +111,28 @@ struct InteropTypeConverter { template <> struct InteropTypeConverter { using InteropType = napi_value; - static KStringPtr convertFrom(napi_env env, InteropType value) + static KStringPtr ConvertFrom(napi_env env, InteropType value) { - if (value == nullptr) + if (value == nullptr) { return KStringPtr(); + } KStringPtr result; size_t length = 0; napi_status status = napi_get_value_string_utf8(env, value, nullptr, 0, &length); - if (status != 0) + if (status != 0) { return result; - result.resize(length); - napi_get_value_string_utf8(env, value, result.data(), length + 1, nullptr); + } + result.Resize(length); + napi_get_value_string_utf8(env, value, result.Data(), length + 1, nullptr); return result; } - static InteropType convertTo(napi_env env, const KStringPtr &value) + static InteropType ConvertTo(napi_env env, const KStringPtr &value) { napi_value result; - napi_create_string_utf8(env, value.c_str(), value.length(), &result); + napi_create_string_utf8(env, value.CStr(), value.Length(), &result); return result; } - static void release([[maybe_unused]] napi_env env, [[maybe_unused]] InteropType value, + static void Release([[maybe_unused]] napi_env env, [[maybe_unused]] InteropType value, [[maybe_unused]] const KStringPtr &converted) { } @@ -137,19 +141,19 @@ struct InteropTypeConverter { template <> struct InteropTypeConverter { using InteropType = napi_value; - static KInteropNumber convertFrom(napi_env env, InteropType interopValue) + static KInteropNumber ConvertFrom(napi_env env, InteropType interopValue) { double value = 0.0; napi_get_value_double(env, interopValue, &value); - return KInteropNumber::fromDouble(value); + return KInteropNumber::FromDouble(value); } - static InteropType convertTo(napi_env env, KInteropNumber value) + static InteropType ConvertTo(napi_env env, KInteropNumber value) { napi_value result; - napi_create_double(env, value.asDouble(), &result); + napi_create_double(env, value.AsDouble(), &result); return result; } - static void release([[maybe_unused]] napi_env env, [[maybe_unused]] InteropType value, + static void Release([[maybe_unused]] napi_env env, [[maybe_unused]] InteropType value, [[maybe_unused]] KInteropNumber converted) { } @@ -158,15 +162,15 @@ struct InteropTypeConverter { template <> struct InteropTypeConverter { using InteropType = napi_value; - static inline KVMObjectHandle convertFrom([[maybe_unused]] napi_env env, InteropType value) + static inline KVMObjectHandle ConvertFrom([[maybe_unused]] napi_env env, InteropType value) { return reinterpret_cast(value); } - static InteropType convertTo([[maybe_unused]] napi_env env, KVMObjectHandle value) + static InteropType ConvertTo([[maybe_unused]] napi_env env, KVMObjectHandle value) { return reinterpret_cast(value); } - static inline void release([[maybe_unused]] napi_env env, [[maybe_unused]] InteropType value, + static inline void Release([[maybe_unused]] napi_env env, [[maybe_unused]] InteropType value, [[maybe_unused]] KVMObjectHandle converted) { } @@ -175,26 +179,28 @@ struct InteropTypeConverter { template <> struct InteropTypeConverter { using InteropType = napi_value; - static inline KInteropReturnBuffer convertFrom(napi_env env, InteropType value) = delete; - static void disposer([[maybe_unused]] napi_env env, [[maybe_unused]] void *data, void *hint) + static inline KInteropReturnBuffer ConvertFrom(napi_env env, InteropType value) = delete; + static void Disposer([[maybe_unused]] napi_env env, [[maybe_unused]] void *data, void *hint) { - KInteropReturnBuffer *bufferCopy = (KInteropReturnBuffer *)hint; + auto *bufferCopy = static_cast(hint); bufferCopy->dispose(bufferCopy->data, bufferCopy->length); delete bufferCopy; } - static InteropType convertTo(napi_env env, KInteropReturnBuffer value) + static InteropType ConvertTo(napi_env env, KInteropReturnBuffer value) { napi_value result = nullptr; napi_value arrayBuffer = nullptr; auto clone = new KInteropReturnBuffer(); *clone = value; - napi_create_external_arraybuffer(env, value.data, value.length, disposer, clone, &arrayBuffer); + napi_create_external_arraybuffer(env, value.data, value.length, Disposer, clone, &arrayBuffer); napi_create_typedarray(env, napi_uint8_array, value.length, arrayBuffer, 0, &result); return result; } - static inline void release(napi_env env, InteropType value, const KInteropReturnBuffer &converted) = delete; + static inline void Release(napi_env env, InteropType value, const KInteropReturnBuffer &converted) = delete; }; +// NOLINTBEGIN(cppcoreguidelines-macro-usage) + #define TS_INTEROP_THROW(vmcontext, object, ...) \ do { \ napi_env env = (napi_env)vmcontext; \ @@ -214,15 +220,15 @@ struct InteropTypeConverter { } while (0) // CC-OFFNXT(G.PRE.02-CPP) code generation -#define NAPI_ASSERT_INDEX(info, index, result) \ - do { \ - /* CC-OFFNXT(G.PRE.02) name part*/ \ - if (static_cast(index) >= info.Length()) { \ - /* CC-OFFNXT(G.PRE.02) name part*/ \ - napi_throw_error(info.Env(), nullptr, "No such element"); \ - /* CC-OFFNXT(G.PRE.05) function gen */ \ - return result; \ - } \ +#define NAPI_ASSERT_INDEX(info, index, result) \ + do { \ + /* CC-OFFNXT(G.PRE.02) name part*/ \ + if ((static_cast(index)) >= (info).Length()) { \ + /* CC-OFFNXT(G.PRE.02) name part*/ \ + napi_throw_error((info).Env(), nullptr, "No such element"); \ + /* CC-OFFNXT(G.PRE.05) function gen */ \ + return result; \ + } \ } while (0) // Helpers from node-addon-api @@ -245,16 +251,19 @@ struct InteropTypeConverter { return; \ } +// NOLINTEND(cppcoreguidelines-macro-usage) + class CallbackInfo { public: - CallbackInfo(napi_env env, napi_callback_info info) : _env(env) + CallbackInfo(napi_env env, napi_callback_info info) : env_(env) { size_t size = 0; napi_status status = napi_get_cb_info(env, info, &size, nullptr, nullptr, nullptr); TS_NAPI_THROW_IF_FAILED_VOID(env, status); if (size > 0) { - args.resize(size); // NOTE(khil): statically allocate small array for common case with few arguments passed - status = napi_get_cb_info(env, info, &size, args.data(), nullptr, nullptr); + args_.resize( + size); // NOTE(khil): statically allocate small array for common case with few arguments passed + status = napi_get_cb_info(env, info, &size, args_.data(), nullptr, nullptr); TS_NAPI_THROW_IF_FAILED_VOID(env, status); } } @@ -263,91 +272,91 @@ public: { if (idx >= Length()) { napi_value result; - napi_get_undefined(_env, &result); + napi_get_undefined(env_, &result); return result; } - return args[idx]; + return args_[idx]; } napi_env Env() const { - return _env; + return env_; } size_t Length() const { - return args.size(); + return args_.size(); } private: - napi_env _env; + napi_env env_; // napi_callback_info _info; - std::vector args; + std::vector args_; }; template -inline napi_typedarray_type getNapiType() = delete; +inline napi_typedarray_type GetNapiType() = delete; template <> -inline napi_typedarray_type getNapiType() +inline napi_typedarray_type GetNapiType() { return napi_float32_array; } template <> -inline napi_typedarray_type getNapiType() +inline napi_typedarray_type GetNapiType() { return napi_int8_array; } template <> -inline napi_typedarray_type getNapiType() +inline napi_typedarray_type GetNapiType() { return napi_uint8_array; } template <> -inline napi_typedarray_type getNapiType() +inline napi_typedarray_type GetNapiType() { return napi_int16_array; } template <> -inline napi_typedarray_type getNapiType() +inline napi_typedarray_type GetNapiType() { return napi_uint16_array; } template <> -inline napi_typedarray_type getNapiType() +inline napi_typedarray_type GetNapiType() { return napi_int32_array; } template <> -inline napi_typedarray_type getNapiType() +inline napi_typedarray_type GetNapiType() { return napi_uint32_array; } template <> -inline napi_typedarray_type getNapiType() +inline napi_typedarray_type GetNapiType() { return napi_biguint64_array; } -napi_valuetype getValueTypeChecked(napi_env env, napi_value value); -bool isTypedArray(napi_env env, napi_value value); +napi_valuetype GetValueTypeChecked(napi_env env, napi_value value); +bool IsTypedArray(napi_env env, napi_value value); template // CC-OFFNXT(G.FUD.06) solid logic, ODR -inline ElemType *getTypedElements(napi_env env, napi_value value) +inline ElemType *GetTypedElements(napi_env env, napi_value value) { - napi_valuetype valueType = getValueTypeChecked(env, value); + napi_valuetype valueType = GetValueTypeChecked(env, value); if (valueType == napi_null) { return nullptr; } - if (!isTypedArray(env, value)) { + if (!IsTypedArray(env, value)) { napi_throw_error(env, nullptr, "Expected TypedArray"); return nullptr; } @@ -358,8 +367,8 @@ inline ElemType *getTypedElements(napi_env env, napi_value value) napi_typedarray_type type; napi_status status = napi_get_typedarray_info(env, value, &type, &byteLength, &data, &arrayBuffer, &byteOffset); TS_NAPI_THROW_IF_FAILED(env, status, nullptr); - if (type != getNapiType()) { - printf("Array type mismatch. Expected %d got %d\n", getNapiType(), type); + if (type != GetNapiType()) { + std::cout << "Array type mismatch. Expected " << GetNapiType() << " got " << type << std::endl; napi_throw_error(env, nullptr, "Array type mismatch"); return nullptr; } @@ -367,155 +376,156 @@ inline ElemType *getTypedElements(napi_env env, napi_value value) } template -inline ElemType *getTypedElements(const CallbackInfo &info, int index) +inline ElemType *GetTypedElements(const CallbackInfo &info, int index) { NAPI_ASSERT_INDEX(info, index, nullptr); - return getTypedElements(info.Env(), info[index]); + return GetTypedElements(info.Env(), info[index]); } -inline uint8_t *getUInt8Elements(const CallbackInfo &info, int index) +inline uint8_t *GetUInt8Elements(const CallbackInfo &info, int index) { - return getTypedElements(info, index); + return GetTypedElements(info, index); } -inline int8_t *getInt8Elements(const CallbackInfo &info, int index) +inline int8_t *GetInt8Elements(const CallbackInfo &info, int index) { - return getTypedElements(info, index); + return GetTypedElements(info, index); } -inline uint16_t *getUInt16Elements(const CallbackInfo &info, int index) +inline uint16_t *GetUInt16Elements(const CallbackInfo &info, int index) { - return getTypedElements(info, index); + return GetTypedElements(info, index); } -inline int16_t *getInt16Elements(const CallbackInfo &info, int index) +inline int16_t *GetInt16Elements(const CallbackInfo &info, int index) { - return getTypedElements(info, index); + return GetTypedElements(info, index); } -inline uint32_t *getUInt32Elements(const CallbackInfo &info, int index) +inline uint32_t *GetUInt32Elements(const CallbackInfo &info, int index) { - return getTypedElements(info, index); + return GetTypedElements(info, index); } -inline uint32_t *getUInt32Elements(napi_env env, napi_value value) +inline uint32_t *GetUInt32Elements(napi_env env, napi_value value) { - return getTypedElements(env, value); + return GetTypedElements(env, value); } -inline int32_t *getInt32Elements(const CallbackInfo &info, int index) +inline int32_t *GetInt32Elements(const CallbackInfo &info, int index) { - return getTypedElements(info, index); + return GetTypedElements(info, index); } -inline float *getFloat32Elements(const CallbackInfo &info, int index) +inline float *GetFloat32Elements(const CallbackInfo &info, int index) { - return getTypedElements(info, index); + return GetTypedElements(info, index); } -inline KNativePointer *getPointerElements(const CallbackInfo &info, int index) +inline KNativePointer *GetPointerElements(const CallbackInfo &info, int index) { - return getTypedElements(info, index); + return GetTypedElements(info, index); } -KInt getInt32(napi_env env, napi_value value); -inline int32_t getInt32(const CallbackInfo &info, int index) +KInt GetInt32(napi_env env, napi_value value); +inline int32_t GetInt32(const CallbackInfo &info, int index) { NAPI_ASSERT_INDEX(info, index, 0); - return getInt32(info.Env(), info[index]); + return GetInt32(info.Env(), info[index]); } -KUInt getUInt32(napi_env env, napi_value value); -inline uint32_t getUInt32(const CallbackInfo &info, int index) +KUInt GetUInt32(napi_env env, napi_value value); +inline uint32_t GetUInt32(const CallbackInfo &info, int index) { NAPI_ASSERT_INDEX(info, index, 0); - return getUInt32(info.Env(), info[index]); + return GetUInt32(info.Env(), info[index]); } -KFloat getFloat32(napi_env env, napi_value value); -inline float getFloat32(const CallbackInfo &info, int index) +KFloat GetFloat32(napi_env env, napi_value value); +inline float GetFloat32(const CallbackInfo &info, int index) { - NAPI_ASSERT_INDEX(info, index, 0.0f); - return getFloat32(info.Env(), info[index]); + NAPI_ASSERT_INDEX(info, index, 0.0F); + return GetFloat32(info.Env(), info[index]); } -KDouble getFloat64(napi_env env, napi_value value); -inline KDouble getFloat64(const CallbackInfo &info, int index) +KDouble GetFloat64(napi_env env, napi_value value); +inline KDouble GetFloat64(const CallbackInfo &info, int index) { NAPI_ASSERT_INDEX(info, index, 0.0); - return getFloat64(info.Env(), info[index]); + return GetFloat64(info.Env(), info[index]); } -KStringPtr getString(napi_env env, napi_value value); -inline KStringPtr getString(const CallbackInfo &info, int index) +KStringPtr GetString(napi_env env, napi_value value); +inline KStringPtr GetString(const CallbackInfo &info, int index) { NAPI_ASSERT_INDEX(info, index, KStringPtr()); - return getString(info.Env(), info[index]); + return GetString(info.Env(), info[index]); } -void *getPointer(napi_env env, napi_value value); -inline void *getPointer(const CallbackInfo &info, int index) +void *GetPointer(napi_env env, napi_value value); +inline void *GetPointer(const CallbackInfo &info, int index) { NAPI_ASSERT_INDEX(info, index, nullptr); - return getPointer(info.Env(), info[index]); + return GetPointer(info.Env(), info[index]); } -KLong getInt64(napi_env env, napi_value value); -inline KLong getInt64(const CallbackInfo &info, int index) +KLong GetInt64(napi_env env, napi_value value); +inline KLong GetInt64(const CallbackInfo &info, int index) { NAPI_ASSERT_INDEX(info, index, 0); - return getInt64(info.Env(), info[index]); + return GetInt64(info.Env(), info[index]); } -KBoolean getBoolean(napi_env env, napi_value value); -inline KBoolean getBoolean(const CallbackInfo &info, int index) +KBoolean GetBoolean(napi_env env, napi_value value); +inline KBoolean GetBoolean(const CallbackInfo &info, int index) { NAPI_ASSERT_INDEX(info, index, false); - return getBoolean(info.Env(), info[index]); + return GetBoolean(info.Env(), info[index]); } template -inline Type getArgument(const CallbackInfo &info, int index) = delete; +inline Type GetArgument(const CallbackInfo &info, int index) = delete; template <> -inline KBoolean getArgument(const CallbackInfo &info, int index) +inline KBoolean GetArgument(const CallbackInfo &info, int index) { - return getBoolean(info, index); + return GetBoolean(info, index); } template <> -inline KUInt getArgument(const CallbackInfo &info, int index) +inline KUInt GetArgument(const CallbackInfo &info, int index) { - return getUInt32(info, index); + return GetUInt32(info, index); } template <> -inline KInt getArgument(const CallbackInfo &info, int index) +inline KInt GetArgument(const CallbackInfo &info, int index) { - return getInt32(info, index); + return GetInt32(info, index); } template <> -inline KInteropNumber getArgument(const CallbackInfo &info, int index) +inline KInteropNumber GetArgument(const CallbackInfo &info, int index) { - KInteropNumber res = {0, {0}}; + KInteropNumber res {}; NAPI_ASSERT_INDEX(info, index, res); - return getArgument(info.Env(), info[index]); + return GetArgument(info.Env(), info[index]); } template <> // CC-OFFNXT(G.FUD.06) solid logic, ODR -inline KLength getArgument(const CallbackInfo &info, int index) +inline KLength GetArgument(const CallbackInfo &info, int index) { - KLength result = {0, 0.0f, 0, 0}; + KLength result = {0, 0.0F, 0, 0}; NAPI_ASSERT_INDEX(info, index, result); auto value = info[index]; napi_valuetype type; - auto type_status = napi_typeof(info.Env(), value, &type); - if (type_status != 0) + auto typeStatus = napi_typeof(info.Env(), value, &type); + if (typeStatus != 0) { return result; + } switch (type) { case napi_number: { - result.value = getFloat32(info.Env(), value); + result.value = GetFloat32(info.Env(), value); result.unit = 1; result.type = 0; break; } case napi_string: { - KStringPtr string = getString(info.Env(), value); + KStringPtr string = GetString(info.Env(), value); ParseKLength(string, &result); result.type = 1; result.resource = 0; @@ -529,201 +539,204 @@ inline KLength getArgument(const CallbackInfo &info, int index) napi_status status = napi_get_named_property(info.Env(), value, "id", &field); if (status == 0) { status = napi_get_value_int32(info.Env(), field, &result.resource); - if (status != 0) + if (status != 0) { result.resource = 0; + } } else { result.resource = 0; } break; } default: - throw "Error, unexpected KLength type"; + throw std::runtime_error("Error, unexpected KLength type"); } return result; } template <> -inline KInteropBuffer getArgument(const CallbackInfo &info, int index) +inline KInteropBuffer GetArgument(const CallbackInfo &info, int index) { KInteropBuffer res = {0, nullptr, 0, nullptr}; NAPI_ASSERT_INDEX(info, index, res); - return getArgument((napi_env)info.Env(), (napi_value)info[index]); + return GetArgument((napi_env)info.Env(), (napi_value)info[index]); } template <> -inline KFloat getArgument(const CallbackInfo &info, int index) +inline KFloat GetArgument(const CallbackInfo &info, int index) { - return getFloat32(info, index); + return GetFloat32(info, index); } template <> -inline KDouble getArgument(const CallbackInfo &info, int index) +inline KDouble GetArgument(const CallbackInfo &info, int index) { - return getFloat64(info, index); + return GetFloat64(info, index); } template <> -inline KNativePointer getArgument(const CallbackInfo &info, int index) +inline KNativePointer GetArgument(const CallbackInfo &info, int index) { - return getPointer(info, index); + return GetPointer(info, index); } template <> -inline KLong getArgument(const CallbackInfo &info, int index) +inline KLong GetArgument(const CallbackInfo &info, int index) { - return getInt64(info, index); + return GetInt64(info, index); } template <> -inline KNativePointerArray getArgument(const CallbackInfo &info, int index) +inline KNativePointerArray GetArgument(const CallbackInfo &info, int index) { - return getPointerElements(info, index); + return GetPointerElements(info, index); } template <> -inline uint8_t *getArgument(const CallbackInfo &info, int index) +inline uint8_t *GetArgument(const CallbackInfo &info, int index) { - return getUInt8Elements(info, index); + return GetUInt8Elements(info, index); } template <> -inline const uint8_t *getArgument(const CallbackInfo &info, int index) +inline const uint8_t *GetArgument(const CallbackInfo &info, int index) { - return getUInt8Elements(info, index); + return GetUInt8Elements(info, index); } template <> -inline int8_t *getArgument(const CallbackInfo &info, int index) +inline int8_t *GetArgument(const CallbackInfo &info, int index) { - return getInt8Elements(info, index); + return GetInt8Elements(info, index); } template <> -inline int16_t *getArgument(const CallbackInfo &info, int index) +inline int16_t *GetArgument(const CallbackInfo &info, int index) { - return getInt16Elements(info, index); + return GetInt16Elements(info, index); } template <> -inline uint16_t *getArgument(const CallbackInfo &info, int index) +inline uint16_t *GetArgument(const CallbackInfo &info, int index) { - return getUInt16Elements(info, index); + return GetUInt16Elements(info, index); } template <> -inline int32_t *getArgument(const CallbackInfo &info, int index) +inline int32_t *GetArgument(const CallbackInfo &info, int index) { - return getInt32Elements(info, index); + return GetInt32Elements(info, index); } template <> -inline uint32_t *getArgument(const CallbackInfo &info, int index) +inline uint32_t *GetArgument(const CallbackInfo &info, int index) { - return getUInt32Elements(info, index); + return GetUInt32Elements(info, index); } template <> -inline float *getArgument(const CallbackInfo &info, int index) +inline float *GetArgument(const CallbackInfo &info, int index) { - return getFloat32Elements(info, index); + return GetFloat32Elements(info, index); } template <> -inline KStringPtr getArgument(const CallbackInfo &info, int index) +inline KStringPtr GetArgument(const CallbackInfo &info, int index) { - return getString(info, index); + return GetString(info, index); } -napi_value makeString(napi_env env, KStringPtr value); -napi_value makeString(napi_env env, const std::string &value); -napi_value makeBoolean(napi_env env, KBoolean value); -napi_value makeInt32(napi_env env, int32_t value); -napi_value makeUInt32(napi_env env, uint32_t value); -napi_value makeFloat32(napi_env env, float value); -napi_value makePointer(napi_env env, void *value); -napi_value makeVoid(napi_env env); +napi_value MakeString(napi_env env, KStringPtr value); +napi_value MakeString(napi_env env, const std::string &value); +napi_value MakeBoolean(napi_env env, KBoolean value); +napi_value MakeInt32(napi_env env, int32_t value); +napi_value MakeUInt32(napi_env env, uint32_t value); +napi_value MakeFloat32(napi_env env, float value); +napi_value MakePointer(napi_env env, void *value); +napi_value MakeVoid(napi_env env); -inline napi_value makeVoid(const CallbackInfo &info) +inline napi_value MakeVoid(const CallbackInfo &info) { - return makeVoid(info.Env()); + return MakeVoid(info.Env()); } template -inline napi_value makeResult(const CallbackInfo &info, Type value) = delete; +inline napi_value MakeResult(const CallbackInfo &info, Type value) = delete; template <> -inline napi_value makeResult(const CallbackInfo &info, KBoolean value) +inline napi_value MakeResult(const CallbackInfo &info, KBoolean value) { - return makeBoolean(info.Env(), value); + return MakeBoolean(info.Env(), value); } template <> -inline napi_value makeResult(const CallbackInfo &info, int32_t value) +inline napi_value MakeResult(const CallbackInfo &info, int32_t value) { - return makeInt32(info.Env(), value); + return MakeInt32(info.Env(), value); } template <> -inline napi_value makeResult(const CallbackInfo &info, uint32_t value) +inline napi_value MakeResult(const CallbackInfo &info, uint32_t value) { - return makeUInt32(info.Env(), value); + return MakeUInt32(info.Env(), value); } template <> -inline napi_value makeResult(const CallbackInfo &info, float value) +inline napi_value MakeResult(const CallbackInfo &info, float value) { - return makeFloat32(info.Env(), value); + return MakeFloat32(info.Env(), value); } template <> -inline napi_value makeResult(const CallbackInfo &info, KNativePointer value) +inline napi_value MakeResult(const CallbackInfo &info, KNativePointer value) { - return makePointer(info.Env(), value); + return MakePointer(info.Env(), value); } template <> -inline napi_value makeResult(const CallbackInfo &info, KVMObjectHandle value) +inline napi_value MakeResult(const CallbackInfo &info, KVMObjectHandle value) { - return InteropTypeConverter::convertTo(info.Env(), value); + return InteropTypeConverter::ConvertTo(info.Env(), value); } template <> -inline napi_value makeResult(const CallbackInfo &info, KStringPtr value) +inline napi_value MakeResult(const CallbackInfo &info, KStringPtr value) { - return InteropTypeConverter::convertTo(info.Env(), value); + return InteropTypeConverter::ConvertTo(info.Env(), value); } template <> -inline napi_value makeResult(const CallbackInfo &info, KInteropBuffer value) +inline napi_value MakeResult(const CallbackInfo &info, KInteropBuffer value) { - return InteropTypeConverter::convertTo(info.Env(), value); + return InteropTypeConverter::ConvertTo(info.Env(), value); } template <> -inline napi_value makeResult(const CallbackInfo &info, KInteropReturnBuffer value) +inline napi_value MakeResult(const CallbackInfo &info, KInteropReturnBuffer value) { - return InteropTypeConverter::convertTo(info.Env(), value); + return InteropTypeConverter::ConvertTo(info.Env(), value); } template <> -inline napi_value makeResult(const CallbackInfo &info, KInteropNumber value) +inline napi_value MakeResult(const CallbackInfo &info, KInteropNumber value) { - return InteropTypeConverter::convertTo(info.Env(), value); + return InteropTypeConverter::ConvertTo(info.Env(), value); } -typedef napi_value (*napi_type_t)(napi_env, napi_callback_info); +using NapiTypeT = napi_value (*)(napi_env, napi_callback_info); class Exports { - std::unordered_map>> implementations; + std::unordered_map>> implementations_; public: - static Exports *getInstance(); + static Exports *GetInstance(); - std::vector getModules(); - void addMethod(const char *module, const char *name, napi_type_t impl); - const std::vector> &getMethods(const std::string &module); + std::vector GetModules(); + void addMethod(const char *module, const char *name, NapiTypeT impl); + const std::vector> &GetMethods(const std::string &module); }; +// NOLINTBEGIN(cppcoreguidelines-macro-usage) + // CC-OFFNXT(G.DCL.01) false positive // CC-OFFNXT(G.NAM.01) false positive #define __QUOTE(x) #x @@ -732,13 +745,17 @@ public: #define MAKE_NODE_EXPORT(module, name) \ __attribute__((constructor)) static void __init_##name() \ { \ - Exports::getInstance()->addMethod(QUOTE(module), "_" #name, Node_##name); \ + Exports::GetInstance()->addMethod(QUOTE(module), "_" #name, Node_##name); \ } +// NOLINTEND(cppcoreguidelines-macro-usage) + #ifndef TS_INTEROP_MODULE #error TS_INTEROP_MODULE is undefined #endif +// NOLINTBEGIN(cppcoreguidelines-macro-usage) + #define MAKE_INTEROP_NODE_EXPORT(name) MAKE_NODE_EXPORT(TS_INTEROP_MODULE, name) #define TS_INTEROP_0(name, Ret) \ @@ -747,7 +764,7 @@ public: TS_MAYBE_LOG(name) \ CallbackInfo info(env, cbinfo); \ /* CC-OFFNXT(G.PRE.05) function gen */ \ - return makeResult(info, impl_##name()); \ + return MakeResult(info, impl_##name()); \ } \ MAKE_NODE_EXPORT(TS_INTEROP_MODULE, name) @@ -756,9 +773,9 @@ public: { \ TS_MAYBE_LOG(name) \ CallbackInfo info(env, cbinfo); \ - P0 p0 = getArgument(info, 0); \ + P0 p0 = GetArgument(info, 0); \ /* CC-OFFNXT(G.PRE.05) function gen */ \ - return makeResult(info, impl_##name(p0)); \ + return MakeResult(info, impl_##name(p0)); \ } \ MAKE_NODE_EXPORT(TS_INTEROP_MODULE, name) @@ -767,10 +784,10 @@ public: { \ TS_MAYBE_LOG(name) \ CallbackInfo info(env, cbinfo); \ - P0 p0 = getArgument(info, 0); \ - P1 p1 = getArgument(info, 1); \ + P0 p0 = GetArgument(info, 0); \ + P1 p1 = GetArgument(info, 1); \ /* CC-OFFNXT(G.PRE.05) function gen */ \ - return makeResult(info, impl_##name(p0, p1)); \ + return MakeResult(info, impl_##name(p0, p1)); \ } \ MAKE_NODE_EXPORT(TS_INTEROP_MODULE, name) @@ -780,11 +797,11 @@ public: { \ TS_MAYBE_LOG(name) \ CallbackInfo info(env, cbinfo); \ - P0 p0 = getArgument(info, 0); \ - P1 p1 = getArgument(info, 1); \ - P2 p2 = getArgument(info, 2); \ + P0 p0 = GetArgument(info, 0); \ + P1 p1 = GetArgument(info, 1); \ + P2 p2 = GetArgument(info, 2); \ /* CC-OFFNXT(G.PRE.05) function gen */ \ - return makeResult(info, impl_##name(p0, p1, p2)); \ + return MakeResult(info, impl_##name(p0, p1, p2)); \ } \ MAKE_NODE_EXPORT(TS_INTEROP_MODULE, name) @@ -794,12 +811,12 @@ public: { \ TS_MAYBE_LOG(name) \ CallbackInfo info(env, cbinfo); \ - P0 p0 = getArgument(info, 0); \ - P1 p1 = getArgument(info, 1); \ - P2 p2 = getArgument(info, 2); \ - P3 p3 = getArgument(info, 3); \ + P0 p0 = GetArgument(info, 0); \ + P1 p1 = GetArgument(info, 1); \ + P2 p2 = GetArgument(info, 2); \ + P3 p3 = GetArgument(info, 3); \ /* CC-OFFNXT(G.PRE.05) function gen */ \ - return makeResult(info, impl_##name(p0, p1, p2, p3)); \ + return MakeResult(info, impl_##name(p0, p1, p2, p3)); \ } \ MAKE_NODE_EXPORT(TS_INTEROP_MODULE, name) @@ -809,13 +826,13 @@ public: { \ TS_MAYBE_LOG(name) \ CallbackInfo info(env, cbinfo); \ - P0 p0 = getArgument(info, 0); \ - P1 p1 = getArgument(info, 1); \ - P2 p2 = getArgument(info, 2); \ - P3 p3 = getArgument(info, 3); \ - P4 p4 = getArgument(info, 4); \ + P0 p0 = GetArgument(info, 0); \ + P1 p1 = GetArgument(info, 1); \ + P2 p2 = GetArgument(info, 2); \ + P3 p3 = GetArgument(info, 3); \ + P4 p4 = GetArgument(info, 4); \ /* CC-OFFNXT(G.PRE.05) function gen */ \ - return makeResult(info, impl_##name(p0, p1, p2, p3, p4)); \ + return MakeResult(info, impl_##name(p0, p1, p2, p3, p4)); \ } \ MAKE_NODE_EXPORT(TS_INTEROP_MODULE, name) @@ -825,14 +842,14 @@ public: { \ TS_MAYBE_LOG(name) \ CallbackInfo info(env, cbinfo); \ - P0 p0 = getArgument(info, 0); \ - P1 p1 = getArgument(info, 1); \ - P2 p2 = getArgument(info, 2); \ - P3 p3 = getArgument(info, 3); \ - P4 p4 = getArgument(info, 4); \ - P5 p5 = getArgument(info, 5); \ + P0 p0 = GetArgument(info, 0); \ + P1 p1 = GetArgument(info, 1); \ + P2 p2 = GetArgument(info, 2); \ + P3 p3 = GetArgument(info, 3); \ + P4 p4 = GetArgument(info, 4); \ + P5 p5 = GetArgument(info, 5); \ /* CC-OFFNXT(G.PRE.05) function gen */ \ - return makeResult(info, impl_##name(p0, p1, p2, p3, p4, p5)); \ + return MakeResult(info, impl_##name(p0, p1, p2, p3, p4, p5)); \ } \ MAKE_NODE_EXPORT(TS_INTEROP_MODULE, name) @@ -842,15 +859,15 @@ public: { \ TS_MAYBE_LOG(name) \ CallbackInfo info(env, cbinfo); \ - P0 p0 = getArgument(info, 0); \ - P1 p1 = getArgument(info, 1); \ - P2 p2 = getArgument(info, 2); \ - P3 p3 = getArgument(info, 3); \ - P4 p4 = getArgument(info, 4); \ - P5 p5 = getArgument(info, 5); \ - P6 p6 = getArgument(info, 6); \ + P0 p0 = GetArgument(info, 0); \ + P1 p1 = GetArgument(info, 1); \ + P2 p2 = GetArgument(info, 2); \ + P3 p3 = GetArgument(info, 3); \ + P4 p4 = GetArgument(info, 4); \ + P5 p5 = GetArgument(info, 5); \ + P6 p6 = GetArgument(info, 6); \ /* CC-OFFNXT(G.PRE.05) function gen */ \ - return makeResult(info, impl_##name(p0, p1, p2, p3, p4, p5, p6)); \ + return MakeResult(info, impl_##name(p0, p1, p2, p3, p4, p5, p6)); \ } \ MAKE_NODE_EXPORT(TS_INTEROP_MODULE, name) @@ -860,16 +877,16 @@ public: { \ TS_MAYBE_LOG(name) \ CallbackInfo info(env, cbinfo); \ - P0 p0 = getArgument(info, 0); \ - P1 p1 = getArgument(info, 1); \ - P2 p2 = getArgument(info, 2); \ - P3 p3 = getArgument(info, 3); \ - P4 p4 = getArgument(info, 4); \ - P5 p5 = getArgument(info, 5); \ - P6 p6 = getArgument(info, 6); \ - P7 p7 = getArgument(info, 7); \ + P0 p0 = GetArgument(info, 0); \ + P1 p1 = GetArgument(info, 1); \ + P2 p2 = GetArgument(info, 2); \ + P3 p3 = GetArgument(info, 3); \ + P4 p4 = GetArgument(info, 4); \ + P5 p5 = GetArgument(info, 5); \ + P6 p6 = GetArgument(info, 6); \ + P7 p7 = GetArgument(info, 7); \ /* CC-OFFNXT(G.PRE.05) function gen */ \ - return makeResult(info, impl_##name(p0, p1, p2, p3, p4, p5, p6, p7)); \ + return MakeResult(info, impl_##name(p0, p1, p2, p3, p4, p5, p6, p7)); \ } \ MAKE_NODE_EXPORT(TS_INTEROP_MODULE, name) @@ -879,17 +896,17 @@ public: { \ TS_MAYBE_LOG(name) \ CallbackInfo info(env, cbinfo); \ - P0 p0 = getArgument(info, 0); \ - P1 p1 = getArgument(info, 1); \ - P2 p2 = getArgument(info, 2); \ - P3 p3 = getArgument(info, 3); \ - P4 p4 = getArgument(info, 4); \ - P5 p5 = getArgument(info, 5); \ - P6 p6 = getArgument(info, 6); \ - P7 p7 = getArgument(info, 7); \ - P8 p8 = getArgument(info, 8); \ + P0 p0 = GetArgument(info, 0); \ + P1 p1 = GetArgument(info, 1); \ + P2 p2 = GetArgument(info, 2); \ + P3 p3 = GetArgument(info, 3); \ + P4 p4 = GetArgument(info, 4); \ + P5 p5 = GetArgument(info, 5); \ + P6 p6 = GetArgument(info, 6); \ + P7 p7 = GetArgument(info, 7); \ + P8 p8 = GetArgument(info, 8); \ /* CC-OFFNXT(G.PRE.05) function gen */ \ - return makeResult(info, impl_##name(p0, p1, p2, p3, p4, p5, p6, p7, p8)); \ + return MakeResult(info, impl_##name(p0, p1, p2, p3, p4, p5, p6, p7, p8)); \ } \ MAKE_NODE_EXPORT(TS_INTEROP_MODULE, name) @@ -899,18 +916,18 @@ public: { \ TS_MAYBE_LOG(name) \ CallbackInfo info(env, cbinfo); \ - P0 p0 = getArgument(info, 0); \ - P1 p1 = getArgument(info, 1); \ - P2 p2 = getArgument(info, 2); \ - P3 p3 = getArgument(info, 3); \ - P4 p4 = getArgument(info, 4); \ - P5 p5 = getArgument(info, 5); \ - P6 p6 = getArgument(info, 6); \ - P7 p7 = getArgument(info, 7); \ - P8 p8 = getArgument(info, 8); \ - P9 p9 = getArgument(info, 9); \ + P0 p0 = GetArgument(info, 0); \ + P1 p1 = GetArgument(info, 1); \ + P2 p2 = GetArgument(info, 2); \ + P3 p3 = GetArgument(info, 3); \ + P4 p4 = GetArgument(info, 4); \ + P5 p5 = GetArgument(info, 5); \ + P6 p6 = GetArgument(info, 6); \ + P7 p7 = GetArgument(info, 7); \ + P8 p8 = GetArgument(info, 8); \ + P9 p9 = GetArgument(info, 9); \ /* CC-OFFNXT(G.PRE.05) function gen */ \ - return makeResult(info, impl_##name(p0, p1, p2, p3, p4, p5, p6, p7, p8, p9)); \ + return MakeResult(info, impl_##name(p0, p1, p2, p3, p4, p5, p6, p7, p8, p9)); \ } \ MAKE_NODE_EXPORT(TS_INTEROP_MODULE, name) @@ -920,19 +937,19 @@ public: { \ TS_MAYBE_LOG(name) \ CallbackInfo info(env, cbinfo); \ - P0 p0 = getArgument(info, 0); \ - P1 p1 = getArgument(info, 1); \ - P2 p2 = getArgument(info, 2); \ - P3 p3 = getArgument(info, 3); \ - P4 p4 = getArgument(info, 4); \ - P5 p5 = getArgument(info, 5); \ - P6 p6 = getArgument(info, 6); \ - P7 p7 = getArgument(info, 7); \ - P8 p8 = getArgument(info, 8); \ - P9 p9 = getArgument(info, 9); \ - P10 p10 = getArgument(info, 10); \ + P0 p0 = GetArgument(info, 0); \ + P1 p1 = GetArgument(info, 1); \ + P2 p2 = GetArgument(info, 2); \ + P3 p3 = GetArgument(info, 3); \ + P4 p4 = GetArgument(info, 4); \ + P5 p5 = GetArgument(info, 5); \ + P6 p6 = GetArgument(info, 6); \ + P7 p7 = GetArgument(info, 7); \ + P8 p8 = GetArgument(info, 8); \ + P9 p9 = GetArgument(info, 9); \ + P10 p10 = GetArgument(info, 10); \ /* CC-OFFNXT(G.PRE.05) function gen */ \ - return makeResult(info, impl_##name(p0, p1, p2, p3, p4, p5, p6, p7, p8, p9, p10)); \ + return MakeResult(info, impl_##name(p0, p1, p2, p3, p4, p5, p6, p7, p8, p9, p10)); \ } \ MAKE_NODE_EXPORT(TS_INTEROP_MODULE, name) @@ -942,20 +959,20 @@ public: { \ TS_MAYBE_LOG(name) \ CallbackInfo info(env, cbinfo); \ - P0 p0 = getArgument(info, 0); \ - P1 p1 = getArgument(info, 1); \ - P2 p2 = getArgument(info, 2); \ - P3 p3 = getArgument(info, 3); \ - P4 p4 = getArgument(info, 4); \ - P5 p5 = getArgument(info, 5); \ - P6 p6 = getArgument(info, 6); \ - P7 p7 = getArgument(info, 7); \ - P8 p8 = getArgument(info, 8); \ - P9 p9 = getArgument(info, 9); \ - P10 p10 = getArgument(info, 10); \ - P11 p11 = getArgument(info, 11); \ + P0 p0 = GetArgument(info, 0); \ + P1 p1 = GetArgument(info, 1); \ + P2 p2 = GetArgument(info, 2); \ + P3 p3 = GetArgument(info, 3); \ + P4 p4 = GetArgument(info, 4); \ + P5 p5 = GetArgument(info, 5); \ + P6 p6 = GetArgument(info, 6); \ + P7 p7 = GetArgument(info, 7); \ + P8 p8 = GetArgument(info, 8); \ + P9 p9 = GetArgument(info, 9); \ + P10 p10 = GetArgument(info, 10); \ + P11 p11 = GetArgument(info, 11); \ /* CC-OFFNXT(G.PRE.05) function gen */ \ - return makeResult(info, impl_##name(p0, p1, p2, p3, p4, p5, p6, p7, p8, p9, p10, p11)); \ + return MakeResult(info, impl_##name(p0, p1, p2, p3, p4, p5, p6, p7, p8, p9, p10, p11)); \ } \ MAKE_NODE_EXPORT(TS_INTEROP_MODULE, name) @@ -965,21 +982,21 @@ public: { \ TS_MAYBE_LOG(name) \ CallbackInfo info(env, cbinfo); \ - P0 p0 = getArgument(info, 0); \ - P1 p1 = getArgument(info, 1); \ - P2 p2 = getArgument(info, 2); \ - P3 p3 = getArgument(info, 3); \ - P4 p4 = getArgument(info, 4); \ - P5 p5 = getArgument(info, 5); \ - P6 p6 = getArgument(info, 6); \ - P7 p7 = getArgument(info, 7); \ - P8 p8 = getArgument(info, 8); \ - P9 p9 = getArgument(info, 9); \ - P10 p10 = getArgument(info, 10); \ - P11 p11 = getArgument(info, 11); \ - P12 p12 = getArgument(info, 12); \ + P0 p0 = GetArgument(info, 0); \ + P1 p1 = GetArgument(info, 1); \ + P2 p2 = GetArgument(info, 2); \ + P3 p3 = GetArgument(info, 3); \ + P4 p4 = GetArgument(info, 4); \ + P5 p5 = GetArgument(info, 5); \ + P6 p6 = GetArgument(info, 6); \ + P7 p7 = GetArgument(info, 7); \ + P8 p8 = GetArgument(info, 8); \ + P9 p9 = GetArgument(info, 9); \ + P10 p10 = GetArgument(info, 10); \ + P11 p11 = GetArgument(info, 11); \ + P12 p12 = GetArgument(info, 12); \ /* CC-OFFNXT(G.PRE.05) function gen */ \ - return makeResult(info, impl_##name(p0, p1, p2, p3, p4, p5, p6, p7, p8, p9, p10, p11, p12)); \ + return MakeResult(info, impl_##name(p0, p1, p2, p3, p4, p5, p6, p7, p8, p9, p10, p11, p12)); \ } \ MAKE_NODE_EXPORT(TS_INTEROP_MODULE, name) @@ -989,22 +1006,22 @@ public: { \ TS_MAYBE_LOG(name) \ CallbackInfo info(env, cbinfo); \ - P0 p0 = getArgument(info, 0); \ - P1 p1 = getArgument(info, 1); \ - P2 p2 = getArgument(info, 2); \ - P3 p3 = getArgument(info, 3); \ - P4 p4 = getArgument(info, 4); \ - P5 p5 = getArgument(info, 5); \ - P6 p6 = getArgument(info, 6); \ - P7 p7 = getArgument(info, 7); \ - P8 p8 = getArgument(info, 8); \ - P9 p9 = getArgument(info, 9); \ - P10 p10 = getArgument(info, 10); \ - P11 p11 = getArgument(info, 11); \ - P12 p12 = getArgument(info, 12); \ - P13 p13 = getArgument(info, 13); \ + P0 p0 = GetArgument(info, 0); \ + P1 p1 = GetArgument(info, 1); \ + P2 p2 = GetArgument(info, 2); \ + P3 p3 = GetArgument(info, 3); \ + P4 p4 = GetArgument(info, 4); \ + P5 p5 = GetArgument(info, 5); \ + P6 p6 = GetArgument(info, 6); \ + P7 p7 = GetArgument(info, 7); \ + P8 p8 = GetArgument(info, 8); \ + P9 p9 = GetArgument(info, 9); \ + P10 p10 = GetArgument(info, 10); \ + P11 p11 = GetArgument(info, 11); \ + P12 p12 = GetArgument(info, 12); \ + P13 p13 = GetArgument(info, 13); \ /* CC-OFFNXT(G.PRE.05) function gen */ \ - return makeResult(info, impl_##name(p0, p1, p2, p3, p4, p5, p6, p7, p8, p9, p10, p11, p12, p13)); \ + return MakeResult(info, impl_##name(p0, p1, p2, p3, p4, p5, p6, p7, p8, p9, p10, p11, p12, p13)); \ } \ MAKE_NODE_EXPORT(TS_INTEROP_MODULE, name) @@ -1015,7 +1032,7 @@ public: CallbackInfo info(env, cbinfo); \ impl_##name(); \ /* CC-OFFNXT(G.PRE.05) function gen */ \ - return makeVoid(info); \ + return MakeVoid(info); \ } \ MAKE_NODE_EXPORT(TS_INTEROP_MODULE, name) @@ -1024,10 +1041,10 @@ public: { \ TS_MAYBE_LOG(name) \ CallbackInfo info(env, cbinfo); \ - P0 p0 = getArgument(info, 0); \ + P0 p0 = GetArgument(info, 0); \ impl_##name(p0); \ /* CC-OFFNXT(G.PRE.05) function gen */ \ - return makeVoid(info); \ + return MakeVoid(info); \ } \ MAKE_NODE_EXPORT(TS_INTEROP_MODULE, name) @@ -1037,11 +1054,11 @@ public: { \ TS_MAYBE_LOG(name) \ CallbackInfo info(env, cbinfo); \ - P0 p0 = getArgument(info, 0); \ - P1 p1 = getArgument(info, 1); \ + P0 p0 = GetArgument(info, 0); \ + P1 p1 = GetArgument(info, 1); \ impl_##name(p0, p1); \ /* CC-OFFNXT(G.PRE.05) function gen */ \ - return makeVoid(info); \ + return MakeVoid(info); \ } \ MAKE_NODE_EXPORT(TS_INTEROP_MODULE, name) @@ -1051,12 +1068,12 @@ public: { \ TS_MAYBE_LOG(name) \ CallbackInfo info(env, cbinfo); \ - P0 p0 = getArgument(info, 0); \ - P1 p1 = getArgument(info, 1); \ - P2 p2 = getArgument(info, 2); \ + P0 p0 = GetArgument(info, 0); \ + P1 p1 = GetArgument(info, 1); \ + P2 p2 = GetArgument(info, 2); \ impl_##name(p0, p1, p2); \ /* CC-OFFNXT(G.PRE.05) function gen */ \ - return makeVoid(info); \ + return MakeVoid(info); \ } \ MAKE_NODE_EXPORT(TS_INTEROP_MODULE, name) @@ -1066,13 +1083,13 @@ public: { \ TS_MAYBE_LOG(name) \ CallbackInfo info(env, cbinfo); \ - P0 p0 = getArgument(info, 0); \ - P1 p1 = getArgument(info, 1); \ - P2 p2 = getArgument(info, 2); \ - P3 p3 = getArgument(info, 3); \ + P0 p0 = GetArgument(info, 0); \ + P1 p1 = GetArgument(info, 1); \ + P2 p2 = GetArgument(info, 2); \ + P3 p3 = GetArgument(info, 3); \ impl_##name(p0, p1, p2, p3); \ /* CC-OFFNXT(G.PRE.05) function gen */ \ - return makeVoid(info); \ + return MakeVoid(info); \ } \ MAKE_NODE_EXPORT(TS_INTEROP_MODULE, name) @@ -1082,14 +1099,14 @@ public: { \ TS_MAYBE_LOG(name) \ CallbackInfo info(env, cbinfo); \ - P0 p0 = getArgument(info, 0); \ - P1 p1 = getArgument(info, 1); \ - P2 p2 = getArgument(info, 2); \ - P3 p3 = getArgument(info, 3); \ - P4 p4 = getArgument(info, 4); \ + P0 p0 = GetArgument(info, 0); \ + P1 p1 = GetArgument(info, 1); \ + P2 p2 = GetArgument(info, 2); \ + P3 p3 = GetArgument(info, 3); \ + P4 p4 = GetArgument(info, 4); \ impl_##name(p0, p1, p2, p3, p4); \ /* CC-OFFNXT(G.PRE.05) function gen */ \ - return makeVoid(info); \ + return MakeVoid(info); \ } \ MAKE_NODE_EXPORT(TS_INTEROP_MODULE, name) @@ -1099,15 +1116,15 @@ public: { \ TS_MAYBE_LOG(name) \ CallbackInfo info(env, cbinfo); \ - P0 p0 = getArgument(info, 0); \ - P1 p1 = getArgument(info, 1); \ - P2 p2 = getArgument(info, 2); \ - P3 p3 = getArgument(info, 3); \ - P4 p4 = getArgument(info, 4); \ - P5 p5 = getArgument(info, 5); \ + P0 p0 = GetArgument(info, 0); \ + P1 p1 = GetArgument(info, 1); \ + P2 p2 = GetArgument(info, 2); \ + P3 p3 = GetArgument(info, 3); \ + P4 p4 = GetArgument(info, 4); \ + P5 p5 = GetArgument(info, 5); \ impl_##name(p0, p1, p2, p3, p4, p5); \ /* CC-OFFNXT(G.PRE.05) function gen */ \ - return makeVoid(info); \ + return MakeVoid(info); \ } \ MAKE_NODE_EXPORT(TS_INTEROP_MODULE, name) @@ -1117,16 +1134,16 @@ public: { \ TS_MAYBE_LOG(name) \ CallbackInfo info(env, cbinfo); \ - P0 p0 = getArgument(info, 0); \ - P1 p1 = getArgument(info, 1); \ - P2 p2 = getArgument(info, 2); \ - P3 p3 = getArgument(info, 3); \ - P4 p4 = getArgument(info, 4); \ - P5 p5 = getArgument(info, 5); \ - P6 p6 = getArgument(info, 6); \ + P0 p0 = GetArgument(info, 0); \ + P1 p1 = GetArgument(info, 1); \ + P2 p2 = GetArgument(info, 2); \ + P3 p3 = GetArgument(info, 3); \ + P4 p4 = GetArgument(info, 4); \ + P5 p5 = GetArgument(info, 5); \ + P6 p6 = GetArgument(info, 6); \ impl_##name(p0, p1, p2, p3, p4, p5, p6); \ /* CC-OFFNXT(G.PRE.05) function gen */ \ - return makeVoid(info); \ + return MakeVoid(info); \ } \ MAKE_NODE_EXPORT(TS_INTEROP_MODULE, name) @@ -1136,17 +1153,17 @@ public: { \ TS_MAYBE_LOG(name) \ CallbackInfo info(env, cbinfo); \ - P0 p0 = getArgument(info, 0); \ - P1 p1 = getArgument(info, 1); \ - P2 p2 = getArgument(info, 2); \ - P3 p3 = getArgument(info, 3); \ - P4 p4 = getArgument(info, 4); \ - P5 p5 = getArgument(info, 5); \ - P6 p6 = getArgument(info, 6); \ - P7 p7 = getArgument(info, 7); \ + P0 p0 = GetArgument(info, 0); \ + P1 p1 = GetArgument(info, 1); \ + P2 p2 = GetArgument(info, 2); \ + P3 p3 = GetArgument(info, 3); \ + P4 p4 = GetArgument(info, 4); \ + P5 p5 = GetArgument(info, 5); \ + P6 p6 = GetArgument(info, 6); \ + P7 p7 = GetArgument(info, 7); \ impl_##name(p0, p1, p2, p3, p4, p5, p6, p7); \ /* CC-OFFNXT(G.PRE.05) function gen */ \ - return makeVoid(info); \ + return MakeVoid(info); \ } \ MAKE_NODE_EXPORT(TS_INTEROP_MODULE, name) @@ -1156,18 +1173,18 @@ public: { \ TS_MAYBE_LOG(impl_##name) \ CallbackInfo info(env, cbinfo); \ - P0 p0 = getArgument(info, 0); \ - P1 p1 = getArgument(info, 1); \ - P2 p2 = getArgument(info, 2); \ - P3 p3 = getArgument(info, 3); \ - P4 p4 = getArgument(info, 4); \ - P5 p5 = getArgument(info, 5); \ - P6 p6 = getArgument(info, 6); \ - P7 p7 = getArgument(info, 7); \ - P8 p8 = getArgument(info, 8); \ + P0 p0 = GetArgument(info, 0); \ + P1 p1 = GetArgument(info, 1); \ + P2 p2 = GetArgument(info, 2); \ + P3 p3 = GetArgument(info, 3); \ + P4 p4 = GetArgument(info, 4); \ + P5 p5 = GetArgument(info, 5); \ + P6 p6 = GetArgument(info, 6); \ + P7 p7 = GetArgument(info, 7); \ + P8 p8 = GetArgument(info, 8); \ impl_##name(p0, p1, p2, p3, p4, p5, p6, p7, p8); \ /* CC-OFFNXT(G.PRE.05) function gen */ \ - return makeVoid(info); \ + return MakeVoid(info); \ } \ MAKE_NODE_EXPORT(TS_INTEROP_MODULE, name) @@ -1177,19 +1194,19 @@ public: { \ TS_MAYBE_LOG(name) \ CallbackInfo info(env, cbinfo); \ - P0 p0 = getArgument(info, 0); \ - P1 p1 = getArgument(info, 1); \ - P2 p2 = getArgument(info, 2); \ - P3 p3 = getArgument(info, 3); \ - P4 p4 = getArgument(info, 4); \ - P5 p5 = getArgument(info, 5); \ - P6 p6 = getArgument(info, 6); \ - P7 p7 = getArgument(info, 7); \ - P8 p8 = getArgument(info, 8); \ - P9 p9 = getArgument(info, 9); \ + P0 p0 = GetArgument(info, 0); \ + P1 p1 = GetArgument(info, 1); \ + P2 p2 = GetArgument(info, 2); \ + P3 p3 = GetArgument(info, 3); \ + P4 p4 = GetArgument(info, 4); \ + P5 p5 = GetArgument(info, 5); \ + P6 p6 = GetArgument(info, 6); \ + P7 p7 = GetArgument(info, 7); \ + P8 p8 = GetArgument(info, 8); \ + P9 p9 = GetArgument(info, 9); \ impl_##name(p0, p1, p2, p3, p4, p5, p6, p7, p8, p9); \ /* CC-OFFNXT(G.PRE.05) function gen */ \ - return makeVoid(info); \ + return MakeVoid(info); \ } \ MAKE_NODE_EXPORT(TS_INTEROP_MODULE, name) @@ -1199,20 +1216,20 @@ public: { \ TS_MAYBE_LOG(impl_##name) \ CallbackInfo info(env, cbinfo); \ - P0 p0 = getArgument(info, 0); \ - P1 p1 = getArgument(info, 1); \ - P2 p2 = getArgument(info, 2); \ - P3 p3 = getArgument(info, 3); \ - P4 p4 = getArgument(info, 4); \ - P5 p5 = getArgument(info, 5); \ - P6 p6 = getArgument(info, 6); \ - P7 p7 = getArgument(info, 7); \ - P8 p8 = getArgument(info, 8); \ - P9 p9 = getArgument(info, 9); \ - P10 p10 = getArgument(info, 10); \ + P0 p0 = GetArgument(info, 0); \ + P1 p1 = GetArgument(info, 1); \ + P2 p2 = GetArgument(info, 2); \ + P3 p3 = GetArgument(info, 3); \ + P4 p4 = GetArgument(info, 4); \ + P5 p5 = GetArgument(info, 5); \ + P6 p6 = GetArgument(info, 6); \ + P7 p7 = GetArgument(info, 7); \ + P8 p8 = GetArgument(info, 8); \ + P9 p9 = GetArgument(info, 9); \ + P10 p10 = GetArgument(info, 10); \ impl_##name(p0, p1, p2, p3, p4, p5, p6, p7, p8, p9, p10); \ /* CC-OFFNXT(G.PRE.05) function gen */ \ - return makeVoid(info); \ + return MakeVoid(info); \ } \ MAKE_NODE_EXPORT(TS_INTEROP_MODULE, name) @@ -1222,21 +1239,21 @@ public: { \ TS_MAYBE_LOG(impl_##name) \ CallbackInfo info(env, cbinfo); \ - P0 p0 = getArgument(info, 0); \ - P1 p1 = getArgument(info, 1); \ - P2 p2 = getArgument(info, 2); \ - P3 p3 = getArgument(info, 3); \ - P4 p4 = getArgument(info, 4); \ - P5 p5 = getArgument(info, 5); \ - P6 p6 = getArgument(info, 6); \ - P7 p7 = getArgument(info, 7); \ - P8 p8 = getArgument(info, 8); \ - P9 p9 = getArgument(info, 9); \ - P10 p10 = getArgument(info, 10); \ - P11 p11 = getArgument(info, 11); \ + P0 p0 = GetArgument(info, 0); \ + P1 p1 = GetArgument(info, 1); \ + P2 p2 = GetArgument(info, 2); \ + P3 p3 = GetArgument(info, 3); \ + P4 p4 = GetArgument(info, 4); \ + P5 p5 = GetArgument(info, 5); \ + P6 p6 = GetArgument(info, 6); \ + P7 p7 = GetArgument(info, 7); \ + P8 p8 = GetArgument(info, 8); \ + P9 p9 = GetArgument(info, 9); \ + P10 p10 = GetArgument(info, 10); \ + P11 p11 = GetArgument(info, 11); \ impl_##name(p0, p1, p2, p3, p4, p5, p6, p7, p8, p9, p10, p11); \ /* CC-OFFNXT(G.PRE.05) function gen */ \ - return makeVoid(info); \ + return MakeVoid(info); \ } \ MAKE_NODE_EXPORT(TS_INTEROP_MODULE, name) @@ -1246,22 +1263,22 @@ public: { \ TS_MAYBE_LOG(impl_##name) \ CallbackInfo info(env, cbinfo); \ - P0 p0 = getArgument(info, 0); \ - P1 p1 = getArgument(info, 1); \ - P2 p2 = getArgument(info, 2); \ - P3 p3 = getArgument(info, 3); \ - P4 p4 = getArgument(info, 4); \ - P5 p5 = getArgument(info, 5); \ - P6 p6 = getArgument(info, 6); \ - P7 p7 = getArgument(info, 7); \ - P8 p8 = getArgument(info, 8); \ - P9 p9 = getArgument(info, 9); \ - P10 p10 = getArgument(info, 10); \ - P11 p11 = getArgument(info, 11); \ - P12 p12 = getArgument(info, 12); \ + P0 p0 = GetArgument(info, 0); \ + P1 p1 = GetArgument(info, 1); \ + P2 p2 = GetArgument(info, 2); \ + P3 p3 = GetArgument(info, 3); \ + P4 p4 = GetArgument(info, 4); \ + P5 p5 = GetArgument(info, 5); \ + P6 p6 = GetArgument(info, 6); \ + P7 p7 = GetArgument(info, 7); \ + P8 p8 = GetArgument(info, 8); \ + P9 p9 = GetArgument(info, 9); \ + P10 p10 = GetArgument(info, 10); \ + P11 p11 = GetArgument(info, 11); \ + P12 p12 = GetArgument(info, 12); \ impl_##name(p0, p1, p2, p3, p4, p5, p6, p7, p8, p9, p10, p11, p12); \ /* CC-OFFNXT(G.PRE.05) function gen */ \ - return makeVoid(info); \ + return MakeVoid(info); \ } \ MAKE_NODE_EXPORT(TS_INTEROP_MODULE, name) @@ -1271,23 +1288,23 @@ public: { \ TS_MAYBE_LOG(name) \ CallbackInfo info(env, cbinfo); \ - P0 p0 = getArgument(info, 0); \ - P1 p1 = getArgument(info, 1); \ - P2 p2 = getArgument(info, 2); \ - P3 p3 = getArgument(info, 3); \ - P4 p4 = getArgument(info, 4); \ - P5 p5 = getArgument(info, 5); \ - P6 p6 = getArgument(info, 6); \ - P7 p7 = getArgument(info, 7); \ - P8 p8 = getArgument(info, 8); \ - P9 p9 = getArgument(info, 9); \ - P10 p10 = getArgument(info, 10); \ - P11 p11 = getArgument(info, 11); \ - P12 p12 = getArgument(info, 12); \ - P13 p13 = getArgument(info, 13); \ + P0 p0 = GetArgument(info, 0); \ + P1 p1 = GetArgument(info, 1); \ + P2 p2 = GetArgument(info, 2); \ + P3 p3 = GetArgument(info, 3); \ + P4 p4 = GetArgument(info, 4); \ + P5 p5 = GetArgument(info, 5); \ + P6 p6 = GetArgument(info, 6); \ + P7 p7 = GetArgument(info, 7); \ + P8 p8 = GetArgument(info, 8); \ + P9 p9 = GetArgument(info, 9); \ + P10 p10 = GetArgument(info, 10); \ + P11 p11 = GetArgument(info, 11); \ + P12 p12 = GetArgument(info, 12); \ + P13 p13 = GetArgument(info, 13); \ impl_##name(p0, p1, p2, p3, p4, p5, p6, p7, p8, p9, p10, p11, p12, p13); \ /* CC-OFFNXT(G.PRE.05) function gen */ \ - return makeVoid(info); \ + return MakeVoid(info); \ } \ MAKE_NODE_EXPORT(TS_INTEROP_MODULE, name) @@ -1297,24 +1314,24 @@ public: { \ TS_MAYBE_LOG(name) \ CallbackInfo info(env, cbinfo); \ - P0 p0 = getArgument(info, 0); \ - P1 p1 = getArgument(info, 1); \ - P2 p2 = getArgument(info, 2); \ - P3 p3 = getArgument(info, 3); \ - P4 p4 = getArgument(info, 4); \ - P5 p5 = getArgument(info, 5); \ - P6 p6 = getArgument(info, 6); \ - P7 p7 = getArgument(info, 7); \ - P8 p8 = getArgument(info, 8); \ - P9 p9 = getArgument(info, 9); \ - P10 p10 = getArgument(info, 10); \ - P11 p11 = getArgument(info, 11); \ - P12 p12 = getArgument(info, 12); \ - P13 p13 = getArgument(info, 13); \ - P14 p14 = getArgument(info, 14); \ + P0 p0 = GetArgument(info, 0); \ + P1 p1 = GetArgument(info, 1); \ + P2 p2 = GetArgument(info, 2); \ + P3 p3 = GetArgument(info, 3); \ + P4 p4 = GetArgument(info, 4); \ + P5 p5 = GetArgument(info, 5); \ + P6 p6 = GetArgument(info, 6); \ + P7 p7 = GetArgument(info, 7); \ + P8 p8 = GetArgument(info, 8); \ + P9 p9 = GetArgument(info, 9); \ + P10 p10 = GetArgument(info, 10); \ + P11 p11 = GetArgument(info, 11); \ + P12 p12 = GetArgument(info, 12); \ + P13 p13 = GetArgument(info, 13); \ + P14 p14 = GetArgument(info, 14); \ impl_##name(p0, p1, p2, p3, p4, p5, p6, p7, p8, p9, p10, p11, p12, p13, p14); \ /* CC-OFFNXT(G.PRE.05) function gen */ \ - return makeVoid(info); \ + return MakeVoid(info); \ } \ MAKE_NODE_EXPORT(TS_INTEROP_MODULE, name) @@ -1326,7 +1343,7 @@ public: CallbackInfo info(env, cbinfo); \ KVMContext ctx = reinterpret_cast((napi_env)info.Env()); \ /* CC-OFFNXT(G.PRE.05) function gen */ \ - return makeResult(info, impl_##name(ctx)); \ + return MakeResult(info, impl_##name(ctx)); \ } \ MAKE_NODE_EXPORT(TS_INTEROP_MODULE, name) @@ -1337,9 +1354,9 @@ public: TS_MAYBE_LOG(impl_##name) \ CallbackInfo info(env, cbinfo); \ KVMContext ctx = reinterpret_cast((napi_env)info.Env()); \ - P0 p0 = getArgument(info, 0); \ + P0 p0 = GetArgument(info, 0); \ /* CC-OFFNXT(G.PRE.05) function gen */ \ - return makeResult(info, impl_##name(ctx, p0)); \ + return MakeResult(info, impl_##name(ctx, p0)); \ } \ MAKE_NODE_EXPORT(TS_INTEROP_MODULE, name) @@ -1350,10 +1367,10 @@ public: TS_MAYBE_LOG(name) \ CallbackInfo info(env, cbinfo); \ KVMContext ctx = reinterpret_cast((napi_env)info.Env()); \ - P0 p0 = getArgument(info, 0); \ - P1 p1 = getArgument(info, 1); \ + P0 p0 = GetArgument(info, 0); \ + P1 p1 = GetArgument(info, 1); \ /* CC-OFFNXT(G.PRE.05) function gen */ \ - return makeResult(info, impl_##name(ctx, p0, p1)); \ + return MakeResult(info, impl_##name(ctx, p0, p1)); \ } \ MAKE_NODE_EXPORT(TS_INTEROP_MODULE, name) @@ -1364,11 +1381,11 @@ public: TS_MAYBE_LOG(name) \ CallbackInfo info(env, cbinfo); \ KVMContext ctx = reinterpret_cast((napi_env)info.Env()); \ - P0 p0 = getArgument(info, 0); \ - P1 p1 = getArgument(info, 1); \ - P2 p2 = getArgument(info, 2); \ + P0 p0 = GetArgument(info, 0); \ + P1 p1 = GetArgument(info, 1); \ + P2 p2 = GetArgument(info, 2); \ /* CC-OFFNXT(G.PRE.05) function gen */ \ - return makeResult(info, impl_##name(ctx, p0, p1, p2)); \ + return MakeResult(info, impl_##name(ctx, p0, p1, p2)); \ } \ MAKE_NODE_EXPORT(TS_INTEROP_MODULE, name) @@ -1379,12 +1396,12 @@ public: TS_MAYBE_LOG(name) \ CallbackInfo info(env, cbinfo); \ KVMContext ctx = reinterpret_cast((napi_env)info.Env()); \ - P0 p0 = getArgument(info, 0); \ - P1 p1 = getArgument(info, 1); \ - P2 p2 = getArgument(info, 2); \ - P3 p3 = getArgument(info, 3); \ + P0 p0 = GetArgument(info, 0); \ + P1 p1 = GetArgument(info, 1); \ + P2 p2 = GetArgument(info, 2); \ + P3 p3 = GetArgument(info, 3); \ /* CC-OFFNXT(G.PRE.05) function gen */ \ - return makeResult(info, impl_##name(ctx, p0, p1, p2, p3)); \ + return MakeResult(info, impl_##name(ctx, p0, p1, p2, p3)); \ } \ MAKE_NODE_EXPORT(TS_INTEROP_MODULE, name) @@ -1397,7 +1414,7 @@ public: KVMContext ctx = reinterpret_cast((napi_env)info.Env()); \ impl_##name(ctx); \ /* CC-OFFNXT(G.PRE.05) function gen */ \ - return makeVoid(info); \ + return MakeVoid(info); \ } \ MAKE_NODE_EXPORT(TS_INTEROP_MODULE, name) @@ -1408,10 +1425,10 @@ public: TS_MAYBE_LOG(name) \ CallbackInfo info(env, cbinfo); \ KVMContext ctx = reinterpret_cast((napi_env)info.Env()); \ - P0 p0 = getArgument(info, 0); \ + P0 p0 = GetArgument(info, 0); \ impl_##name(ctx, p0); \ /* CC-OFFNXT(G.PRE.05) function gen */ \ - return makeVoid(info); \ + return MakeVoid(info); \ } \ MAKE_NODE_EXPORT(TS_INTEROP_MODULE, name) @@ -1422,11 +1439,11 @@ public: TS_MAYBE_LOG(name) \ CallbackInfo info(env, cbinfo); \ KVMContext ctx = reinterpret_cast((napi_env)info.Env()); \ - P0 p0 = getArgument(info, 0); \ - P1 p1 = getArgument(info, 1); \ + P0 p0 = GetArgument(info, 0); \ + P1 p1 = GetArgument(info, 1); \ impl_##name(ctx, p0, p1); \ /* CC-OFFNXT(G.PRE.05) function gen */ \ - return makeVoid(info); \ + return MakeVoid(info); \ } \ MAKE_NODE_EXPORT(TS_INTEROP_MODULE, name) @@ -1437,12 +1454,12 @@ public: TS_MAYBE_LOG(name) \ CallbackInfo info(env, cbinfo); \ KVMContext ctx = reinterpret_cast((napi_env)info.Env()); \ - P0 p0 = getArgument(info, 0); \ - P1 p1 = getArgument(info, 1); \ - P2 p2 = getArgument(info, 2); \ + P0 p0 = GetArgument(info, 0); \ + P1 p1 = GetArgument(info, 1); \ + P2 p2 = GetArgument(info, 2); \ impl_##name(ctx, p0, p1, p2); \ /* CC-OFFNXT(G.PRE.05) function gen */ \ - return makeVoid(info); \ + return MakeVoid(info); \ } \ MAKE_NODE_EXPORT(TS_INTEROP_MODULE, name) @@ -1461,26 +1478,27 @@ public: } \ } while (0) -napi_value getKoalaNapiCallbackDispatcher(napi_env env); +napi_value GetKoalaNapiCallbackDispatcher(napi_env env); // CC-OFFNXT(G.PRE.06) solid logic #define TS_INTEROP_CALL_VOID(venv, id, length, args) \ { \ napi_env env = reinterpret_cast(venv); \ - napi_value bridge = getKoalaNapiCallbackDispatcher(env), global = nullptr, return_val = nullptr; \ + napi_value bridge = GetKoalaNapiCallbackDispatcher(env), global = nullptr, return_val = nullptr; \ napi_handle_scope scope = nullptr; \ napi_open_handle_scope(env, &scope); \ napi_status status = napi_get_global(env, &global); \ - napi_value node_args[3]; \ + std::array node_args; \ napi_create_int32(env, id, &node_args[0]); \ napi_value buffer = nullptr; \ napi_create_external_arraybuffer( \ env, args, length, [](napi_env, void *data, void *hint) {}, nullptr, &buffer); \ napi_create_typedarray(env, napi_uint8_array, length, buffer, 0, &node_args[1]); \ napi_create_int32(env, length, &node_args[2]); \ - status = napi_call_function(env, global, bridge, 3, node_args, &return_val); \ - if (status != napi_ok) \ + status = napi_call_function(env, global, bridge, 3, node_args.data(), &return_val); \ + if (status != napi_ok) { \ NODEJS_GET_AND_THROW_LAST_ERROR((env)); \ + } \ napi_close_handle_scope(env, scope); \ } @@ -1488,11 +1506,13 @@ napi_value getKoalaNapiCallbackDispatcher(napi_env env); #define TS_INTEROP_CALL_INT(venv, id, length, args) \ { \ napi_env env = reinterpret_cast(venv); \ - napi_value bridge = getKoalaNapiCallbackDispatcher(env), global = nullptr, return_val = nullptr; \ + napi_value bridge = GetKoalaNapiCallbackDispatcher(env); \ + napi_value global = nullptr; \ + napi_value return_val = nullptr; \ napi_handle_scope scope = nullptr; \ napi_open_handle_scope(env, &scope); \ napi_status status = napi_get_global(env, &global); \ - napi_value node_args[3]; \ + std::array node_args {}; \ napi_create_int32(env, id, &node_args[0]); \ napi_value buffer = nullptr; \ napi_create_external_arraybuffer( \ @@ -1500,9 +1520,10 @@ napi_value getKoalaNapiCallbackDispatcher(napi_env env); &buffer); \ napi_create_typedarray(env, napi_uint8_array, length, buffer, 0, &node_args[1]); \ napi_create_int32(env, length, &node_args[2]); \ - status = napi_call_function(env, global, bridge, 3, node_args, &return_val); \ - if (status != napi_ok) \ + status = napi_call_function(env, global, bridge, 3, node_args.data(), &return_val); \ + if (status != napi_ok) { \ NODEJS_GET_AND_THROW_LAST_ERROR((env)); \ + } \ int result; \ status = napi_get_value_int32(env, return_val, &result); \ napi_close_handle_scope(env, scope); \ @@ -1513,6 +1534,6 @@ napi_value getKoalaNapiCallbackDispatcher(napi_env env); #define TS_INTEROP_CALL_VOID_INTS32(venv, id, argc, args) TS_INTEROP_CALL_VOID(venv, id, (argc) * sizeof(int32_t), args) #define TS_INTEROP_CALL_INT_INTS32(venv, id, argc, args) TS_INTEROP_CALL_INT(venv, id, (argc) * sizeof(int32_t), args) -// NOLINTEND +// NOLINTEND(cppcoreguidelines-macro-usage) #endif // CONVERTORS_NAPI_H_ diff --git a/ets2panda/bindings/native/include/interop-logging.h b/ets2panda/bindings/native/include/interop-logging.h index b95a79146b2ff9a9b485fdd0e9dca3a793b6e32c..c31c90bdae2d62fde5b003f2ae24b8f1f62b0ca5 100644 --- a/ets2panda/bindings/native/include/interop-logging.h +++ b/ets2panda/bindings/native/include/interop-logging.h @@ -15,19 +15,29 @@ #ifndef INTEROP_LOGGING_H #define INTEROP_LOGGING_H -#include +#include #include -// NOLINTBEGIN +inline void Log(const char *msg) +{ + std::cout << msg << "\n"; +} -// CC-OFFNXT(G.PRE.09) code generation -#define LOG(msg) fprintf(stdout, msg "\n"); -// CC-OFFNXT(G.PRE.09) code generation -#define LOGI(msg, ...) fprintf(stdout, msg "\n", __VA_ARGS__); -// CC-OFFNXT(G.PRE.09) code generation -#define LOGE(msg, ...) fprintf(stderr, msg "\n", __VA_ARGS__); -// CC-OFFNXT(G.PRE.09) code generation -#define LOGE0(msg) fprintf(stderr, msg "\n"); +template +void LogI(Args &&...args) +{ + (std::cout << ... << args); + std::cout << "\n"; +} + +template +void LogE(Args &&...args) +{ + (std::cerr << ... << args); + std::cerr << "\n"; +} + +// NOLINTNEXTLINE(cppcoreguidelines-macro-usage) #define LOG_PUBLIC "" #if defined(PANDA_TARGET_WINDOWS) @@ -36,6 +46,4 @@ #define INTEROP_API_EXPORT __attribute__((visibility("default"))) #endif -// NOLINTEND - #endif // INTEROP_LOGGING_H diff --git a/ets2panda/bindings/native/include/interop-types.h b/ets2panda/bindings/native/include/interop-types.h index 2f43a9af110d274c6c14e84dd126ffc8be76ce76..4a84e8e10873ffe67654d214624c1eccc512dac3 100644 --- a/ets2panda/bindings/native/include/interop-types.h +++ b/ets2panda/bindings/native/include/interop-types.h @@ -17,10 +17,9 @@ #define INTEROP_TYPES_H_ #include +#include -// NOLINTBEGIN - -typedef enum InteropTag { +enum InteropTag { INTEROP_TAG_UNDEFINED = 101, INTEROP_TAG_INT32 = 102, INTEROP_TAG_FLOAT32 = 103, @@ -28,9 +27,9 @@ typedef enum InteropTag { INTEROP_TAG_LENGTH = 105, INTEROP_TAG_RESOURCE = 106, INTEROP_TAG_OBJECT = 107, -} InteropTag; +}; -typedef enum InteropRuntimeType { +enum InteropRuntimeType { INTEROP_RUNTIME_UNEXPECTED = -1, INTEROP_RUNTIME_NUMBER = 1, INTEROP_RUNTIME_STRING = 2, @@ -41,103 +40,103 @@ typedef enum InteropRuntimeType { INTEROP_RUNTIME_FUNCTION = 7, INTEROP_RUNTIME_SYMBOL = 8, INTEROP_RUNTIME_MATERIALIZED = 9, -} InteropRuntimeType; - -typedef float InteropFloat32; -typedef double InteropFloat64; -typedef int32_t InteropInt32; -typedef unsigned int InteropUInt32; -typedef int64_t InteropInt64; -typedef int8_t InteropInt8; -typedef uint8_t InteropUInt8; -typedef int64_t InteropDate; -typedef int8_t InteropBoolean; -typedef const char *InteropCharPtr; -typedef void *InteropNativePointer; +}; + +using InteropFloat32 = float; +using InteropFloat64 = double; +using InteropInt32 = int32_t; +using InteropUInt32 = unsigned int; +using InteropInt64 = int64_t; +using InteropInt8 = int8_t; +using InteropUInt8 = uint8_t; +using InteropDate = int64_t; +using InteropBoolean = int8_t; +using InteropCharPtr = const char *; +using InteropNativePointer = void *; struct InteropVMContextRaw; -typedef struct InteropVMContextRaw *InteropVMContext; +using InteropVMContext = InteropVMContextRaw *; struct InteropPipelineContextRaw; -typedef struct InteropPipelineContextRaw *InteropPipelineContext; +using InteropPipelineContext = InteropPipelineContextRaw *; struct InteropVMObjectRaw; -typedef struct InteropVMObjectRaw *InteropVMObject; +using InteropVMObject = InteropVMObjectRaw *; struct InteropNode; -typedef struct InteropNode *InteropNodeHandle; -typedef struct InteropDeferred { +using InteropNodeHandle = InteropNode *; +struct InteropDeferred { void *handler; void *context; void (*resolve)(struct InteropDeferred *thiz, uint8_t *data, int32_t length); void (*reject)(struct InteropDeferred *thiz, const char *message); -} InteropDeferred; +}; // Binary layout of InteropString must match that of KStringPtrImpl. -typedef struct InteropString { +struct InteropString { const char *chars; InteropInt32 length; -} InteropString; +}; -typedef struct InteropEmpty { +struct InteropEmpty { InteropInt32 dummy; // Empty structs are forbidden in C. -} InteropEmpty; +}; -typedef struct InteropNumber { +struct InteropNumber { InteropInt8 tag; union { InteropFloat32 f32; InteropInt32 i32; }; -} InteropNumber; +}; // Binary layout of InteropLength must match that of KLength. -typedef struct InteropLength { +struct InteropLength { InteropInt8 type; InteropFloat32 value; InteropInt32 unit; InteropInt32 resource; -} InteropLength; +}; -typedef struct InteropCustomObject { - char kind[20]; +const int G_INTEROP_CUSTOM_OBJECT_KIND_SIZE = 20; +const int G_UNION_CAPACITY32 = 4; +struct InteropCustomObject { + std::array kind; InteropInt32 id; // Data of custom object. union { - InteropInt32 ints[4]; - InteropFloat32 floats[4]; - void *pointers[4]; + std::array ints; + std::array floats; + std::array pointers; InteropString string; }; -} InteropCustomObject; +}; -typedef struct InteropUndefined { +struct InteropUndefined { InteropInt32 dummy; // Empty structs are forbidden in C. -} InteropUndefined; +}; -typedef struct InteropVoid { +struct InteropVoid { InteropInt32 dummy; // Empty structs are forbidden in C. -} InteropVoid; +}; -typedef struct InteropFunction { +struct InteropFunction { InteropInt32 id; -} InteropFunction; -typedef InteropFunction InteropCallback; -typedef InteropFunction InteropErrorCallback; +}; +using InteropCallback = InteropFunction; +using InteropErrorCallback = InteropFunction; -typedef struct InteropMaterialized { +struct InteropMaterialized { InteropNativePointer ptr; -} InteropMaterialized; +}; -typedef struct InteropCallbackResource { +struct InteropCallbackResource { InteropInt32 resourceId; void (*hold)(InteropInt32 resourceId); void (*release)(InteropInt32 resourceId); -} InteropCallbackResource; +}; -typedef struct InteropBuffer { +struct InteropBuffer { InteropCallbackResource resource; InteropNativePointer data; InteropInt64 length; -} InteropBuffer; - -// NOLINTEND +}; #endif // INTEROP_TYPES_H_ diff --git a/ets2panda/bindings/native/include/panda_types.h b/ets2panda/bindings/native/include/panda_types.h index cc9c3e7579985d8e445495f60d66456c436bb383..da6fcc37dd5e4c040bcd37ef5a9a0d2030c200a3 100644 --- a/ets2panda/bindings/native/include/panda_types.h +++ b/ets2panda/bindings/native/include/panda_types.h @@ -20,155 +20,183 @@ #include #include #include +#include +#include "interop-logging.h" #include "securec.h" -// NOLINTBEGIN +const unsigned int ARK_TAG_INT32 = 102U; +const unsigned int ARK_TAG_FLOAT32 = 103U; struct KStringPtrImpl { - KStringPtrImpl(const char *str) : value(nullptr), owned(true) + explicit KStringPtrImpl(const char *str) : value_(nullptr), lengthStr_(0), owned_(true) { - int len = str ? strlen(str) : 0; - assign(str, len); + int len = str != nullptr ? strlen(str) : 0; + Assign(str, len); } - KStringPtrImpl(const char *str, int len, bool isOwned) : value(nullptr), owned(isOwned) + KStringPtrImpl(const char *str, int len, bool isowned) : value_(nullptr), lengthStr_(0), owned_(isowned) { - assign(str, len); + Assign(str, len); } - KStringPtrImpl() : value(nullptr), lengthStr(0), owned(true) {} + KStringPtrImpl() : value_(nullptr), lengthStr_(0), owned_(true) {} KStringPtrImpl(const KStringPtrImpl &other) = delete; KStringPtrImpl &operator=(const KStringPtrImpl &other) = delete; KStringPtrImpl(KStringPtrImpl &&other) { - this->value = other.release(); - this->owned = other.owned; - other.owned = false; - this->lengthStr = other.lengthStr; + this->value_ = other.Release(); + this->owned_ = other.owned_; + other.owned_ = false; + this->lengthStr_ = other.lengthStr_; + } + KStringPtrImpl &operator=(KStringPtrImpl &&other) + { + this->value_ = other.Release(); + this->owned_ = other.owned_; + other.owned_ = false; + this->lengthStr_ = other.lengthStr_; + return *this; } ~KStringPtrImpl() { - if (value && owned) - free(value); + if (value_ != nullptr && owned_) { + delete[] value_; + } } - bool isNull() const + bool IsNull() const { - return value == nullptr; + return value_ == nullptr; } - const char *c_str() const + const char *CStr() const { - return value; + return value_; } - char *data() const + char *Data() const { - return value; + return value_; } - int length() const + int Length() const { - return lengthStr; + return lengthStr_; } - void resize(unsigned int size) + void Resize(unsigned int size) { - lengthStr = size; - if (!owned) + lengthStr_ = size; + if (!owned_) { return; + } // Ignore old content. - if (value && owned) - free(value); - value = reinterpret_cast(std::malloc(size + 1)); - if (value == nullptr) { + if (value_ != nullptr && owned_) { + delete[] value_; + } + value_ = new char[size + 1] {}; + if (value_ == nullptr) { // NOTE(khil): should be refactored to proper malloc return; } - value[size] = 0; } - void assign(const char *data) + void Assign(const char *data) { - assign(data, data ? strlen(data) : 0); + Assign(data, data != nullptr ? strlen(data) : 0); } - void assign(const char *data, unsigned int len) + void Assign(const char *data, unsigned int len) { - if (value && owned) - free(value); - if (data) { - if (owned) { - value = reinterpret_cast(std::malloc(len + 1)); - if (!value) { + if (value_ != nullptr && owned_) { + delete[] value_; + } + if (data != nullptr) { + if (owned_) { + value_ = new char[len + 1] {}; + if (value_ == nullptr) { return; } - memcpy_s(value, len, data, len); - value[len] = 0; + int err = memcpy_s(value_, std::strlen(value_), data, len); + const int eok = 0; + if (err != eok) { + LogE("Error: memcpy_s returned error-code"); + } } else { - value = const_cast(data); + value_ = const_cast(data); } } else { - value = nullptr; + value_ = nullptr; } - lengthStr = len; + lengthStr_ = len; } protected: - char *release() + char *Release() { - char *result = this->value; - this->value = nullptr; + char *result = this->value_; + this->value_ = nullptr; return result; } private: - char *value; - int lengthStr; - bool owned; + char *value_; + // CC-OFFNXT(G.NAM.01) project code style + int lengthStr_; + bool owned_; }; struct KInteropNumber { - int8_t tag; - union { - int32_t i32; - float f32; - }; - static inline KInteropNumber fromDouble(double value) + KInteropNumber() : value_(0) {} + static inline KInteropNumber FromDouble(double value) { - KInteropNumber result = {0, {0}}; + KInteropNumber result {}; // NOTE(khil): boundary check if (value == std::floor(value)) { - result.tag = 102U; // ARK_TAG_INT32 - result.i32 = (int)value; + result.SetTag(ARK_TAG_INT32); + result.SetValue(static_cast(value)); } else { - result.tag = 103U; // ARK_TAG_FLOAT32 - result.f32 = (float)value; + result.SetTag(ARK_TAG_FLOAT32); + result.SetValue(static_cast(value)); } return result; } - inline double asDouble() + inline double AsDouble() + { + if (tag_ == ARK_TAG_INT32) { + return static_cast(std::get(value_)); + } + return static_cast(std::get(value_)); + } + inline void SetTag(int8_t tag) + { + tag_ = tag; + } + template + void SetValue(T value) { - if (tag == 102U) // ARK_TAG_INT32 - return (double)i32; - else - return (double)f32; + value_ = value; } + +private: + std::variant value_; + // CC-OFFNXT(G.NAM.01) project code style + int8_t tag_ {0}; }; -typedef int8_t KBoolean; -typedef uint8_t KByte; -typedef int16_t KChar; -typedef int16_t KShort; -typedef uint16_t KUShort; -typedef int32_t KInt; -typedef uint32_t KUInt; -typedef float KFloat; -typedef int64_t KLong; -typedef double KDouble; -typedef void *KNativePointer; -typedef KStringPtrImpl KStringPtr; -typedef float *KFloatArray; -typedef const uint8_t *KStringArray; -typedef void **KNativePointerArray; +using KBoolean = int8_t; +using KByte = uint8_t; +using KChar = int16_t; +using KShort = int16_t; +using KUShort = uint16_t; +using KInt = int32_t; +using KUInt = uint32_t; +using KFloat = float; +using KLong = int64_t; +using KDouble = double; +using KNativePointer = void *; +using KStringPtr = KStringPtrImpl; +using KFloatArray = float *; +using KStringArray = const uint8_t *; +using KNativePointerArray = void **; struct KInteropBuffer { KLong length; @@ -196,23 +224,26 @@ inline void ParseKLength(const KStringPtrImpl &string, KLength *result) { char *suffixPtr = nullptr; - float value = std::strtof(string.c_str(), &suffixPtr); + float value = std::strtof(string.CStr(), &suffixPtr); - if (!suffixPtr || suffixPtr == string.c_str()) { + if (suffixPtr == nullptr || suffixPtr == string.CStr()) { // not a numeric value result->unit = -1; return; } result->value = value; - if (suffixPtr[0] == '\0' || (suffixPtr[0] == 'v' && suffixPtr[1] == 'p')) { + const size_t cmpOneByte = 1; + const size_t cmpTwoByte = 2; + const size_t cmpThreeByte = 3; + if (std::strncmp(suffixPtr, "\0", 1) == 0 || std::strncmp(suffixPtr, "vp", cmpTwoByte) == 0) { result->unit = 1; - } else if (suffixPtr[0] == '%') { + } else if (std::strncmp(suffixPtr, "%", cmpOneByte) == 0) { result->unit = 3U; - } else if (suffixPtr[0] == 'p' && suffixPtr[1] == 'x') { + } else if (std::strncmp(suffixPtr, "px", cmpTwoByte) == 0) { result->unit = 0; - } else if (suffixPtr[0] == 'l' && suffixPtr[1] == 'p' && suffixPtr[2U] == 'x') { + } else if (std::strncmp(suffixPtr, "lpx", cmpThreeByte) == 0) { result->unit = 4U; - } else if (suffixPtr[0] == 'f' && suffixPtr[1] == 'p') { + } else if (std::strncmp(suffixPtr, "fp", cmpTwoByte) == 0) { result->unit = 2U; } else { result->unit = -1; @@ -220,27 +251,27 @@ inline void ParseKLength(const KStringPtrImpl &string, KLength *result) } struct KVMContextRaw; -typedef KVMContextRaw *KVMContext; +using KVMContext = KVMContextRaw *; // BEWARE: this MUST never be used in user code, only in very rare service code. struct KVMObjectRaw; -typedef KVMObjectRaw *KVMObjectHandle; +using KVMObjectHandle = KVMObjectRaw *; -typedef struct KVMDeferred { +struct KVMDeferred { void *handler; void *context; void (*resolve)(KVMDeferred *thiz, uint8_t *data, int32_t length); void (*reject)(KVMDeferred *thiz, const char *message); -} KVMDeferred; +}; template -T *ptr(KNativePointer ptr) +T *Ptr(KNativePointer ptr) { return reinterpret_cast(ptr); } template -T &ref(KNativePointer ptr) +T &Ref(KNativePointer ptr) { return *reinterpret_cast(ptr); } @@ -251,11 +282,9 @@ inline KNativePointer NativePtr(void *pointer) } template -KNativePointer fnPtr(void (*pointer)(T *)) +KNativePointer FnPtr(void (*pointer)(T *)) { return reinterpret_cast(pointer); } -// NOLINTEND - #endif /* TS_TYPES_H */ diff --git a/ets2panda/bindings/native/src/bridges.cpp b/ets2panda/bindings/native/src/bridges.cpp index 19790f849e81c7860fc8d24b3c12703d2cfc05ae..54a3a39b86312aee74e83f0070beff638e414e02 100644 --- a/ets2panda/bindings/native/src/bridges.cpp +++ b/ets2panda/bindings/native/src/bridges.cpp @@ -32,7 +32,7 @@ TS_INTEROP_1(ContextProgram, KNativePointer, KNativePointer) KNativePointer impl_CreateContextFromString(KNativePointer configPtr, KStringPtr &sourcePtr, KStringPtr &filenamePtr) { auto config = reinterpret_cast(configPtr); - return GetPublicImpl()->CreateContextFromString(config, sourcePtr.data(), filenamePtr.data()); + return GetPublicImpl()->CreateContextFromString(config, sourcePtr.Data(), filenamePtr.Data()); } TS_INTEROP_3(CreateContextFromString, KNativePointer, KNativePointer, KStringPtr, KStringPtr) @@ -41,7 +41,7 @@ KInt impl_GenerateTsDeclarationsFromContext(KNativePointer contextPtr, KStringPt { auto context = reinterpret_cast(contextPtr); return static_cast(GetPublicImpl()->GenerateTsDeclarationsFromContext( - context, outputDeclEts.data(), outputEts.data(), exportAll != 0, isolated != 0)); + context, outputDeclEts.Data(), outputEts.Data(), exportAll != 0, isolated != 0)); } TS_INTEROP_5(GenerateTsDeclarationsFromContext, KInt, KNativePointer, KStringPtr, KStringPtr, KBoolean, KBoolean) diff --git a/ets2panda/bindings/native/src/callback-resource.cpp b/ets2panda/bindings/native/src/callback-resource.cpp deleted file mode 100644 index d2664f17740563d0ab4b7a97309eeaca8bc9309a..0000000000000000000000000000000000000000 --- a/ets2panda/bindings/native/src/callback-resource.cpp +++ /dev/null @@ -1,101 +0,0 @@ -/* - * Copyright (c) 2025 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "common-interop.h" -#include "callback-resource.h" -#include -#include -#include -#include - -// NOLINTBEGIN - -static bool needReleaseFront = false; -static std::deque callbackEventsQueue; -static std::deque callbackCallSubqueue; -static std::deque callbackResourceSubqueue; - -void EnqueueCallback(const CallbackBuffer *event) -{ - callbackEventsQueue.push_back(EVENT_CALL_CALLBACK); - callbackCallSubqueue.push_back(*event); -} - -void HoldManagedCallbackResource(InteropInt32 resourceId) -{ - callbackEventsQueue.push_back(EVENT_HOLD_MANAGED_RESOURCE); - callbackResourceSubqueue.push_back(resourceId); -} - -void ReleaseManagedCallbackResource(InteropInt32 resourceId) -{ - callbackEventsQueue.push_back(EVENT_RELEASE_MANAGED_RESOURCE); - callbackResourceSubqueue.push_back(resourceId); -} - -KInt impl_CheckCallbackEvent(KByte *result, [[maybe_unused]] KInt size) -{ - if (needReleaseFront) { - switch (callbackEventsQueue.front()) { - case EVENT_CALL_CALLBACK: - callbackCallSubqueue.front().resourceHolder.release(); - callbackCallSubqueue.pop_front(); - break; - case EVENT_HOLD_MANAGED_RESOURCE: - case EVENT_RELEASE_MANAGED_RESOURCE: - callbackResourceSubqueue.pop_front(); - break; - default: - throw std::runtime_error("Unknown event kind"); - } - callbackEventsQueue.pop_front(); - needReleaseFront = false; - } - if (callbackEventsQueue.empty()) { - return 0; - } - const CallbackEventKind frontEventKind = callbackEventsQueue.front(); - std::copy_n(&frontEventKind, 4U, result); - switch (frontEventKind) { - case EVENT_CALL_CALLBACK: - std::copy_n(callbackCallSubqueue.front().buffer, sizeof(CallbackBuffer::buffer), result + 4U); - break; - case EVENT_HOLD_MANAGED_RESOURCE: - case EVENT_RELEASE_MANAGED_RESOURCE: { - const InteropInt32 resourceId = callbackResourceSubqueue.front(); - std::copy_n(&resourceId, 4U, result + 4U); - break; - } - default: - throw std::runtime_error("Unknown event kind"); - } - needReleaseFront = true; - return 1; -} -TS_INTEROP_2(CheckCallbackEvent, KInt, KByte *, KInt) - -void impl_ReleaseCallbackResource(InteropInt32 resourceId) -{ - ReleaseManagedCallbackResource(resourceId); -} -TS_INTEROP_V1(ReleaseCallbackResource, KInt) - -void impl_HoldCallbackResource(InteropInt32 resourceId) -{ - HoldManagedCallbackResource(resourceId); -} -TS_INTEROP_V1(HoldCallbackResource, KInt) - -// NOLINTEND diff --git a/ets2panda/bindings/native/src/common-interop.cpp b/ets2panda/bindings/native/src/common-interop.cpp index fd418bbc797ebd3a5f428120598d26b59bccdd28..ad310140d77f40023f6af731582f5e8a62dfa95c 100644 --- a/ets2panda/bindings/native/src/common-interop.cpp +++ b/ets2panda/bindings/native/src/common-interop.cpp @@ -20,8 +20,6 @@ #include #include -// NOLINTBEGIN - #ifdef TS_INTEROP_MODULE #undef TS_INTEROP_MODULE #endif @@ -31,6 +29,7 @@ #include "convertors-napi.h" #include "common-interop.h" +// NOLINTBEGIN(cppcoreguidelines-pro-bounds-pointer-arithmetic) #if TS_INTEROP_PROFILER #include "profiler.h" @@ -43,34 +42,33 @@ using std::string; // Callback dispatcher MOVED to convertors-napi.cc. // Let's keep platform-specific parts of the code together -typedef void (*HoldT)(KInt); +using HoldT = void (*)(KInt); KInt impl_getTypeOfVariant(KNativePointer varPtr) { auto *var = reinterpret_cast *>(varPtr); if (std::get_if(var) != nullptr) { return 0; - } else { - return 1; } + return 1; } TS_INTEROP_1(getTypeOfVariant, KInt, KNativePointer) -KNativePointer impl_getStringFromVariant(KNativePointer varPtr) +KNativePointer impl_GetStringFromVariant(KNativePointer varPtr) { auto *var = reinterpret_cast *>(varPtr); auto *res = new std::string(*std::get_if(var)); return res; } -TS_INTEROP_1(getStringFromVariant, KNativePointer, KNativePointer) +TS_INTEROP_1(GetStringFromVariant, KNativePointer, KNativePointer) -KInt impl_getIntFromVariant(KNativePointer varPtr) +KInt impl_GetIntFromVariant(KNativePointer varPtr) { auto *var = reinterpret_cast *>(varPtr); auto res = *std::get_if(var); return res; } -TS_INTEROP_1(getIntFromVariant, KInt, KNativePointer) +TS_INTEROP_1(GetIntFromVariant, KInt, KNativePointer) KInteropBuffer impl_MaterializeBuffer(KNativePointer data, KLong length, KInt resourceId, KNativePointer holdPtr, KNativePointer releasePtr) @@ -106,25 +104,25 @@ TS_INTEROP_V3(StringData, KNativePointer, KByte *, KUInt) KNativePointer impl_StringMake(const KStringPtr &str) { - return new string(str.c_str()); + return new string(str.CStr()); } TS_INTEROP_1(StringMake, KNativePointer, KStringPtr) // For slow runtimes w/o fast encoders. KInt impl_ManagedStringWrite(const KStringPtr &str, KByte *buffer, KInt offset) { - memcpy_s(buffer + offset, str.length() + 1, str.c_str(), str.length() + 1); - return str.length() + 1; + memcpy_s(buffer + offset, str.Length() + 1, str.CStr(), str.Length() + 1); + return str.Length() + 1; } TS_INTEROP_3(ManagedStringWrite, KInt, KStringPtr, KByte *, KInt) -void stringFinalizer(string *ptr) +void StringFinalizer(string *ptr) { delete ptr; } KNativePointer impl_GetStringFinalizer() { - return fnPtr(stringFinalizer); + return FnPtr(StringFinalizer); } TS_INTEROP_0(GetStringFinalizer, KNativePointer) @@ -152,7 +150,11 @@ TS_INTEROP_2(GetPtrVectorElement, KNativePointer, KNativePointer, KInt) inline KUInt UnpackUInt(const KByte *bytes) { - return (bytes[0] | (bytes[1] << 8) | (bytes[2] << 16) | (bytes[3] << 24)); + const KUInt oneByte = 8U; + const KUInt twoByte = 16U; + const KUInt threeByte = 24U; + return (static_cast(bytes[0]) | (static_cast(bytes[1]) << oneByte) | + (static_cast(bytes[2]) << twoByte) | (static_cast(bytes[3]) << threeByte)); } std::vector MakeStringVector(KStringArray strArray) @@ -165,7 +167,7 @@ std::vector MakeStringVector(KStringArray strArray) size_t offset = sizeof(KUInt); for (KUInt i = 0; i < arraySize; ++i) { int len = UnpackUInt(strArray + offset); - res[i].assign((const char *)(strArray + offset + sizeof(KUInt)), len); + res[i].Assign(reinterpret_cast(strArray + offset + sizeof(KUInt)), len); offset += len + sizeof(KUInt); } return res; @@ -175,25 +177,24 @@ std::vector MakeStringVector(KNativePointerArray arr, KInt length) { if (arr == nullptr) { return std::vector(0); - } else { - std::vector res(length); - char **strings = reinterpret_cast(arr); - for (KInt i = 0; i < length; ++i) { - const char *str = reinterpret_cast(strings[i]); - res[i].assign(str); - } - return res; } + std::vector res(length); + char **strings = reinterpret_cast(arr); + for (KInt i = 0; i < length; ++i) { + const char *str = reinterpret_cast(strings[i]); + res[i].Assign(str); + } + return res; } -typedef KInt (*LoadVirtualMachine_t)(KInt vmKind, const char *classPath, const char *libraryPath, +using LoadVirtualMachineT = KInt (*)(KInt vmKind, const char *classPath, const char *libraryPath, void *currentVMContext); -typedef KNativePointer (*StartApplication_t)(const char *appUrl, const char *appParams); -typedef KBoolean (*RunApplication_t)(const KInt arg0, const KInt arg1); -typedef void (*EmitEventT)(const KInt type, const KInt target, const KInt arg0, const KInt arg1); +using StartApplicationT = KNativePointer (*)(const char *appUrl, const char *appParams); +using RunApplicationT = KBoolean (*)(const KInt arg0, const KInt arg1); +using EmitEventT = void (*)(const KInt type, const KInt target, const KInt arg0, const KInt arg1); static CallbackCallert g_callbackCaller = nullptr; -void setCallbackCaller(CallbackCallert callbackCaller) +void SetCallbackCaller(CallbackCallert callbackCaller) { g_callbackCaller = callbackCaller; } @@ -207,14 +208,14 @@ void impl_CallCallback(KInt callbackKind, KByte *args, KInt argsSize) TS_INTEROP_V3(CallCallback, KInt, KByte *, KInt) static CallbackCallerSynct g_callbackCallerSync = nullptr; -void setCallbackCallerSync(CallbackCallerSynct callbackCallerSync) +void SetCallbackCallerSync(CallbackCallerSynct callbackCallerSync) { g_callbackCallerSync = callbackCallerSync; } void impl_CallCallbackSync(KVMContext vmContext, KInt callbackKind, KByte *args, KInt argsSize) { - if (g_callbackCallerSync) { + if (g_callbackCallerSync != nullptr) { g_callbackCallerSync(vmContext, callbackKind, args, argsSize); } } @@ -232,86 +233,93 @@ void impl_CallCallbackResourceReleaser(KNativePointer releaser, KInt resourceId) } TS_INTEROP_V2(CallCallbackResourceReleaser, KNativePointer, KInt) +// NOLINTBEGIN(cppcoreguidelines-macro-usage) + // CC-OFFNXT(G.EXP.01) false positive #define __QUOTE(x) #x #define QUOTE(x) __QUOTE(x) +// NOLINTEND(cppcoreguidelines-macro-usage) + #ifndef INTEROP_LIBRARY_NAME #error "INTEROP_LIBRARY_NAME must be defined" #endif void impl_NativeLog(const KStringPtr &str) { - fprintf(stdout, "%s: %s\n", QUOTE(INTEROP_LIBRARY_NAME), str.c_str()); - fflush(stdout); + std::cout << QUOTE(INTEROP_LIBRARY_NAME) << ": " << str.CStr() << std::endl; } TS_INTEROP_V1(NativeLog, KStringPtr) -int32_t callCallback(KVMContext context, int32_t methodId, uint8_t *argsData, int32_t argsLength) +int32_t CallCallback(KVMContext context, int32_t methodId, uint8_t *argsData, int32_t argsLength) { TS_INTEROP_CALL_INT(context, methodId, argsLength, argsData); return 0; } -void resolveDeferred(KVMDeferred *deferred, [[maybe_unused]] uint8_t *argsData, [[maybe_unused]] int32_t argsLength) +void ResolveDeferred(KVMDeferred *deferred, [[maybe_unused]] uint8_t *argsData, [[maybe_unused]] int32_t argsLength) { - napi_acquire_threadsafe_function((napi_threadsafe_function)deferred->handler); - auto status = - napi_call_threadsafe_function((napi_threadsafe_function)deferred->handler, deferred, napi_tsfn_nonblocking); - if (status != napi_ok) - LOGE("cannot call thread-safe function; status=%d", status); - napi_release_threadsafe_function((napi_threadsafe_function)deferred->handler, napi_tsfn_release); + napi_acquire_threadsafe_function(static_cast(deferred->handler)); + auto status = napi_call_threadsafe_function(static_cast(deferred->handler), deferred, + napi_tsfn_nonblocking); + if (status != napi_ok) { + LogE("cannot call thread-safe function; status=", status); + } + napi_release_threadsafe_function(static_cast(deferred->handler), napi_tsfn_release); } -void rejectDeferred(KVMDeferred *deferred, [[maybe_unused]] const char *message) +void RejectDeferred(KVMDeferred *deferred, [[maybe_unused]] const char *message) { - napi_release_threadsafe_function((napi_threadsafe_function)deferred->handler, napi_tsfn_release); + napi_release_threadsafe_function(static_cast(deferred->handler), napi_tsfn_release); delete deferred; } -void resolveDeferredImpl(napi_env env, [[maybe_unused]] napi_value js_callback, KVMDeferred *deferred, +void ResolveDeferredImpl(napi_env env, [[maybe_unused]] napi_value jsCallback, KVMDeferred *deferred, [[maybe_unused]] void *data) { napi_value undefined = nullptr; napi_get_undefined(env, &undefined); - auto status = napi_resolve_deferred(env, (napi_deferred)deferred->context, undefined); - if (status != napi_ok) - LOGE("cannot resolve deferred; status=%d", status); + auto status = napi_resolve_deferred(env, reinterpret_cast(deferred->context), undefined); + if (status != napi_ok) { + LogE("cannot resolve deferred; status=", status); + } delete deferred; } -[[maybe_unused]] static void releaseDeferred(KVMDeferred *deferred) +[[maybe_unused]] static void ReleaseDeferred(KVMDeferred *deferred) { delete deferred; } KVMDeferred *CreateDeferred(KVMContext vmContext, KVMObjectHandle *promiseHandle) { - KVMDeferred *deferred = new KVMDeferred(); - deferred->resolve = resolveDeferred; - deferred->reject = rejectDeferred; + auto *deferred = new KVMDeferred(); + deferred->resolve = ResolveDeferred; + deferred->reject = RejectDeferred; // NOTE(khil): mb move\remove to interop! - napi_env env = (napi_env)vmContext; + auto env = reinterpret_cast(vmContext); napi_value promise; napi_value resourceName; size_t napiStrLen = 5; napi_create_string_utf8(env, "Async", napiStrLen, &resourceName); - auto status = napi_create_promise(env, (napi_deferred *)&deferred->context, &promise); - if (status != napi_ok) - LOGE("cannot make a promise; status=%d", status); + auto status = napi_create_promise(env, reinterpret_cast(&deferred->context), &promise); + if (status != napi_ok) { + LogE("cannot make a promise; status=", status); + } status = napi_create_threadsafe_function(env, nullptr, nullptr, resourceName, 0, 1, nullptr, nullptr, deferred, - (napi_threadsafe_function_call_js)resolveDeferredImpl, - (napi_threadsafe_function *)&deferred->handler); - if (status != napi_ok) - LOGE("cannot make threadsafe function; status=%d", status); - *promiseHandle = (KVMObjectHandle)promise; + reinterpret_cast(ResolveDeferredImpl), + reinterpret_cast(&deferred->handler)); + if (status != napi_ok) { + LogE("cannot make threadsafe function; status=", status); + } + *promiseHandle = reinterpret_cast(promise); return deferred; } // Allocate, so CTX versions. KStringPtr impl_Utf8ToString([[maybe_unused]] KVMContext vmContext, KByte *data, KInt offset, KInt length) { - KStringPtr result((const char *)(data + offset), length, false); + KStringPtr result(reinterpret_cast(data + offset), length, false); return result; } TS_INTEROP_CTX_3(Utf8ToString, KStringPtr, KByte *, KInt, KInt) @@ -328,9 +336,9 @@ KInteropReturnBuffer impl_RawReturnData([[maybe_unused]] KVMContext vmContext, K { void *data = new int8_t[v1]; memset_s(data, v2, v1, v2); - KInteropReturnBuffer buffer = {v1, data, [](KNativePointer ptr, KInt) { delete[](int8_t *) ptr; }}; + KInteropReturnBuffer buffer = {v1, data, + [](KNativePointer ptr, KInt) { delete[] reinterpret_cast(ptr); }}; return buffer; } TS_INTEROP_CTX_2(RawReturnData, KInteropReturnBuffer, KInt, KInt) - -// NOLINTEND +// NOLINTEND(cppcoreguidelines-pro-bounds-pointer-arithmetic) diff --git a/ets2panda/bindings/native/src/common.cpp b/ets2panda/bindings/native/src/common.cpp index 7bc499ea450df7025d1792365cdbe0873ca271e2..fa594a9b17d939a27cddf022364de7f185147025 100644 --- a/ets2panda/bindings/native/src/common.cpp +++ b/ets2panda/bindings/native/src/common.cpp @@ -19,11 +19,9 @@ #include "public/es2panda_lib.h" #include "dynamic-loader.h" -// NOLINTBEGIN - using std::string, std::cout, std::endl, std::vector; -static es2panda_Impl const *impl = nullptr; +static es2panda_Impl const *g_impl = nullptr; #ifdef _WIN32 #include @@ -52,7 +50,7 @@ void *FindLibrary() if (envValue) { libraryName = string(envValue) + ("/" PLUGIN_DIR "/lib/") + LIB_ES2PANDA_PUBLIC; } else { - if (g_pandaLibPath == "") { + if (g_pandaLibPath.empty()) { libraryName = LIB_ES2PANDA_PUBLIC; } else { libraryName = g_pandaLibPath + "/" + LIB_ES2PANDA_PUBLIC; @@ -63,51 +61,57 @@ void *FindLibrary() const es2panda_Impl *GetPublicImpl() { - if (impl) { - return impl; + if (g_impl != nullptr) { + return g_impl; } auto library = FindLibrary(); - if (!library) { + if (library == nullptr) { std::cout << "Cannot find " << LIB_ES2PANDA_PUBLIC << endl; } auto symbol = FindSymbol(library, "es2panda_GetImpl"); - if (!symbol) { + if (symbol == nullptr) { std::cout << "Cannot find Impl Entry point" << endl; } - impl = reinterpret_cast(symbol)(ES2PANDA_LIB_VERSION); - return impl; + g_impl = reinterpret_cast(symbol)(ES2PANDA_LIB_VERSION); + return g_impl; } std::string GetString(KStringPtr ptr) { - return ptr.data(); + return ptr.Data(); } char *GetStringCopy(KStringPtr &ptr) { - return strdup(ptr.c_str()); + return strdup(ptr.CStr()); } inline KUInt UnpackUInt(const KByte *bytes) { - return (bytes[0] | (bytes[1] << 8U) | (bytes[2U] << 16U) | (bytes[3U] << 24U)); + const KUInt oneByte = 8U; + const KUInt twoByte = 16U; + const KUInt threeByte = 24U; + return (static_cast(bytes[0]) | (static_cast(bytes[1]) << oneByte) | + (static_cast(bytes[twoByte / oneByte]) << twoByte) | + (static_cast(bytes[threeByte / oneByte]) << threeByte)); } inline std::string_view GetStringView(KStringPtr &ptr) { - return std::string_view(ptr.c_str(), static_cast(ptr.length())); + return std::string_view(ptr.CStr(), static_cast(ptr.Length())); } KNativePointer impl_CreateConfig(KInt argc, KStringArray argvPtr, KStringPtr &pandaLibPath) { - const std::size_t HEADER_LEN = 4; + const std::size_t headerLen = 4; g_pandaLibPath = GetStringView(pandaLibPath); + const char **argv = new const char *[static_cast(argc)]; - std::size_t position = HEADER_LEN; + std::size_t position = headerLen; std::size_t strLen; for (std::size_t i = 0; i < static_cast(argc); ++i) { strLen = UnpackUInt(argvPtr + position); - position += HEADER_LEN; + position += headerLen; argv[i] = strdup(std::string(reinterpret_cast(argvPtr + position), strLen).c_str()); position += strLen; } @@ -180,7 +184,7 @@ KNativePointer impl_CreateCacheContextFromString(KNativePointer configPtr, KStri { auto config = reinterpret_cast(configPtr); auto context = reinterpret_cast(globalContext); - return GetPublicImpl()->CreateCacheContextFromString(config, sourcePtr.data(), filenamePtr.data(), context, + return GetPublicImpl()->CreateCacheContextFromString(config, sourcePtr.Data(), filenamePtr.Data(), context, isExternal); } TS_INTEROP_5(CreateCacheContextFromString, KNativePointer, KNativePointer, KStringPtr, KStringPtr, KNativePointer, @@ -189,21 +193,20 @@ TS_INTEROP_5(CreateCacheContextFromString, KNativePointer, KNativePointer, KStri void impl_RemoveFileCache(KNativePointer globalContextPtr, KStringPtr &filenamePtr) { auto context = reinterpret_cast(globalContextPtr); - return GetPublicImpl()->RemoveFileCache(context, filenamePtr.data()); + return GetPublicImpl()->RemoveFileCache(context, filenamePtr.Data()); } TS_INTEROP_V2(RemoveFileCache, KNativePointer, KStringPtr) void impl_AddFileCache(KNativePointer globalContextPtr, KStringPtr &filenamePtr) { auto context = reinterpret_cast(globalContextPtr); - return GetPublicImpl()->AddFileCache(context, filenamePtr.data()); + return GetPublicImpl()->AddFileCache(context, filenamePtr.Data()); } TS_INTEROP_V2(AddFileCache, KNativePointer, KStringPtr) void impl_InvalidateFileCache(KNativePointer globalContextPtr, KStringPtr &filenamePtr) { auto context = reinterpret_cast(globalContextPtr); - return GetPublicImpl()->InvalidateFileCache(context, filenamePtr.data()); + return GetPublicImpl()->InvalidateFileCache(context, filenamePtr.Data()); } TS_INTEROP_V2(InvalidateFileCache, KNativePointer, KStringPtr) -// NOLINTEND diff --git a/ets2panda/bindings/native/src/convertors-napi.cpp b/ets2panda/bindings/native/src/convertors-napi.cpp index d2b553e787deb0f500e3612cb88e7a48331326cc..4a44de21d1088d1eb075665b90fa3f023e13ff1d 100644 --- a/ets2panda/bindings/native/src/convertors-napi.cpp +++ b/ets2panda/bindings/native/src/convertors-napi.cpp @@ -20,7 +20,7 @@ #include "interop-logging.h" #include "convertors-napi.h" -// NOLINTBEGIN +// NOLINTBEGIN(cppcoreguidelines-macro-usage) // Adapter for NAPI_MODULE #define NODE_API_MODULE_ADAPTER(modname, regfunc) \ @@ -31,7 +31,9 @@ } \ NAPI_MODULE(modname, __napi_##regfunc) -napi_valuetype getValueTypeChecked(napi_env env, napi_value value) +// NOLINTEND(cppcoreguidelines-macro-usage) + +napi_valuetype GetValueTypeChecked(napi_env env, napi_value value) { napi_valuetype type; napi_status status = napi_typeof(env, value, &type); @@ -39,7 +41,7 @@ napi_valuetype getValueTypeChecked(napi_env env, napi_value value) return type; } -bool isTypedArray(napi_env env, napi_value value) +bool IsTypedArray(napi_env env, napi_value value) { bool result = false; napi_status status = napi_is_typedarray(env, value, &result); @@ -47,19 +49,19 @@ bool isTypedArray(napi_env env, napi_value value) return result; } -KBoolean getBoolean(napi_env env, napi_value value) +KBoolean GetBoolean(napi_env env, napi_value value) { - if (getValueTypeChecked(env, value) == napi_valuetype::napi_boolean) { + if (GetValueTypeChecked(env, value) == napi_valuetype::napi_boolean) { bool result = false; napi_get_value_bool(env, value, &result); return static_cast(result); } - return static_cast(getInt32(env, value) != 0); + return static_cast(GetInt32(env, value) != 0); } -KInt getInt32(napi_env env, napi_value value) +KInt GetInt32(napi_env env, napi_value value) { - if (getValueTypeChecked(env, value) != napi_valuetype::napi_number) { + if (GetValueTypeChecked(env, value) != napi_valuetype::napi_number) { napi_throw_error(env, nullptr, "Expected Number"); return 0; } @@ -68,9 +70,9 @@ KInt getInt32(napi_env env, napi_value value) return static_cast(result); } -KUInt getUInt32(napi_env env, napi_value value) +KUInt GetUInt32(napi_env env, napi_value value) { - if (getValueTypeChecked(env, value) != napi_valuetype::napi_number) { + if (GetValueTypeChecked(env, value) != napi_valuetype::napi_number) { napi_throw_error(env, nullptr, "Expected Number"); return 0; } @@ -79,9 +81,9 @@ KUInt getUInt32(napi_env env, napi_value value) return static_cast(result); } -KFloat getFloat32(napi_env env, napi_value value) +KFloat GetFloat32(napi_env env, napi_value value) { - if (getValueTypeChecked(env, value) != napi_valuetype::napi_number) { + if (GetValueTypeChecked(env, value) != napi_valuetype::napi_number) { napi_throw_error(env, nullptr, "Expected Number"); return 0.0F; } @@ -90,9 +92,9 @@ KFloat getFloat32(napi_env env, napi_value value) return static_cast(static_cast(result)); } -KDouble getFloat64(napi_env env, napi_value value) +KDouble GetFloat64(napi_env env, napi_value value) { - if (getValueTypeChecked(env, value) != napi_valuetype::napi_number) { + if (GetValueTypeChecked(env, value) != napi_valuetype::napi_number) { napi_throw_error(env, nullptr, "Expected Number"); return 0.0; } @@ -101,10 +103,10 @@ KDouble getFloat64(napi_env env, napi_value value) return static_cast(result); } -KStringPtr getString(napi_env env, napi_value value) +KStringPtr GetString(napi_env env, napi_value value) { KStringPtr result {}; - napi_valuetype valueType = getValueTypeChecked(env, value); + napi_valuetype valueType = GetValueTypeChecked(env, value); if (valueType == napi_valuetype::napi_null || valueType == napi_valuetype::napi_undefined) { return result; } @@ -119,15 +121,16 @@ KStringPtr getString(napi_env env, napi_value value) if (status != 0) { return result; } - result.resize(length); - status = napi_get_value_string_utf8(env, value, result.data(), length + 1, nullptr); - TS_NAPI_THROW_IF_FAILED(env, status, nullptr); + result.Resize(length); + status = napi_get_value_string_utf8(env, value, result.Data(), length + 1, nullptr); + TS_NAPI_THROW_IF_FAILED(env, status, KStringPtr(nullptr)); + return result; } -KNativePointer getPointer(napi_env env, napi_value value) +KNativePointer GetPointer(napi_env env, napi_value value) { - napi_valuetype valueType = getValueTypeChecked(env, value); + napi_valuetype valueType = GetValueTypeChecked(env, value); if (valueType == napi_valuetype::napi_external) { KNativePointer result = nullptr; napi_status status = napi_get_value_external(env, value, &result); @@ -151,9 +154,9 @@ KNativePointer getPointer(napi_env env, napi_value value) return reinterpret_cast(ptrU64); } -KLong getInt64(napi_env env, napi_value value) +KLong GetInt64(napi_env env, napi_value value) { - if (getValueTypeChecked(env, value) != napi_valuetype::napi_bigint) { + if (GetValueTypeChecked(env, value) != napi_valuetype::napi_bigint) { napi_throw_error(env, nullptr, "cannot be coerced to int64"); return -1; } @@ -168,15 +171,15 @@ KLong getInt64(napi_env env, napi_value value) return static_cast(ptr64); } -napi_value makeString(napi_env env, const KStringPtr &value) +napi_value MakeString(napi_env env, const KStringPtr &value) { napi_value result; - napi_status status = napi_create_string_utf8(env, value.isNull() ? "" : value.data(), value.length(), &result); + napi_status status = napi_create_string_utf8(env, value.IsNull() ? "" : value.Data(), value.Length(), &result); TS_NAPI_THROW_IF_FAILED(env, status, result); return result; } -napi_value makeString(napi_env env, const std::string &value) +napi_value MakeString(napi_env env, const std::string &value) { napi_value result; napi_status status = napi_create_string_utf8(env, value.c_str(), value.length(), &result); @@ -184,7 +187,7 @@ napi_value makeString(napi_env env, const std::string &value) return result; } -napi_value makeBoolean(napi_env env, int8_t value) +napi_value MakeBoolean(napi_env env, int8_t value) { napi_value result; napi_status status = napi_get_boolean(env, value != 0, &result); @@ -192,7 +195,7 @@ napi_value makeBoolean(napi_env env, int8_t value) return result; } -napi_value makeInt32(napi_env env, int32_t value) +napi_value MakeInt32(napi_env env, int32_t value) { napi_value result; napi_status status = napi_create_int32(env, value, &result); @@ -200,7 +203,7 @@ napi_value makeInt32(napi_env env, int32_t value) return result; } -napi_value makeUInt32(napi_env env, uint32_t value) +napi_value MakeUInt32(napi_env env, uint32_t value) { napi_value result; napi_status status = napi_create_uint32(env, value, &result); @@ -208,7 +211,7 @@ napi_value makeUInt32(napi_env env, uint32_t value) return result; } -napi_value makeFloat32(napi_env env, float value) +napi_value MakeFloat32(napi_env env, float value) { napi_value result; napi_status status = napi_create_double(env, value, &result); @@ -216,7 +219,7 @@ napi_value makeFloat32(napi_env env, float value) return result; } -napi_value makePointer(napi_env env, void *value) +napi_value MakePointer(napi_env env, void *value) { napi_value result; napi_status status = @@ -225,7 +228,7 @@ napi_value makePointer(napi_env env, void *value) return result; } -napi_value makeVoid(napi_env env) +napi_value MakeVoid(napi_env env) { napi_value result; napi_status status = napi_get_undefined(env, &result); @@ -233,7 +236,7 @@ napi_value makeVoid(napi_env env) return result; } -napi_value makeObject(napi_env env, [[maybe_unused]] napi_value object) +napi_value MakeObject(napi_env env, [[maybe_unused]] napi_value object) { napi_value result; napi_status status = napi_create_object(env, &result); @@ -246,7 +249,7 @@ napi_value makeObject(napi_env env, [[maybe_unused]] napi_value object) #pragma comment(linker, "/alternatename:__imp___std_init_once_begin_initialize=__imp_InitOnceBeginInitialize") #endif -Exports *Exports::getInstance() +Exports *Exports::GetInstance() { static Exports *instance = nullptr; if (instance == nullptr) { @@ -255,30 +258,30 @@ Exports *Exports::getInstance() return instance; } -std::vector Exports::getModules() +std::vector Exports::GetModules() { std::vector result; - for (auto it = implementations.begin(); it != implementations.end(); ++it) { - result.push_back(it->first); + for (auto &it : implementations_) { + result.push_back(it.first); } return result; } -void Exports::addMethod(const char *module, const char *name, napi_type_t impl) +void Exports::addMethod(const char *module, const char *name, NapiTypeT impl) { - auto it = implementations.find(module); - if (it == implementations.end()) { - it = implementations.insert(std::make_pair(module, std::vector>())).first; + auto it = implementations_.find(module); + if (it == implementations_.end()) { + it = implementations_.insert(std::make_pair(module, std::vector>())).first; } - it->second.push_back(std::make_pair(name, impl)); + it->second.emplace_back(std::make_pair(name, impl)); } -const std::vector> &Exports::getMethods(const std::string &module) +const std::vector> &Exports::GetMethods(const std::string &module) { - auto it = implementations.find(module); - if (it == implementations.end()) { - LOGE("Module %s is not registered", module.c_str()); - throw "Fatal error"; + auto it = implementations_.find(module); + if (it == implementations_.end()) { + LogE("Module", module.c_str(), "is not registered"); + throw std::runtime_error("Fatal error"); } return it->second; } @@ -296,7 +299,7 @@ napi_value Node_SetCallbackDispatcher(napi_env env, napi_callback_info cbinfo) { CallbackInfo info(env, cbinfo); napi_value dispatcher = info[0]; - napi_value result = makeVoid(env); + napi_value result = MakeVoid(env); napi_status status = napi_create_reference(env, dispatcher, 1, &g_koalaNapiCallbackDispatcher); TS_NAPI_THROW_IF_FAILED(env, status, result); @@ -306,8 +309,8 @@ MAKE_NODE_EXPORT(TS_INTEROP_MODULE, SetCallbackDispatcher) napi_value Node_CleanCallbackDispatcher(napi_env env, [[maybe_unused]] napi_callback_info cbinfo) { - napi_value result = makeVoid(env); - if (g_koalaNapiCallbackDispatcher) { + napi_value result = MakeVoid(env); + if (g_koalaNapiCallbackDispatcher != nullptr) { napi_status status = napi_delete_reference(env, g_koalaNapiCallbackDispatcher); g_koalaNapiCallbackDispatcher = nullptr; TS_NAPI_THROW_IF_FAILED(env, status, result); @@ -316,14 +319,14 @@ napi_value Node_CleanCallbackDispatcher(napi_env env, [[maybe_unused]] napi_call } MAKE_NODE_EXPORT(TS_INTEROP_MODULE, CleanCallbackDispatcher) -napi_value getKoalaNapiCallbackDispatcher(napi_env env) +napi_value GetKoalaNapiCallbackDispatcher(napi_env env) { - if (!g_koalaNapiCallbackDispatcher) { + if (g_koalaNapiCallbackDispatcher == nullptr) { abort(); } napi_value value; napi_status status = napi_get_reference_value(env, g_koalaNapiCallbackDispatcher, &value); - TS_NAPI_THROW_IF_FAILED(env, status, makeVoid(env)); + TS_NAPI_THROW_IF_FAILED(env, status, MakeVoid(env)); return value; } @@ -349,10 +352,10 @@ static constexpr bool SPLIT_MODULES = true; static napi_value InitModule(napi_env env, napi_value exports) { - Exports *inst = Exports::getInstance(); + Exports *inst = Exports::GetInstance(); napi_status status; napi_value target = exports; - for (const auto &module : inst->getModules()) { + for (const auto &module : inst->GetModules()) { if (SPLIT_MODULES) { status = napi_create_object(env, &target); TS_NAPI_THROW_IF_FAILED(env, status, exports); @@ -360,7 +363,7 @@ static napi_value InitModule(napi_env env, napi_value exports) TS_NAPI_THROW_IF_FAILED(env, status, exports); } - for (const auto &impl : inst->getMethods(module)) { + for (const auto &impl : inst->GetMethods(module)) { napi_value implFunc; status = napi_create_function(env, impl.first.c_str(), 0, impl.second, nullptr, &implFunc); TS_NAPI_THROW_IF_FAILED(env, status, exports); @@ -372,5 +375,3 @@ static napi_value InitModule(napi_env env, napi_value exports) } NAPI_MODULE(INTEROP_LIBRARY_NAME, InitModule) - -// NOLINTEND diff --git a/ets2panda/bindings/native/src/generated/bridges.cpp b/ets2panda/bindings/native/src/generated/bridges.cpp index 5484e3dcefda93fec3a6d6139fa799004b09a421..cdd977e8c70472ce3e2a48ce8028f747a6f1357c 100644 --- a/ets2panda/bindings/native/src/generated/bridges.cpp +++ b/ets2panda/bindings/native/src/generated/bridges.cpp @@ -16,8 +16,6 @@ #include #include "public/es2panda_lib.h" -// NOLINTBEGIN - // CC-OFFNXT(G.FUN.01-CPP) solid logic KNativePointer impl_CreateMemberExpression(KNativePointer context, KNativePointer objectArg, KNativePointer property, KInt kind, KBoolean computed, KBoolean optionalArg) @@ -39,15 +37,15 @@ TS_INTEROP_6(CreateMemberExpression, KNativePointer, KNativePointer, KNativePoin KNativePointer impl_UpdateMemberExpression(KNativePointer context, KNativePointer original, KNativePointer object_arg, KNativePointer property, KInt kind, KBoolean computed, KBoolean optional_arg) { - const auto _context = reinterpret_cast(context); - const auto _original = reinterpret_cast(original); - const auto _object_arg = reinterpret_cast(object_arg); - const auto _property = reinterpret_cast(property); - const auto _kind = static_cast(kind); - const auto _computed = static_cast(computed); - const auto _optional_arg = static_cast(optional_arg); - const auto result = GetPublicImpl()->UpdateMemberExpression(_context, _original, _object_arg, _property, _kind, - _computed, _optional_arg); + const auto newContext = reinterpret_cast(context); + const auto newOriginal = reinterpret_cast(original); + const auto newObjectArg = reinterpret_cast(object_arg); + const auto newProperty = reinterpret_cast(property); + const auto newKind = static_cast(kind); + const auto newComputed = static_cast(computed); + const auto newOptionalArg = static_cast(optional_arg); + const auto result = GetPublicImpl()->UpdateMemberExpression(newContext, newOriginal, newObjectArg, newProperty, + newKind, newComputed, newOptionalArg); return result; } // CC-OFFNXT(G.FUN.01-CPP) solid logic @@ -56,29 +54,27 @@ TS_INTEROP_7(UpdateMemberExpression, KNativePointer, KNativePointer, KNativePoin KNativePointer impl_MemberExpressionObject(KNativePointer context, KNativePointer receiver) { - const auto _context = reinterpret_cast(context); - const auto _receiver = reinterpret_cast(receiver); - const auto result = GetPublicImpl()->MemberExpressionObject(_context, _receiver); + const auto newContext = reinterpret_cast(context); + const auto newReceiver = reinterpret_cast(receiver); + const auto result = GetPublicImpl()->MemberExpressionObject(newContext, newReceiver); return result; } TS_INTEROP_2(MemberExpressionObject, KNativePointer, KNativePointer, KNativePointer) KNativePointer impl_MemberExpressionProperty(KNativePointer context, KNativePointer receiver) { - const auto _context = reinterpret_cast(context); - const auto _receiver = reinterpret_cast(receiver); - const auto result = GetPublicImpl()->MemberExpressionProperty(_context, _receiver); + const auto newContext = reinterpret_cast(context); + const auto newReceiver = reinterpret_cast(receiver); + const auto result = GetPublicImpl()->MemberExpressionProperty(newContext, newReceiver); return result; } TS_INTEROP_2(MemberExpressionProperty, KNativePointer, KNativePointer, KNativePointer) KInt impl_MemberExpressionKindConst(KNativePointer context, KNativePointer receiver) { - const auto _context = reinterpret_cast(context); - const auto _receiver = reinterpret_cast(receiver); - const auto result = GetPublicImpl()->MemberExpressionKindConst(_context, _receiver); + const auto newContext = reinterpret_cast(context); + const auto newReceiver = reinterpret_cast(receiver); + const auto result = GetPublicImpl()->MemberExpressionKindConst(newContext, newReceiver); return result; } TS_INTEROP_2(MemberExpressionKindConst, KInt, KNativePointer, KNativePointer) - -// NOLINTEND diff --git a/ets2panda/bindings/native/src/lsp.cpp b/ets2panda/bindings/native/src/lsp.cpp index 95a5fd779514ee81c73ddd7ad7b24dc1c6bba506..5e419cd36348c24ce3aa6fbbbc72ab81819f49e0 100644 --- a/ets2panda/bindings/native/src/lsp.cpp +++ b/ets2panda/bindings/native/src/lsp.cpp @@ -32,7 +32,7 @@ using ark::es2panda::lsp::ClassPropertyItem; char *GetStringCopy(KStringPtr &ptr) { - return strdup(ptr.c_str()); + return strdup(ptr.CStr()); } KNativePointer impl_getCurrentTokenValue(KNativePointer context, KInt position) @@ -792,19 +792,19 @@ KNativePointer impl_getDefinitionAtPosition(KNativePointer context, KInt positio } TS_INTEROP_2(getDefinitionAtPosition, KNativePointer, KNativePointer, KInt) -KNativePointer impl_getFileNameFromDef(KNativePointer defPtr) +KNativePointer impl_GetFileNameFromDef(KNativePointer defPtr) { auto *defInfo = reinterpret_cast(defPtr); return new std::string(defInfo->fileName); } -TS_INTEROP_1(getFileNameFromDef, KNativePointer, KNativePointer) +TS_INTEROP_1(GetFileNameFromDef, KNativePointer, KNativePointer) -KInt impl_getStartFromDef(KNativePointer defPtr) +KInt impl_GetStartFromDef(KNativePointer defPtr) { auto *defInfo = reinterpret_cast(defPtr); return defInfo->start; } -TS_INTEROP_1(getStartFromDef, KInt, KNativePointer) +TS_INTEROP_1(GetStartFromDef, KInt, KNativePointer) KInt impl_getLengthFromDef(KNativePointer defPtr) { diff --git a/ets2panda/bindings/native/src/win-dynamic-node.cpp b/ets2panda/bindings/native/src/win-dynamic-node.cpp index 85bb3cb4da61e7cde2ee782aefb8d404b7c9bb18..5e484955b7e31d4a05d326a2f08d69e3195673de 100644 --- a/ets2panda/bindings/native/src/win-dynamic-node.cpp +++ b/ets2panda/bindings/native/src/win-dynamic-node.cpp @@ -149,11 +149,11 @@ NAPI_EXTERN napi_status NAPI_CDECL napi_is_typedarray(napi_env env, napi_value v } // CC-OFFNXT(G.FUN.01, huge_method) solid logic -NAPI_EXTERN napi_status NAPI_CDECL napi_add_finalizer(napi_env env, napi_value js_object, void *finalize_data, - napi_finalize finalize_cb, void *finalize_hint, napi_ref *result) +NAPI_EXTERN napi_status NAPI_CDECL napi_add_finalizer(napi_env env, napi_value js_object, void *FinalizeData, + napi_finalize finalize_cb, void *FinalizeHint, napi_ref *result) { LoadNapiFunctions(); - return p_napi_add_finalizer(env, js_object, finalize_data, finalize_cb, finalize_hint, result); + return p_napi_add_finalizer(env, js_object, FinalizeData, finalize_cb, FinalizeHint, result); } // CC-OFFNXT(G.FUN.01, huge_method) solid logic @@ -403,10 +403,10 @@ NAPI_EXTERN napi_status NAPI_CDECL napi_create_int32(napi_env env, int32_t value // CC-OFFNXT(G.FUN.01, huge_method) solid logic NAPI_EXTERN napi_status NAPI_CDECL napi_create_external_arraybuffer(napi_env env, void *external_data, size_t byte_length, napi_finalize finalize_cb, - void *finalize_hint, napi_value *result) + void *FinalizeHint, napi_value *result) { LoadNapiFunctions(); - return p_napi_create_external_arraybuffer(env, external_data, byte_length, finalize_cb, finalize_hint, result); + return p_napi_create_external_arraybuffer(env, external_data, byte_length, finalize_cb, FinalizeHint, result); } // CC-OFFNXT(G.FUN.01, huge_method) solid logic @@ -469,12 +469,12 @@ NAPI_EXTERN napi_status NAPI_CDECL napi_reject_deferred(napi_env env, napi_defer // CC-OFFNXT(G.FUN.01, huge_method) solid logic NAPI_EXTERN napi_status NAPI_CDECL napi_create_threadsafe_function( napi_env env, napi_value func, napi_value async_resource, napi_value async_resource_name, size_t max_queue_size, - size_t initial_thread_count, void *thread_finalize_data, napi_finalize thread_finalize_cb, void *context, + size_t initial_thread_count, void *thread_FinalizeData, napi_finalize thread_finalize_cb, void *context, napi_threadsafe_function_call_js call_js_cb, napi_threadsafe_function *result) { LoadNapiFunctions(); return p_napi_create_threadsafe_function(env, func, async_resource, async_resource_name, max_queue_size, - initial_thread_count, thread_finalize_data, thread_finalize_cb, context, + initial_thread_count, thread_FinalizeData, thread_finalize_cb, context, call_js_cb, result); }