• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /**
2  * Copyright (c) 2022-2024 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_ETS_NAPI_ENV_H
17 #define PANDA_PLUGINS_ETS_RUNTIME_ETS_NAPI_ENV_H
18 
19 #include "plugins/ets/runtime/mem/ets_reference.h"
20 #include "plugins/ets/runtime/napi/ets_napi.h"
21 
22 namespace ark::ets {
23 
24 class EtsCoroutine;
25 class PandaEtsVM;
26 using EtsThrowable = EtsObject;
27 
28 class PandaEtsNapiEnv : public EtsEnv {
29 public:
30     static Expected<std::unique_ptr<PandaEtsNapiEnv>, const char *> Create(EtsCoroutine *coroutine,
31                                                                            mem::InternalAllocatorPtr allocator);
32     PANDA_PUBLIC_API static PandaEtsNapiEnv *GetCurrent();
33 
34     PandaEtsNapiEnv(EtsCoroutine *coroutine, PandaUniquePtr<EtsReferenceStorage> referenceStorage);
35     ~PandaEtsNapiEnv() = default;
36 
GetEtsCoroutine()37     EtsCoroutine *GetEtsCoroutine() const
38     {
39         return coroutine_;
40     }
41 
42     PandaEtsVM *GetEtsVM() const;
43 
GetEtsReferenceStorage()44     EtsReferenceStorage *GetEtsReferenceStorage() const
45     {
46         return referenceStorage_.get();
47     }
48 
ToPandaEtsEnv(EtsEnv * env)49     static PandaEtsNapiEnv *ToPandaEtsEnv(EtsEnv *env)
50     {
51         return static_cast<PandaEtsNapiEnv *>(env);
52     }
53 
54     void SetException(EtsThrowable *thr);
55     EtsThrowable *GetThrowable() const;
56     bool HasPendingException() const;
57     void ClearException();
58     void FreeInternalMemory();
59 
60     NO_COPY_SEMANTIC(PandaEtsNapiEnv);
61     NO_MOVE_SEMANTIC(PandaEtsNapiEnv);
62 
63 private:
64     EtsCoroutine *coroutine_;
65     PandaUniquePtr<EtsReferenceStorage> referenceStorage_;
66 };
67 
68 }  // namespace ark::ets
69 
70 #endif  // PANDA_PLUGINS_ETS_RUNTIME_ETS_NAPI_ENV_H
71