diff --git a/arkoala/framework/native/src/generated/arkoala_api_generated.h b/arkoala/framework/native/src/generated/arkoala_api_generated.h index bfb132d274fcfb23f2b36d84ba3fc5890c91351b..711c23251941f211ab7cdb2b735ccc42b07e7a10 100644 --- a/arkoala/framework/native/src/generated/arkoala_api_generated.h +++ b/arkoala/framework/native/src/generated/arkoala_api_generated.h @@ -58,6 +58,7 @@ typedef double InteropFloat64; typedef int32_t InteropInt32; typedef unsigned int InteropUInt32; // TODO: update unsigned int typedef int64_t InteropInt64; +typedef uint64_t InteropUInt64; typedef int8_t InteropInt8; typedef uint8_t InteropUInt8; typedef int64_t InteropDate; diff --git a/interop/src/cpp/DeserializerBase.h b/interop/src/cpp/DeserializerBase.h index 87fe3fc392bb6d037735247552eabcfecebf361e..16d49ffe7d284989ea8feabae4ff0c2b1b6db8ef 100644 --- a/interop/src/cpp/DeserializerBase.h +++ b/interop/src/cpp/DeserializerBase.h @@ -412,6 +412,18 @@ public: memcpy(&value, data + position, 4); #else auto value = *(InteropInt64 *)(data + position); +#endif + position += 8; + return value; + } + InteropUInt64 readUInt64() + { + check(8); +#ifdef KOALA_NO_UNALIGNED_ACCESS + InteropInt64 value; + memcpy(&value, data + position, 4); +#else + auto value = *(InteropUInt64 *)(data + position); #endif position += 8; return value; diff --git a/interop/src/cpp/SerializerBase.h b/interop/src/cpp/SerializerBase.h index 8d638146613b76db7f99a404bfd6fd7c87019801..d631a0a2ad959aaf1f7ca7ae1106a5db34d856ce 100644 --- a/interop/src/cpp/SerializerBase.h +++ b/interop/src/cpp/SerializerBase.h @@ -140,6 +140,16 @@ public: position += 8; } + void writeUInt64(InteropUInt64 value) { + check(8); +#ifdef KOALA_NO_UNALIGNED_ACCESS + memcpy(data + position, &value, 8); +#else + *((InteropUInt64*)(data + position)) = value; +#endif + position += 8; + } + void writeFloat32(InteropFloat32 value) { check(8); #ifdef KOALA_NO_UNALIGNED_ACCESS diff --git a/interop/src/cpp/interop-types.h b/interop/src/cpp/interop-types.h index b27e3dc18e080fb3032d93cdcbf9ca05e05746f3..6c23272a457ccc737701229da9c0fc865a1dc1a6 100644 --- a/interop/src/cpp/interop-types.h +++ b/interop/src/cpp/interop-types.h @@ -35,6 +35,7 @@ typedef double InteropFloat64; typedef int32_t InteropInt32; typedef unsigned int InteropUInt32; // TODO: update unsigned int typedef int64_t InteropInt64; +typedef uint64_t InteropUInt64; typedef int8_t InteropInt8; typedef uint8_t InteropUInt8; typedef int64_t InteropDate; diff --git a/interop/src/cpp/napi/convertors-napi.cc b/interop/src/cpp/napi/convertors-napi.cc index 725853dd5faac31a66701cd7d9b19e5c1b7b3f26..7fa237507d1856f7b851ffd9c156d77f81c4e3fe 100644 --- a/interop/src/cpp/napi/convertors-napi.cc +++ b/interop/src/cpp/napi/convertors-napi.cc @@ -12,6 +12,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ +#include #include #include #include @@ -152,17 +153,21 @@ KLong getInt64(napi_env env, napi_value value) { return static_cast(ptr64); } -// napi_value getObject(napi_env env, napi_value value) { -// if (getValueTypeChecked(env, value) != napi_valuetype::napi_object) { -// Napi::Error::New(env, "Expected Object") -// .ThrowAsJavaScriptException(); -// napi_value result; -// napi_status status = napi_get_global(env, &result); -// KOALA_NAPI_THROW_IF_FAILED(env, status, result); -// } +KULong getUInt64(napi_env env, napi_value value) { + if (getValueTypeChecked(env, value) != napi_valuetype::napi_bigint) { + napi_throw_error(env, nullptr, "cannot be coerced to uint64"); + return -1; + } -// return value; -// } + bool isWithinRange = true; + uint64_t ptr64 = 0; + napi_get_value_bigint_uint64(env, value, &ptr64, &isWithinRange); + if (!isWithinRange) { + napi_throw_error(env, nullptr, "cannot be coerced to uint64, value is too large"); + return -1; + } + return static_cast(ptr64); +} napi_value makeString(napi_env env, const KStringPtr& value) { napi_value result; @@ -204,6 +209,22 @@ napi_value makeUInt32(napi_env env, uint32_t value) { return result; } +napi_value makeInt64(napi_env env, int64_t value) { + napi_value result; + napi_status status; + status = napi_create_bigint_int64(env, value, &result); + KOALA_NAPI_THROW_IF_FAILED(env, status, result); + return result; +} + +napi_value makeUInt64(napi_env env, uint64_t value) { + napi_value result; + napi_status status; + status = napi_create_bigint_uint64(env, value, &result); + KOALA_NAPI_THROW_IF_FAILED(env, status, result); + return result; +} + napi_value makeFloat32(napi_env env, float value) { napi_value result; napi_status status; diff --git a/interop/src/cpp/napi/convertors-napi.h b/interop/src/cpp/napi/convertors-napi.h index aa4354c3c76503fa1e5e3b3abc5f7f84bf52921f..29adb12654b5845aac16c86837db2881c16d7fbc 100644 --- a/interop/src/cpp/napi/convertors-napi.h +++ b/interop/src/cpp/napi/convertors-napi.h @@ -393,6 +393,11 @@ inline void* getPointer(const CallbackInfo& info, int index) { NAPI_ASSERT_INDEX(info, index, nullptr); return getPointer(info.Env(), info[index]); } +KULong getUInt64(napi_env env, napi_value value); +inline KULong getUInt64(const CallbackInfo& info, int index) { + NAPI_ASSERT_INDEX(info, index, 0); + return getUInt64(info.Env(), info[index]); +} KLong getInt64(napi_env env, napi_value value); inline KLong getInt64(const CallbackInfo& info, int index) { NAPI_ASSERT_INDEX(info, index, 0); @@ -503,6 +508,11 @@ inline KLong getArgument(const CallbackInfo& info, int index) { return getInt64(info, index); } +template <> +inline KULong getArgument(const CallbackInfo& info, int index) { + return getUInt64(info, index); +} + template <> inline KNativePointerArray getArgument(const CallbackInfo& info, int index) { return getPointerElements(info, index); @@ -563,6 +573,8 @@ 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 makeInt64(napi_env env, int32_t value); +napi_value makeUInt64(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); @@ -590,6 +602,16 @@ inline napi_value makeResult(const CallbackInfo& info, uint32_t value) return makeUInt32(info.Env(), value); } +template <> +inline napi_value makeResult(const CallbackInfo& info, int64_t value) { + return makeInt64(info.Env(), value); +} + +template <> +inline napi_value makeResult(const CallbackInfo& info, uint64_t value) { + return makeUInt64(info.Env(), value); +} + template <> inline napi_value makeResult(const CallbackInfo& info, float value) { return makeFloat32(info.Env(), value); @@ -600,16 +622,6 @@ inline napi_value makeResult(const CallbackInfo& info, KNativePo return makePointer(info.Env(), value); } -// template <> -// inline napi_value makeResult(const CallbackInfo& info, napi_value value) { -// return value; -// } - -// template <> -// inline napi_value makeResult(const CallbackInfo& info, napi_value value) { -// return makeObject(info, value); -// } - template <> inline napi_value makeResult(const CallbackInfo& info, KVMObjectHandle value) { return InteropTypeConverter::convertTo(info.Env(), value); diff --git a/interop/src/cpp/types/koala-types.h b/interop/src/cpp/types/koala-types.h index 8b0e86f8a91e0a0c17266633ca3a200810f497df..44beaceeec7b9f977fec3862ca12ca86b8f0cbd9 100644 --- a/interop/src/cpp/types/koala-types.h +++ b/interop/src/cpp/types/koala-types.h @@ -124,6 +124,7 @@ typedef int32_t KInt; typedef uint32_t KUInt; typedef float KFloat; typedef int64_t KLong; +typedef uint64_t KULong; typedef double KDouble; typedef void* KNativePointer; typedef KStringPtrImpl KStringPtr;