From 956a8c101d1bb5f221cae3927e59431634b41b5b Mon Sep 17 00:00:00 2001 From: Panferov Ivan Date: Fri, 5 Sep 2025 14:00:09 +0800 Subject: [PATCH] Fix raw object usage in ArrayBuffer Issue: #ICXEP3 Signed-off-by: Panferov Ivan --- .../runtime/intrinsics/escompat_ArrayBuffer.cpp | 2 +- .../plugins/ets/runtime/types/ets_arraybuffer.h | 15 ++++++++------- 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/static_core/plugins/ets/runtime/intrinsics/escompat_ArrayBuffer.cpp b/static_core/plugins/ets/runtime/intrinsics/escompat_ArrayBuffer.cpp index 510d136f59..70ca02b9e1 100644 --- a/static_core/plugins/ets/runtime/intrinsics/escompat_ArrayBuffer.cpp +++ b/static_core/plugins/ets/runtime/intrinsics/escompat_ArrayBuffer.cpp @@ -148,7 +148,7 @@ extern "C" void EtsEscompatArrayBufferSet(EtsEscompatArrayBuffer *arrayBuffer, E extern "C" ObjectHeader *EtsEscompatArrayBufferAllocateNonMovable(EtsInt length) { - return EtsEscompatArrayBuffer::AllocateNonMovableArray(length); + return EtsEscompatArrayBuffer::AllocateNonMovableArray(length)->GetCoreType(); } extern "C" EtsLong EtsEscompatArrayBufferGetAddress(ObjectHeader *byteArray) diff --git a/static_core/plugins/ets/runtime/types/ets_arraybuffer.h b/static_core/plugins/ets/runtime/types/ets_arraybuffer.h index e711952496..2a1a0f970e 100644 --- a/static_core/plugins/ets/runtime/types/ets_arraybuffer.h +++ b/static_core/plugins/ets/runtime/types/ets_arraybuffer.h @@ -57,9 +57,9 @@ public: * @param length of created array. * NOTE: non-movable creation ensures that native code can obtain raw pointer to buffer. */ - ALWAYS_INLINE static ObjectHeader *AllocateNonMovableArray(EtsInt length) + ALWAYS_INLINE static EtsByteArray *AllocateNonMovableArray(EtsInt length) { - return EtsByteArray::Create(length, SpaceType::SPACE_TYPE_NON_MOVABLE_OBJECT)->GetCoreType(); + return EtsByteArray::Create(length, SpaceType::SPACE_TYPE_NON_MOVABLE_OBJECT); } ALWAYS_INLINE static EtsLong GetAddress(const EtsByteArray *array) @@ -81,7 +81,8 @@ public: return nullptr; } - handle->InitializeByDefault(coro, length); + auto *buf = AllocateNonMovableArray(length); + handle->InitializeByDefault(coro, buf); *resultData = handle->GetData(); return handle.GetPtr(); } @@ -299,11 +300,11 @@ private: * Initializes ArrayBuffer. * NOTE: behavior of this method must repeat initialization from managed constructor. */ - void InitializeByDefault(EtsCoroutine *coro, size_t length) + void InitializeByDefault(EtsCoroutine *coro, EtsByteArray *buffer) { - ObjectAccessor::SetObject(coro, this, GetManagedDataOffset(), AllocateNonMovableArray(length)); - ASSERT(length <= static_cast(std::numeric_limits::max())); - byteLength_ = static_cast(length); + ObjectAccessor::SetObject(coro, this, GetManagedDataOffset(), buffer->GetCoreType()); + ASSERT(buffer->GetLength() <= static_cast(std::numeric_limits::max())); + byteLength_ = static_cast(buffer->GetLength()); nativeData_ = GetAddress(EtsByteArray::FromCoreType(ObjectAccessor::GetObject(coro, this, GetManagedDataOffset()))); ASSERT(nativeData_ != 0); -- Gitee