From 6781f5d39d6550894b4591aee55968b48af0ef57 Mon Sep 17 00:00:00 2001 From: hecunmao Date: Thu, 28 Aug 2025 21:35:21 +0800 Subject: [PATCH] wqCherry-pick 12678 to 0702 Issue: https://gitee.com/openharmony/arkcompiler_ets_runtime/issues/ICVBF6 Signed-off-by: hecunmao Change-Id: Iaf213475f6a1ff4f1993db640b9698734ec1685f --- ecmascript/ecma_vm.cpp | 44 +++++++++++++++++++++++++++++++++++ ecmascript/ecma_vm.h | 12 ++++++++++ ecmascript/js_typed_array.cpp | 4 ++++ 3 files changed, 60 insertions(+) diff --git a/ecmascript/ecma_vm.cpp b/ecmascript/ecma_vm.cpp index bbdb615cd8..7ac5085c1d 100644 --- a/ecmascript/ecma_vm.cpp +++ b/ecmascript/ecma_vm.cpp @@ -354,6 +354,7 @@ bool EcmaVM::Initialize() abcBufferCache_ = new AbcBufferCache(); auto globalConst = const_cast(thread_->GlobalConstants()); globalConst->Init(thread_); + InitDataViewTypeTable(globalConst); [[maybe_unused]] EcmaHandleScope scope(thread_); thread_->SetReadyForGCIterating(true); thread_->SetSharedMarkStatus(DaemonThread::GetInstance()->GetSharedMarkStatus()); @@ -2118,4 +2119,47 @@ void EcmaVM::AddModuleManager(ModuleManager *moduleManager) moduleManagers_.push_back(moduleManager); } +void EcmaVM::InitDataViewTypeTable(const GlobalEnvConstants *constant) +{ + dataViewTypeTable_.emplace(constant->GetInt8ArrayString().GetRawData(), static_cast(DataViewType::INT8)); + dataViewTypeTable_.emplace( + constant->GetSharedInt8ArrayString().GetRawData(), static_cast(DataViewType::INT8)); + dataViewTypeTable_.emplace(constant->GetUint8ArrayString().GetRawData(), static_cast(DataViewType::UINT8)); + dataViewTypeTable_.emplace( + constant->GetSharedUint8ArrayString().GetRawData(), static_cast(DataViewType::UINT8)); + dataViewTypeTable_.emplace( + constant->GetUint8ClampedArrayString().GetRawData(), static_cast(DataViewType::UINT8_CLAMPED)); + dataViewTypeTable_.emplace( + constant->GetSharedUint8ClampedArrayString().GetRawData(), static_cast(DataViewType::UINT8_CLAMPED)); + dataViewTypeTable_.emplace(constant->GetInt16ArrayString().GetRawData(), static_cast(DataViewType::INT16)); + dataViewTypeTable_.emplace( + constant->GetSharedInt16ArrayString().GetRawData(), static_cast(DataViewType::INT16)); + dataViewTypeTable_.emplace( + constant->GetUint16ArrayString().GetRawData(), static_cast(DataViewType::UINT16)); + dataViewTypeTable_.emplace( + constant->GetSharedUint16ArrayString().GetRawData(), static_cast(DataViewType::UINT16)); + dataViewTypeTable_.emplace(constant->GetInt32ArrayString().GetRawData(), static_cast(DataViewType::INT32)); + dataViewTypeTable_.emplace( + constant->GetSharedInt32ArrayString().GetRawData(), static_cast(DataViewType::INT32)); + dataViewTypeTable_.emplace( + constant->GetUint32ArrayString().GetRawData(), static_cast(DataViewType::UINT32)); + dataViewTypeTable_.emplace( + constant->GetSharedUint32ArrayString().GetRawData(), static_cast(DataViewType::UINT32)); + dataViewTypeTable_.emplace( + constant->GetFloat32ArrayString().GetRawData(), static_cast(DataViewType::FLOAT32)); + dataViewTypeTable_.emplace( + constant->GetSharedFloat32ArrayString().GetRawData(), static_cast(DataViewType::FLOAT32)); + dataViewTypeTable_.emplace( + constant->GetFloat64ArrayString().GetRawData(), static_cast(DataViewType::FLOAT64)); + dataViewTypeTable_.emplace( + constant->GetSharedFloat64ArrayString().GetRawData(), static_cast(DataViewType::FLOAT64)); + dataViewTypeTable_.emplace( + constant->GetBigInt64ArrayString().GetRawData(), static_cast(DataViewType::BIGINT64)); + dataViewTypeTable_.emplace( + constant->GetSharedBigInt64ArrayString().GetRawData(), static_cast(DataViewType::BIGINT64)); + dataViewTypeTable_.emplace( + constant->GetBigUint64ArrayString().GetRawData(), static_cast(DataViewType::BIGUINT64)); + dataViewTypeTable_.emplace( + constant->GetSharedBigUint64ArrayString().GetRawData(), static_cast(DataViewType::BIGUINT64)); +} } // namespace panda::ecmascript diff --git a/ecmascript/ecma_vm.h b/ecmascript/ecma_vm.h index 63a9ee7f3a..3559beef56 100644 --- a/ecmascript/ecma_vm.h +++ b/ecmascript/ecma_vm.h @@ -1313,6 +1313,14 @@ public: static void ClearKeptObjects(JSThread *thread); static void AddToKeptObjects(JSThread *thread, JSHandle value); void AddModuleManager(ModuleManager *moduleManager); + int8_t GetDataViewType(JSTaggedType type) const + { + auto result = dataViewTypeTable_.find(type); + if (result == dataViewTypeTable_.end()) { + return -1; + } + return result->second; + } #ifdef PANDA_JS_ETS_HYBRID_MODE ECMAVM_PUBLIC_HYBRID_MODE_EXTENSION() @@ -1370,6 +1378,8 @@ private: Expected CommonInvokeEcmaEntrypoint(const JSPandaFile *jsPandaFile, std::string_view entryPoint, JSHandle &func, const ExecuteTypes &executeType); + void InitDataViewTypeTable(const GlobalEnvConstants *constant); + NO_MOVE_SEMANTIC(EcmaVM); NO_COPY_SEMANTIC(EcmaVM); @@ -1529,6 +1539,8 @@ private: JSTaggedValue registerSymbols_ {JSTaggedValue::Hole()}; JSTaggedValue microJobQueue_ {JSTaggedValue::Hole()}; std::atomic isProcessingPendingJob_{false}; + + std::unordered_map dataViewTypeTable_; #if ECMASCRIPT_ENABLE_SCOPE_LOCK_STAT // Stats for Thread-State-Transition and String-Table Locks diff --git a/ecmascript/js_typed_array.cpp b/ecmascript/js_typed_array.cpp index 4b936e1599..6dd4bc1bed 100644 --- a/ecmascript/js_typed_array.cpp +++ b/ecmascript/js_typed_array.cpp @@ -463,6 +463,10 @@ bool JSTypedArray::IsValidIntegerIndex(const JSHandle &typedArray DataViewType JSTypedArray::GetTypeFromName(JSThread *thread, const JSHandle &typeName) { + auto type = thread->GetEcmaVM()->GetDataViewType(typeName.GetTaggedType()); + if (type != -1) { + return DataViewType(type); + } const GlobalEnvConstants *globalConst = thread->GlobalConstants(); if (JSTaggedValue::SameValue(typeName, globalConst->GetHandledInt8ArrayString()) || JSTaggedValue::SameValue(typeName, globalConst->GetHandledSharedInt8ArrayString())) { -- Gitee