diff --git a/interop/src/arkts/InteropTypes.ts b/interop/src/arkts/InteropTypes.ts index d33b53adcba6b2ee8d9b0c68936fc38d247bb939..b01abe95557048eed4c000def9b9f0a649a4035b 100644 --- a/interop/src/arkts/InteropTypes.ts +++ b/interop/src/arkts/InteropTypes.ts @@ -25,6 +25,7 @@ export type KLong = long export type KUInt = KInt export type KBoolean = int export type KFloat = float +export type KDouble = double; export type KPointer = long // look once again export type pointer = KPointer export type KNativePointer = KPointer diff --git a/interop/src/cangjie/InteropTypes.cj b/interop/src/cangjie/InteropTypes.cj index ddda5415ddc68fa8788fa05360058f0c1de15207..3240744bc4c342867cd195ae1edc5b62d92e225f 100644 --- a/interop/src/cangjie/InteropTypes.cj +++ b/interop/src/cangjie/InteropTypes.cj @@ -18,6 +18,7 @@ import std.collection.* public type KPointer = UInt64 public type KFloat = Float32 +public type KDouble = Float64 public type pointer = KPointer public type KInt = Int32 public type KLong = Int64 diff --git a/interop/src/cpp/ani/convertors-ani.h b/interop/src/cpp/ani/convertors-ani.h index 39782c73780b3ced38c2080e8a6aef893993d4d4..10e7a22de5704056093f437fe0dff0acd8ca5972 100644 --- a/interop/src/cpp/ani/convertors-ani.h +++ b/interop/src/cpp/ani/convertors-ani.h @@ -131,6 +131,18 @@ struct InteropTypeConverter { static inline void release(ani_env* env, InteropType value, KFloat converted) {} }; +template<> +struct InteropTypeConverter { + using InteropType = ani_double; + static inline KDouble convertFrom(ani_env* env, InteropType value) { + return value; + } + static inline InteropType convertTo(ani_env* env, KDouble value) { + return value; + } + static inline void release(ani_env* env, InteropType value, KDouble converted) {} +}; + template<> struct InteropTypeConverter { using InteropType = ani_long; diff --git a/interop/src/cpp/ets/convertors-ets.h b/interop/src/cpp/ets/convertors-ets.h index aab64e15fd1eaed2b411018dd9faac9c34519b7f..efef48798ba19d7e50e59d02c831d343b459612e 100644 --- a/interop/src/cpp/ets/convertors-ets.h +++ b/interop/src/cpp/ets/convertors-ets.h @@ -78,6 +78,14 @@ struct InteropTypeConverter { static void release(EtsEnv* env, InteropType value, KFloat converted) {} }; +template<> +struct InteropTypeConverter { + using InteropType = ets_double; + static KDouble convertFrom(EtsEnv* env, InteropType value) { return value; } + static InteropType convertTo(EtsEnv* env, InteropFloat64 value) { return value; } + static void release(EtsEnv* env, InteropType value, KDouble converted) {} +}; + template<> struct InteropTypeConverter { using InteropType = ets_long; diff --git a/interop/src/cpp/jsc/convertors-jsc.cc b/interop/src/cpp/jsc/convertors-jsc.cc index ba963845419d5f8cdcf3ea57097c8bb9b4f14065..7245991c75710c03d07fc8eab367530a5ae92f71 100644 --- a/interop/src/cpp/jsc/convertors-jsc.cc +++ b/interop/src/cpp/jsc/convertors-jsc.cc @@ -197,6 +197,18 @@ KFloat getFloat(JSContextRef context, JSValueRef value) { return static_cast(result); } +KDouble getDouble(JSContextRef context, JSValueRef value) { + JSValueRef exception {}; + if (JSValueIsNull(context, value)) { + return 0; + } + if (JSValueIsUndefined(context, value)) { + ASSERT(false); + return 0; + } + return JSValueToNumber(context, value, &exception); +} + KShort getShort(JSContextRef context, JSValueRef value) { JSValueRef exception {}; if (JSValueIsNull(context, value)) { @@ -260,6 +272,10 @@ JSValueRef makeFloat(JSContextRef context, KFloat value) { return JSValueMakeNumber(context, value); } +JSValueRef makeDouble(JSContextRef context, KDouble value) { + return JSValueMakeNumber(context, value); +} + JSValueRef makeBoolean(JSContextRef context, KBoolean value) { return JSValueMakeBoolean(context, value); } diff --git a/interop/src/cpp/jsc/convertors-jsc.h b/interop/src/cpp/jsc/convertors-jsc.h index f51ced4818cfaa430812ad2d406643e9a0d61ee2..8ad7a4284950464c40aef715ae98bb7f2601b23a 100644 --- a/interop/src/cpp/jsc/convertors-jsc.h +++ b/interop/src/cpp/jsc/convertors-jsc.h @@ -65,6 +65,7 @@ int32_t getInt32(JSContextRef context, JSValueRef value); uint32_t getUInt32(JSContextRef context, JSValueRef value); KNativePointer getPointer(JSContextRef context, JSValueRef value); KFloat getFloat(JSContextRef context, JSValueRef value); +KDouble getDouble(JSContextRef context, JSValueRef value); KStringPtr getString(JSContextRef context, JSValueRef value); KBoolean getBoolean(JSContextRef context, JSValueRef value); KStringPtr getString(JSContextRef context, JSValueRef value); @@ -102,6 +103,12 @@ inline KFloat getArgument(JSContextRef context, size_t argumentCount, co return getFloat(context, arguments[index]); } +template<> +inline KDouble getArgument(JSContextRef context, size_t argumentCount, const JSValueRef arguments[], int index) { + ASSERT(index < argumentCount); + return getDouble(context, arguments[index]); +} + template <> inline KStringPtr getArgument(JSContextRef context, size_t argumentCount, const JSValueRef arguments[], int index) { ASSERT(index < argumentCount); @@ -160,6 +167,7 @@ JSValueRef makeInt32(JSContextRef context, int32_t value); JSValueRef makeUInt32(JSContextRef context, uint32_t value); JSValueRef makePointer(JSContextRef context, KNativePointer value); JSValueRef makeFloat(JSContextRef context, KFloat value); +JSValueRef makeDouble(JSContextRef context, KDouble value); JSValueRef makeBoolean(JSContextRef context, KBoolean value); JSValueRef makeVoid(JSContextRef context); @@ -186,6 +194,11 @@ inline JSValueRef makeResult(JSContextRef context, KFloat value) { return makeFloat(context, value); } +template <> +inline JSValueRef makeResult(JSContextRef context, KDouble value) { + return makeDouble(context, value); +} + template <> inline JSValueRef makeResult(JSContextRef context, KBoolean value) { return makeBoolean(context, value); diff --git a/interop/src/cpp/kotlin/convertors-kotlin.h b/interop/src/cpp/kotlin/convertors-kotlin.h index ed20284bb042291d09211f2eef22604fe9098914..d2ffceb39c4c403f6924f2e11ce4eba832d3dc80 100644 --- a/interop/src/cpp/kotlin/convertors-kotlin.h +++ b/interop/src/cpp/kotlin/convertors-kotlin.h @@ -101,6 +101,18 @@ struct InteropTypeConverter { static inline void release(InteropType value, KFloat converted) {} }; +template<> +struct InteropTypeConverter { + using InteropType = double; + static inline KDouble convertFrom(InteropType value) { + return value; + } + static inline InteropType convertTo(KDouble value) { + return value; + } + static inline void release(InteropType value, KDouble converted) {} +}; + template<> struct InteropTypeConverter { using InteropType = int64_t; diff --git a/interop/src/cpp/napi/convertors-napi.cc b/interop/src/cpp/napi/convertors-napi.cc index 39bbbc98891a1e72d665c85382211e28a53ba61c..f0b49b53b35b33dc81a4dd3eb01f26ce3c7bf288 100644 --- a/interop/src/cpp/napi/convertors-napi.cc +++ b/interop/src/cpp/napi/convertors-napi.cc @@ -244,6 +244,14 @@ napi_value makeFloat32(napi_env env, float value) { return result; } +napi_value makeFloat64(napi_env env, double value) { + napi_value result; + napi_status status; + status = napi_create_double(env, value, &result); + KOALA_NAPI_THROW_IF_FAILED(env, status, result); + return result; +} + napi_value makePointer(napi_env env, void* 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 e737505b4cbbf31b6ab301efd119ce7bd34c8011..d1551ad4addffb7f2b741f09d1f6066827865af1 100644 --- a/interop/src/cpp/napi/convertors-napi.h +++ b/interop/src/cpp/napi/convertors-napi.h @@ -64,6 +64,7 @@ napi_value makeUInt32(napi_env env, uint32_t value); napi_value makeInt64(napi_env env, int64_t value); napi_value makeUInt64(napi_env env, uint64_t value); napi_value makeFloat32(napi_env env, float value); +napi_value makeFloat64(napi_env env, double value); napi_value makePointer(napi_env env, void* value); napi_value makeVoid(napi_env env); @@ -293,6 +294,11 @@ inline napi_typedarray_type getNapiType() { return napi_float32_array; } +template <> +inline napi_typedarray_type getNapiType() { + return napi_float64_array; +} + template <> inline napi_typedarray_type getNapiType() { return napi_int8_array; @@ -400,6 +406,10 @@ inline float* getFloat32Elements(const CallbackInfo& info, int index) { return getTypedElements(info, index); } +inline double* getFloat64Elements(const CallbackInfo& info, int index) { + return getTypedElements(info, index); +} + inline KNativePointer* getPointerElements(const CallbackInfo& info, int index) { return getTypedElements(info, index); } @@ -600,6 +610,11 @@ inline napi_value makeResult(const CallbackInfo& info, float value) { return makeFloat32(info.Env(), value); } +template <> +inline napi_value makeResult(const CallbackInfo& info, double value) { + return makeFloat64(info.Env(), value); +} + template <> inline napi_value makeResult(const CallbackInfo& info, KNativePointer value) { return makePointer(info.Env(), value); diff --git a/interop/src/cpp/wasm/convertors-wasm.h b/interop/src/cpp/wasm/convertors-wasm.h index 3d33a6cc714bceb625b071179c56d21f6d7bfd96..d6a1220f6372c72b7f587dcc7c6f1d27fae599a6 100644 --- a/interop/src/cpp/wasm/convertors-wasm.h +++ b/interop/src/cpp/wasm/convertors-wasm.h @@ -86,6 +86,14 @@ struct InteropTypeConverter { static void release(InteropType value, KFloat converted) {} }; +template<> +struct InteropTypeConverter { + using InteropType = double; + static KDouble convertFrom(InteropType value) { return value; } + static InteropType convertTo(InteropFloat64 value) { return value; } + static void release(InteropType value, KDouble converted) {} +}; + template<> struct InteropTypeConverter { using InteropType = void *;