1 /*
2  * Copyright (c) 2020 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 OHOS_ACELITE_JS_APP_ENVIRONMENT_H
17 #define OHOS_ACELITE_JS_APP_ENVIRONMENT_H
18 
19 #include "js_debugger_config.h"
20 #include "non_copyable.h"
21 
22 namespace OHOS {
23 namespace ACELite {
24 /**
25  * @brief Environment of js app.
26  */
27 class JsAppEnvironment final : public MemoryHeap {
28 public:
29     ACE_DISALLOW_COPY_AND_MOVE(JsAppEnvironment);
30     /**
31      * @brief: get instance of js app Environment.
32      *
33      * @returns: js app environment instance
34      */
GetInstance()35     static JsAppEnvironment *GetInstance()
36     {
37         static JsAppEnvironment instance;
38         return &instance;
39     }
40 
41     /**
42      * @brief: init js framework.
43      */
44     void InitJsFramework() const;
45     /**
46      * @brief: cleanup resources
47      */
48     void Cleanup();
49     /*
50      * @brief: this is called when preparing the environment for the application running, to decide
51      * the snapshot mode or JS parsing mode.
52      */
53     void InitRuntimeMode();
IsSnapshotMode()54     bool IsSnapshotMode() const
55     {
56         return snapshotMode_;
57     }
58 
59 private:
60     void LoadAceBuiltInModules() const;
61     JsAppEnvironment();
~JsAppEnvironment()62     ~JsAppEnvironment() {}
63     void LoadFramework() const;
64     // we use snapshot as default on device and JS parser as default on simulator
65     bool snapshotMode_;
66 };
67 } // namespace ACELite
68 } // namespace OHOS
69 
70 #endif // OHOS_ACELITE_JS_APP_ENVIRONMENT_H
71