1 /** 2 * Copyright (c) 2024-2025 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16 #ifndef PANDA_PLUGINS_ETS_RUNTIME_INTEROP_JS_OHOS_STACK_INFO_H 17 #define PANDA_PLUGINS_ETS_RUNTIME_INTEROP_JS_OHOS_STACK_INFO_H 18 19 #include <memory> 20 #include "libpandabase/macros.h" 21 22 struct NapiStackInfo; 23 24 namespace ark::ets { 25 class EtsCoroutine; 26 } // namespace ark::ets 27 28 namespace ark::ets::interop::js { 29 30 class InteropCtx; 31 32 class StackInfoManagerBase { 33 public: StackInfoManagerBase(InteropCtx * ctx,EtsCoroutine * coro)34 StackInfoManagerBase([[maybe_unused]] InteropCtx *ctx, [[maybe_unused]] EtsCoroutine *coro) 35 : ctx_(ctx), mainCoro_(coro) 36 { 37 UNUSED_VAR(ctx_); 38 UNUSED_VAR(mainCoro_); 39 } 40 // NOTE(konstanting, #23205): revert to ALWAYS_INLINE once the migration of ets_vm_plugin.cpp to ANI is completed InitStackInfoIfNeeded()41 PANDA_PUBLIC_API void InitStackInfoIfNeeded() {}; 42 // NOTE(konstanting, #23205): revert to ALWAYS_INLINE once the migration of ets_vm_plugin.cpp to ANI is completed UpdateStackInfoIfNeeded()43 PANDA_PUBLIC_API void UpdateStackInfoIfNeeded() {}; 44 ~StackInfoManagerBase() = default; 45 46 NO_MOVE_SEMANTIC(StackInfoManagerBase); 47 NO_COPY_SEMANTIC(StackInfoManagerBase); 48 49 protected: 50 InteropCtx *ctx_; // NOLINT(misc-non-private-member-variables-in-classes) 51 EtsCoroutine *mainCoro_; // NOLINT(misc-non-private-member-variables-in-classes) 52 }; 53 54 class StackInfoManagerOhos : public StackInfoManagerBase { 55 public: 56 StackInfoManagerOhos(InteropCtx *ctx, EtsCoroutine *coro); 57 // NOTE(konstanting, #23205): revert to ALWAYS_INLINE once the migration of ets_vm_plugin.cpp to ANI is completed 58 PANDA_PUBLIC_API void InitStackInfoIfNeeded(); 59 // NOTE(konstanting, #23205): revert to ALWAYS_INLINE once the migration of ets_vm_plugin.cpp to ANI is completed 60 PANDA_PUBLIC_API void UpdateStackInfoIfNeeded(); 61 ~StackInfoManagerOhos(); 62 63 NO_MOVE_SEMANTIC(StackInfoManagerOhos); 64 NO_COPY_SEMANTIC(StackInfoManagerOhos); 65 66 private: 67 std::unique_ptr<NapiStackInfo> mainStackInfo_ {}; 68 }; 69 70 #if defined(PANDA_TARGET_OHOS) || defined(PANDA_JS_ETS_HYBRID_MODE) 71 using StackInfoManager = StackInfoManagerOhos; 72 #else 73 using StackInfoManager = StackInfoManagerBase; 74 #endif 75 76 } // namespace ark::ets::interop::js 77 #endif // !PANDA_PLUGINS_ETS_RUNTIME_INTEROP_JS_OHOS_STACK_INFO_H