From 5e3178f5d85eae017a3d5211b56b8053a7fde135 Mon Sep 17 00:00:00 2001 From: MockMockBlack Date: Thu, 15 May 2025 15:27:06 +0800 Subject: [PATCH] [Builtin] TypedArray external buffer support Modified EtsEscompatTypedArrayGet and EtsEscompatTypedArraySet to support using ArrayBuffer created from external buffer(not in object buffer). Issue: https://gitee.com/openharmony/arkcompiler_runtime_core/issues/IC81RE Signed-off-by: MockMockBlack Change-Id: I4384a4c2d3d2325352200479a26ae49ba0cea442 --- .../runtime/intrinsics/escompat_TypedArrays.cpp | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/static_core/plugins/ets/runtime/intrinsics/escompat_TypedArrays.cpp b/static_core/plugins/ets/runtime/intrinsics/escompat_TypedArrays.cpp index 7175e1896e..785b76912e 100644 --- a/static_core/plugins/ets/runtime/intrinsics/escompat_TypedArrays.cpp +++ b/static_core/plugins/ets/runtime/intrinsics/escompat_TypedArrays.cpp @@ -13,6 +13,8 @@ * limitations under the License. */ +#include "libpandabase/mem/mem.h" +#include "plugins/ets/runtime/types/ets_primitives.h" #include "plugins/ets/runtime/types/ets_typed_arrays.h" #include "plugins/ets/runtime/types/ets_typed_unsigned_arrays.h" #include "intrinsics.h" @@ -47,13 +49,15 @@ static void EtsEscompatTypedArraySet(T *thisArray, EtsInt pos, typename T::Eleme return; } + // Boundary Check if (UNLIKELY(pos < 0 || pos >= thisArray->GetLengthInt())) { EtsCoroutine *coro = EtsCoroutine::GetCurrent(); ThrowEtsException(coro, panda_file_items::class_descriptors::RANGE_ERROR, "invalid index"); return; } - ObjectAccessor::SetPrimitive( - data, pos * sizeof(typename T::ElementType) + static_cast(thisArray->GetByteOffset()), val); + + auto *dataPtr = ToVoidPtr(ToUintPtr(data) + static_cast(thisArray->GetByteOffset())); + reinterpret_cast(dataPtr)[pos] = val; } template @@ -64,13 +68,15 @@ typename T::ElementType EtsEscompatTypedArrayGet(T *thisArray, EtsInt pos) return 0; } + // Boundary Check if (UNLIKELY(pos < 0 || pos >= thisArray->GetLengthInt())) { EtsCoroutine *coro = EtsCoroutine::GetCurrent(); ThrowEtsException(coro, panda_file_items::class_descriptors::RANGE_ERROR, "invalid index"); return 0; } - return ObjectAccessor::GetPrimitive( - data, pos * sizeof(typename T::ElementType) + static_cast(thisArray->GetByteOffset())); + + auto *dataPtr = ToVoidPtr(ToUintPtr(data) + static_cast(thisArray->GetByteOffset())); + return reinterpret_cast(dataPtr)[pos]; } extern "C" void EtsEscompatInt8ArraySetInt(ark::ets::EtsEscompatInt8Array *thisArray, EtsInt pos, EtsInt val) -- Gitee