• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021-2022 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 FOUNDATION_ACE_NAPI_NATIVE_ENGINE_IMPL_ARK_ARK_NATIVE_ENGINE_H
17 #define FOUNDATION_ACE_NAPI_NATIVE_ENGINE_IMPL_ARK_ARK_NATIVE_ENGINE_H
18 
19 #include <memory>
20 #if !defined(PREVIEW) && !defined(IOS_PLATFORM)
21 #include <sys/wait.h>
22 #include <sys/types.h>
23 #endif
24 #include <iostream>
25 #include <map>
26 #include <mutex>
27 #include <regex>
28 #include <thread>
29 #include <unistd.h>
30 
31 #include "ark_idle_monitor.h"
32 #include "ark_native_options.h"
33 #include "ecmascript/napi/include/dfx_jsnapi.h"
34 #include "ecmascript/napi/include/jsnapi.h"
35 #include "native_engine/impl/ark/ark_finalizers_pack.h"
36 #include "native_engine/native_engine.h"
37 
38 namespace panda::ecmascript {
39 struct JsHeapDumpWork;
40 struct JsFrameInfo {
41     std::string functionName;
42     std::string fileName;
43     std::string packageName;
44     std::string pos;
45 };
46 struct ApiCheckContext {
47     NativeModuleManager* moduleManager;
48     EcmaVM* ecmaVm;
49     panda::Local<panda::StringRef>& moduleName;
50     panda::Local<panda::ObjectRef>& exportObj;
51     panda::EscapeLocalScope& scope;
52 };
53 } // panda::ecmascript
54 using JsFrameInfo = panda::ecmascript::JsFrameInfo;
55 using DFXJSNApi = panda::DFXJSNApi;
56 using LocalScope = panda::LocalScope;
57 using JSNApi = panda::JSNApi;
58 using JSValueRef = panda::JSValueRef;
59 using JsiRuntimeCallInfo = panda::JsiRuntimeCallInfo;
60 // indirect used by ace_engine and(or) ability_runtime
61 using panda::Local;
62 
63 typedef bool (*NapiModuleValidateCallback)(const char* moduleName);
64 
65 class NativeTimerCallbackInfo;
66 template <bool changeState = true>
67 panda::JSValueRef ArkNativeFunctionCallBack(JsiRuntimeCallInfo *runtimeInfo);
68 void NapiDefinePropertyInner(napi_env env,
69                              Local<panda::ObjectRef> &obj,
70                              NapiPropertyDescriptor &propertyDescriptor,
71                              Local<panda::JSValueRef> &propertyName,
72                              bool &result);
73 bool NapiDefineProperty(napi_env env, panda::Local<panda::ObjectRef> &obj, NapiPropertyDescriptor propertyDescriptor);
74 NAPI_EXPORT panda::Local<panda::JSValueRef> NapiValueToLocalValue(napi_value v);
75 NAPI_EXPORT napi_value LocalValueToLocalNapiValue(panda::Local<panda::JSValueRef> local);
76 #ifdef ENABLE_CONTAINER_SCOPE
77 void FunctionSetContainerId(napi_env env, panda::Local<panda::JSValueRef> &local);
78 #endif
79 panda::Local<panda::JSValueRef> NapiDefineClass(napi_env env, const char* name, NapiNativeCallback callback,
80                                                 void* data, const NapiPropertyDescriptor* properties, size_t length);
81 Local<JSValueRef> NapiDefineSendableClass(napi_env env,
82                                           const char* name,
83                                           NapiNativeCallback callback,
84                                           void* data,
85                                           const NapiPropertyDescriptor* properties,
86                                           size_t propertiesLength,
87                                           napi_value parent);
88 panda::Local<panda::ObjectRef> NapiCreateSObjectWithProperties(napi_env env,
89                                                                size_t propertyCount,
90                                                                const NapiPropertyDescriptor* properties);
91 panda::Local<panda::ObjectRef> NapiCreateObjectWithProperties(napi_env env, size_t propertyCount,
92                                                               const napi_property_descriptor *properties,
93                                                               Local<panda::JSValueRef> *keys,
94                                                               panda::PropertyAttribute *attrs);
95 void CommonDeleter(void *env, void *externalPointer, void *data);
96 
97 enum class ForceExpandState : int32_t {
98     FINISH_COLD_START = 0,
99     START_HIGH_SENSITIVE,
100     FINISH_HIGH_SENSITIVE,
101     WARM_START,
102 };
103 
104 enum class ModuleTypes : uint8_t {
105     NATIVE_MODULE = 0x01,
106     MODULE_INNER_FILE,
107     UNKNOWN
108 };
109 
110 class SerializationData {
111 public:
SerializationData()112     SerializationData() : data_(nullptr), size_(0) {}
113     ~SerializationData() = default;
114 
GetData()115     uint8_t* GetData() const
116     {
117         return data_.get();
118     }
GetSize()119     size_t GetSize() const
120     {
121         return size_;
122     }
123 
124 private:
125     struct DataDeleter {
operatorDataDeleter126         void operator()(uint8_t* p) const
127         {
128             free(p);
129         }
130     };
131 
132     std::unique_ptr<uint8_t, DataDeleter> data_;
133     size_t size_;
134 };
135 
136 enum class ArkNativeEngineState : uint8_t {
137     RUNNING,
138     STOPPED,
139     RELEASING,
140 };
141 
142 class AppStateNotifier {
143 public:
SetCallback(NapiAppStateCallback callback)144     void SetCallback(NapiAppStateCallback callback)
145     {
146         callback_ = callback;
147     }
148 
149     void Notify(NapiAppState state, int64_t timestamp = 0)
150     {
151         if (callback_ != nullptr) {
152             callback_(state, timestamp);
153         }
154     }
155 
156 private:
157     NapiAppStateCallback callback_ {nullptr};
158 };
159 
160 class NAPI_EXPORT ArkNativeEngine : public NativeEngine {
161 friend struct MoudleNameLocker;
162 public:
163     // ArkNativeEngine constructor
164     ArkNativeEngine(EcmaVM* vm, void* jsEngine, bool isLimitedWorker = false);
165     // ArkNativeEngine destructor
166     ~ArkNativeEngine() override;
167 
168     static ArkNativeEngine* New(NativeEngine* engine, EcmaVM* vm, const Local<JSValueRef>& context);
169 
170     bool IsReadyToDelete();
171     void Delete();
172 
GetEcmaVm()173     NAPI_EXPORT const EcmaVM* GetEcmaVm() const override
174     {
175         return vm_;
176     }
177     const ArkNativeEngine* GetParent() const override;
178 
179     void Loop(LoopMode mode, bool needSync = false) override;
180     void SetPromiseRejectCallback(NativeReference* rejectCallbackRef, NativeReference* checkCallbackRef) override;
181     static bool SetModuleValidateCallback(NapiModuleValidateCallback validateCallback);
182     // For concurrent
183     bool InitTaskPoolThread(NativeEngine* engine, NapiConcurrentCallback callback) override;
184     bool InitTaskPoolThread(napi_env env, NapiConcurrentCallback callback) override;
185     bool InitTaskPoolFunc(napi_env env, napi_value func, void* taskInfo) override;
186     void ClearCurrentTaskInfo() override;
187     bool HasPendingJob() const override;
188     bool IsProfiling() const override;
189     bool IsExecutingPendingJob() const override;
190     void* GetCurrentTaskInfo() const override;
191     void TerminateExecution() const override;
192     void NotifyTaskBegin() const override;
193     void NotifyTaskFinished() const override;
194 
195     // judge_typedarray
196     bool NapiNewTypedArray(NativeTypedArrayType typedArrayType,
197                            Local<panda::ArrayBufferRef> arrayBuf,
198                            size_t byte_offset, size_t length, napi_value* result) override;
199     bool NapiNewSendableTypedArray(NativeTypedArrayType typedArrayType,
200                                    Local<panda::SendableArrayBufferRef> arrayBuf,
201                                    size_t byte_offset, size_t length, napi_value* result) override;
202     NativeTypedArrayType GetTypedArrayType(panda::Local<panda::TypedArrayRef> typedArray) override;
203     NativeTypedArrayType GetSendableTypedArrayType(panda::Local<panda::SendableTypedArrayRef> typedArray) override;
204     // Call function
205     napi_value CallFunction(napi_value thisVar,
206                             napi_value function,
207                             napi_value const* argv,
208                             size_t argc) override;
209     bool RunScriptPath(const char* path, bool checkPath = false) override;
210 
211     napi_value RunScriptBuffer(const char* path, std::vector<uint8_t>& buffer, bool isBundle,
212         bool needUpdate = false) override;
213     bool RunScriptBuffer(const std::string& path, uint8_t* buffer, size_t size, bool isBundle) override;
214 
215     // Run buffer script
216     napi_value RunBufferScript(std::vector<uint8_t>& buffer) override;
217     napi_value RunActor(uint8_t* buffer, size_t size, const char* descriptor,
218         char* entryPoint = nullptr, bool checkPath = false, void* fileMapper = nullptr) override;
219     // Set lib path
220     NAPI_EXPORT void SetPackagePath(const std::string appLinPathKey, const std::vector<std::string>& packagePath);
221     napi_value CreateInstance(napi_value constructor, napi_value const* argv, size_t argc) override;
222 
223     // Create native reference
224     NativeReference* CreateReference(napi_value value, uint32_t initialRefcount, bool flag = false,
225         NapiNativeFinalize callback = nullptr, void* data = nullptr, void* hint = nullptr,
226         size_t nativeBindingSize = 0) override;
227     NativeReference* CreateXRefReference(napi_value value, uint32_t initialRefcount, bool flag = false,
228         NapiNativeFinalize callback = nullptr, void* data = nullptr);
229     NativeReference* CreateAsyncReference(napi_value value, uint32_t initialRefcount, bool flag = false,
230         NapiNativeFinalize callback = nullptr, void* data = nullptr, void* hint = nullptr) override;
231     napi_value CreatePromise(NativeDeferred** deferred) override;
232     void* CreateRuntime(bool isLimitedWorker = false) override;
233     panda::Local<panda::ObjectRef> LoadArkModule(const void *buffer, int32_t len, const std::string& fileName);
234     napi_value ValueToNapiValue(JSValueWrapper& value) override;
235     NAPI_EXPORT static napi_value ArkValueToNapiValue(napi_env env, Local<JSValueRef> value);
236 
237     std::string GetSourceCodeInfo(napi_value value, ErrorPos pos) override;
238 
239     NAPI_EXPORT bool ExecuteJsBin(const std::string& fileName, bool checkPath = false);
240     static bool IsValidPandaFile(const char* path);
241     static bool IsValidScriptBuffer(uint8_t* scriptBuffer, size_t bufferSize);
242     NAPI_EXPORT panda::Local<panda::ObjectRef> LoadModuleByName(const std::string& moduleName, bool isAppModule,
243         const std::string& param, const std::string& instanceName, void* instance, const std::string& path = "");
244 
245     void TriggerFatalException(panda::Local<panda::JSValueRef> exceptionValue) override;
246     bool AdjustExternalMemory(int64_t ChangeInBytes, int64_t* AdjustedValue) override;
247 
248     // Set jsdump thresholds
249     void SetJsDumpThresholds(size_t thresholds) override;
250 
251     // Set Appfreeze Filter
252     void SetAppFreezeFilterCallback(AppFreezeFilterCallback callback) override;
253 
254     // Set RawHeap Trim Level
255     void SetRawHeapTrimLevel(uint32_t level) override;
256 
257     // Detect performance to obtain cpuprofiler file
258     void StartCpuProfiler(const std::string& fileName = "") override;
259     void StopCpuProfiler() override;
260 
261     void ResumeVM() override;
262     bool SuspendVM() override;
263     bool IsSuspended() override;
264     bool CheckSafepoint() override;
265     bool SuspendVMById(uint32_t tid) override;
266     void ResumeVMById(uint32_t tid) override;
267 
268     // isVmMode means the internal class in vm is visible.
269     // isPrivate means the number and string is not visible.
270     void DumpHeapSnapshot(const std::string &path, bool isVmMode = true, DumpFormat dumpFormat = DumpFormat::JSON,
271         bool isPrivate = false, bool captureNumericValue = false, bool isJSLeakWatcher = false) override;
272     void DumpHeapSnapshot(bool isFullGC, const std::string &path,
273         const std::function<void(uint8_t)> &callback) override;
274     void DumpCpuProfile() override;
275     // Dump the file into faultlog for heap leak.
276     void DumpHeapSnapshot(bool isVmMode = true, DumpFormat dumpFormat = DumpFormat::JSON,
277         bool isPrivate = false, bool isFullGC = true) override;
278     bool BuildNativeAndJsStackTrace(std::string& stackTraceStr) override;
279     bool BuildJsStackTrace(std::string& stackTraceStr) override;
280     bool BuildJsStackInfoListWithCustomDepth(std::vector<JsFrameInfo>& jsFrames)
281         override;
282     void GetMainThreadStackTrace(napi_env env, std::string &stackTraceStr) override;
283 
284     bool DeleteWorker(NativeEngine* workerEngine) override;
285     bool StartHeapTracking(double timeInterval, bool isVmMode = true) override;
286     bool StopHeapTracking(const std::string& filePath) override;
287 
288     void PrintStatisticResult() override;
289     void StartRuntimeStat() override;
290     void StopRuntimeStat() override;
291     size_t GetArrayBufferSize() override;
292     size_t GetHeapTotalSize() override;
293     size_t GetHeapUsedSize() override;
294     size_t GetHeapObjectSize() override;
295     size_t GetHeapLimitSize() override;
296     size_t GetProcessHeapLimitSize() override;
297     size_t GetGCCount() override;
298     size_t GetGCDuration() override;
299     size_t GetAccumulatedAllocateSize() override;
300     size_t GetAccumulatedFreeSize() override;
301     size_t GetFullGCLongTimeCount() override;
302     void NotifyApplicationState(bool inBackground) override;
303     void NotifyIdleStatusControl(std::function<void(bool)> callback) override;
304     void NotifyIdleTime(int idleMicroSec) override;
305     void NotifyMemoryPressure(bool inHighMemoryPressure = false) override;
306     void NotifyForceExpandState(int32_t value) override;
307     void NotifyForceExpandState(uint64_t tid, int32_t value) override;
308     void RegisterAppStateCallback(NapiAppStateCallback callback) override;
309 
310     void AllowCrossThreadExecution() const override;
311     static void PromiseRejectCallback(void* values);
312 
313     void SetMockModuleList(const std::map<std::string, std::string> &list) override;
314     int32_t GetObjectHash(napi_env env, napi_value src) override;
315 
316     // debugger
317     bool IsMixedDebugEnabled();
318     void JsHeapStart();
319     uint64_t GetCurrentTickMillseconds();
320     bool JudgmentDumpExecuteTask(int pid);
321     void JudgmentDump(size_t limitSize);
322     void NotifyNativeCalling(const void *nativeAddress);
323 
324     void PostFinalizeTasks();
325     void PostAsyncTask(panda::AsyncNativeCallbacksPack *callbacksPack);
326     void PostTriggerGCTask(panda::TriggerGCData& data) override;
327 
GetArkFinalizersPack()328     ArkFinalizersPack &GetArkFinalizersPack()
329     {
330         return arkFinalizersPack_;
331     }
332 
GetPendingAsyncFinalizers()333     std::vector<RefAsyncFinalizer> &GetPendingAsyncFinalizers()
334     {
335         return pendingAsyncFinalizers_;
336     }
337 
338     void RegisterNapiUncaughtExceptionHandler(NapiUncaughtExceptionCallback callback) override;
339     void HandleUncaughtException() override;
340     bool HasPendingException() override;
341     void RegisterPermissionCheck(PermissionCheckCallback callback) override;
342     bool ExecutePermissionCheck() override;
343     void RegisterTranslateBySourceMap(SourceMapCallback callback) override;
344     std::string ExecuteTranslateBySourceMap(const std::string& rawStack) override;
345         void RegisterSourceMapTranslateCallback(SourceMapTranslateCallback callback) override;
346     panda::Local<panda::ObjectRef> GetModuleFromName(
347         const std::string& moduleName, bool isAppModule, const std::string& id, const std::string& param,
348         const std::string& instanceName, void** instance);
349     napi_value NapiLoadModule(const char* path) override;
350     napi_value NapiLoadModuleWithInfo(const char* path, const char* module_info) override;
351     napi_value NapiLoadModuleWithInfoForHybridApp(const char* path, const char* module_info) override;
352     std::string GetOhmurl(std::string str);
353     Local<JSValueRef> NapiLoadNativeModule(std::string path);
GetPromiseRejectCallBackRef()354     NativeReference* GetPromiseRejectCallBackRef()
355     {
356         return promiseRejectCallbackRef_;
357     }
358 
RegisterAllPromiseCallback(NapiAllPromiseRejectCallback callback)359     void RegisterAllPromiseCallback(NapiAllPromiseRejectCallback callback) override
360     {
361         allPromiseRejectCallback_ = callback;
362     }
363 
SetPromiseRejectCallBackRef(NativeReference * rejectCallbackRef)364     void SetPromiseRejectCallBackRef(NativeReference* rejectCallbackRef) override
365     {
366         promiseRejectCallbackRef_ = rejectCallbackRef;
367     }
368 
GetConcurrentCallbackFunc()369     NapiConcurrentCallback GetConcurrentCallbackFunc()
370     {
371         return concurrentCallbackFunc_;
372     }
373 
GetCheckCallbackRef()374     NativeReference* GetCheckCallbackRef()
375     {
376         return checkCallbackRef_;
377     }
378 
SetCheckCallbackRef(NativeReference * checkCallbackRef)379     void SetCheckCallbackRef(NativeReference* checkCallbackRef) override
380     {
381         checkCallbackRef_ = checkCallbackRef;
382     }
383 
GetNapiUncaughtExceptionCallback()384     NapiUncaughtExceptionCallback GetNapiUncaughtExceptionCallback() override
385     {
386         return napiUncaughtExceptionCallback_;
387     }
388 
GetPromiseRejectCallback()389     void* GetPromiseRejectCallback() override
390     {
391         return reinterpret_cast<void*>(PromiseRejectCallback);
392     }
393 
394     void SetModuleName(panda::Local<panda::ObjectRef> &nativeObj, std::string moduleName);
395     void GetCurrentModuleInfo(std::string& moduleName, std::string& fileName, bool needRecordName) override;
396     bool GetIsBundle() override;
397     bool GetIsNormalizedOhmUrlPack() override;
398     bool GetIsDebugModeEnabled() override;
399     std::string GetBundleName() override;
400     std::string GetPkgName(const std::string &moduleName) override;
401     bool IsExecuteModuleInAbcFile(std::string bundleName, std::string moduleName, std::string ohmurl) override;
402     int GetProcessStartRealTime() override;
403 
404     static bool napiProfilerEnabled;
405     static std::string tempModuleName_;
406 
407     static void* GetNativePtrCallBack(void* data);
408     static void CopyPropertyApiFilter(const std::unique_ptr<ApiAllowListChecker>& apiAllowListChecker,
409         const EcmaVM* ecmaVm, const panda::Local<panda::ObjectRef> exportObj,
410         panda::Local<panda::ObjectRef>& exportCopy, const std::string& apiPath);
411 
IsCrossThreadCheckEnabled()412     inline bool IsCrossThreadCheckEnabled() const override
413     {
414         return crossThreadCheck_;
415     }
UpdateCrossThreadCheckStatus()416     inline void UpdateCrossThreadCheckStatus() override
417     {
418         crossThreadCheck_ = JSNApi::IsMultiThreadCheckEnabled(vm_);
419     }
420     static constexpr size_t FINALIZERS_PACK_PENDING_NATIVE_BINDING_SIZE_THRESHOLD = 500 * 1024 * 1024;  // 500 MB
421 
IsContainerScopeEnabled()422     bool IsContainerScopeEnabled() const override
423     {
424         return containerScopeEnable_;
425     }
426 
GetTimerListHead()427     NativeTimerCallbackInfo* GetTimerListHead() const
428     {
429         return TimerListHead_;
430     }
SetTimerListHead(NativeTimerCallbackInfo * info)431     void SetTimerListHead(NativeTimerCallbackInfo* info)
432     {
433         TimerListHead_ = info;
434     }
435 
IsMainEnvContext()436     inline bool IsMainEnvContext() const override
437     {
438         return isMainEnvContext_;
439     }
440 
IsMultiContextEnabled()441     inline bool IsMultiContextEnabled() const override
442     {
443         return isMultiContextEnabled_;
444     }
445 
SetMultiContextEnabled(bool enabled)446     inline void SetMultiContextEnabled(bool enabled) override
447     {
448         isMultiContextEnabled_ = enabled;
449     }
450 
451     Local<JSValueRef> GetContext() const override;
452 
453     napi_status SwitchContext() override;
454 
455     napi_status DestroyContext() override;
456 
457     void NotifyVMIgnoreFinalizeCallback() const override;
458 #if defined(PREVIEW)
459     static void SetCurrentPreviewenv(bool enableFileOperation);
460 #endif
461 private:
462     // ArkNativeEngine constructor for multi-context
463     ArkNativeEngine(NativeEngine* parent, EcmaVM* vm, const Local<JSValueRef>& context);
464     void DeconstructCtxEnv();
465     static void EnvironmentCleanup(void* arg);
466 
467     // -1: failed to load module
468     //  0: success to found module -> need load
469     //  1: success to load module -> return exports
470     int CheckAndGetModule(
471         JsiRuntimeCallInfo *info,
472         NativeModuleManager* moduleManager,
473         bool isAppModule,
474         Local<panda::StringRef> &moduleName,
475         NativeModule *&module,
476         Local<JSValueRef> &exports,
477         std::string &errInfo
478     );
479     Local<JSValueRef> LoadNativeModule(
480         NativeModuleManager* moduleManager,
481         Local<panda::StringRef> &moduleName,
482         NativeModule* module,
483         Local<JSValueRef> exports,
484         std::string &errInfo);
485     static Local<JSValueRef> RequireNapi(JsiRuntimeCallInfo *info);
486     static Local<JSValueRef> RequireNapiForCtxEnv(JsiRuntimeCallInfo *info);
487     static Local<JSValueRef> RequireInternal(JsiRuntimeCallInfo *info);
488 
GetNapiOptions()489     inline NapiOptions *GetNapiOptions() const override
490     {
491         return options_;
492     }
493 
494     void EnableNapiProfiler() override;
495 
496     static void RunCallbacks(ArkFinalizersPack *finalizersPack);
497     static void RunAsyncCallbacks(std::vector<RefAsyncFinalizer> *finalizers);
498     static void RunCallbacks(panda::AsyncNativeCallbacksPack *callbacks);
499     static void RunCallbacks(panda::TriggerGCData *triggerGCData);
500     static void SetAttribute(bool isLimitedWorker, panda::RuntimeOption &option);
501     static NativeEngine* CreateRuntimeFunc(NativeEngine* engine, void* jsEngine, bool isLimitedWorker = false);
502     static NativeEngine* GetArkNativeEngineByID(uint64_t tid);
503     static bool CheckArkApiAllowList(
504         NativeModule* module, panda::ecmascript::ApiCheckContext context, panda::Local<panda::ObjectRef>& exportCopy);
IncreasePendingFinalizersPackNativeBindingSize(size_t nativeBindingSize)505     void IncreasePendingFinalizersPackNativeBindingSize(size_t nativeBindingSize)
506     {
507         pendingFinalizersPackNativeBindingSize_ += nativeBindingSize;
508     }
DecreasePendingFinalizersPackNativeBindingSize(size_t nativeBindingSize)509     void DecreasePendingFinalizersPackNativeBindingSize(size_t nativeBindingSize)
510     {
511         pendingFinalizersPackNativeBindingSize_ -= nativeBindingSize;
512     }
513 
IsLimitWorker()514     bool IsLimitWorker() const override
515     {
516         return isLimitedWorker_;
517     }
518 
519     // ecma vm
520     EcmaVM* vm_ = nullptr;
521     bool needStop_ = false;
522     panda::LocalScope topScope_;
523     panda::Global<panda::JSValueRef> context_;
524 
525     // for context env
526     ArkNativeEngine* parentEngine_ { nullptr };
527     static std::atomic<NapiModuleValidateCallback> moduleValidateCallback_;
528 #if defined(PREVIEW)
529     static bool enableFileOperation_;
530 #endif
531 
532     NapiConcurrentCallback concurrentCallbackFunc_ { nullptr };
533     NativeReference* promiseRejectCallbackRef_ { nullptr };
534     NativeReference* checkCallbackRef_ { nullptr };
535     std::map<NativeModule*, panda::Global<panda::JSValueRef>> loadedModules_ {};
536     static PermissionCheckCallback permissionCheckCallback_;
537     NapiUncaughtExceptionCallback napiUncaughtExceptionCallback_ { nullptr };
538     NapiAllPromiseRejectCallback allPromiseRejectCallback_ {nullptr};
539     SourceMapCallback SourceMapCallback_ { nullptr };
540     static bool napiProfilerParamReaded;
541     bool isLimitedWorker_ = false;
542     size_t pendingFinalizersPackNativeBindingSize_ {0};
543     ArkFinalizersPack arkFinalizersPack_ {};
544     std::vector<RefAsyncFinalizer> pendingAsyncFinalizers_ {};
545     // napi options and its cache
546     NapiOptions* options_ { nullptr };
547     bool crossThreadCheck_ { false };
548     // Initialize the default value to false rather than isolating it with macros.
549     bool containerScopeEnable_ { false };
550     NativeTimerCallbackInfo* TimerListHead_ {nullptr};
551     bool isMainEnvContext_ = false;
552     bool isMultiContextEnabled_ = false;
553     ArkNativeEngineState engineState_ { ArkNativeEngineState::RUNNING };
554     AppStateNotifier interopAppState_ {};
555 };
556 #endif /* FOUNDATION_ACE_NAPI_NATIVE_ENGINE_IMPL_ARK_ARK_NATIVE_ENGINE_H */
557