• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /**
2  * Copyright (c) 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_XGC_XGC_VM_ADAPTOR_H
17 #define PANDA_PLUGINS_ETS_RUNTIME_INTEROP_JS_XGC_XGC_VM_ADAPTOR_H
18 
19 #include "hybrid/ecma_vm_interface.h"
20 #include "libpandabase/macros.h"
21 #include <node_api.h>
22 
23 namespace ark::ets::interop::js {
24 
25 class InteropCtx;
26 
27 class XGCVmAdaptor {
28 public:
XGCVmAdaptor(napi_env env,arkplatform::EcmaVMInterface * ecmaVMIface)29     XGCVmAdaptor(napi_env env, arkplatform::EcmaVMInterface *ecmaVMIface) : env_(env), ecmaVMIface_(ecmaVMIface) {}
30     NO_COPY_SEMANTIC(XGCVmAdaptor);
31     NO_MOVE_SEMANTIC(XGCVmAdaptor);
32     virtual ~XGCVmAdaptor() = default;
33     /**
34      * @brief Method checks if specific napi environment is equal to internal one
35      * @param env: napi env you want to compare with internal one
36      * @returns true if envs are equal, otherwise false
37      */
HasSameEnv(napi_env env)38     bool HasSameEnv(napi_env env) const
39     {
40         return env == env_;
41     }
42     /**
43      * @brief Method uses `napi_delete_reference` to delete specific napi reference
44      * @param ref: reference that should be deleted
45      * @returns status of `napi_delete_reference` function execution
46      */
47     napi_status NapiDeleteReference(napi_ref ref);
48     /**
49      * @brief Method use internal ecma interface to start ecma gc marking from specific reference
50      * @param ref: ecma vm napi ref you want to start gc marking with
51      */
52     virtual void MarkFromObject([[maybe_unused]] napi_ref ref);
53     /// @brief Method starts executing of cross reference marking in ecma vm
54     virtual bool StartXRefMarking();
55 
56     virtual void NotifyXGCInterruption();
57 
58 private:
59     napi_env env_;
60     arkplatform::EcmaVMInterface *ecmaVMIface_ = nullptr;
61 };
62 
63 }  // namespace ark::ets::interop::js
64 
65 #endif  // PANDA_PLUGINS_ETS_RUNTIME_INTEROP_JS_XGC_XGC_VM_ADAPTOR_H