• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 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 ECMASCRIPT_TOOLING_INTERFACE_JS_DEBUGGER_MANAGER_H
17 #define ECMASCRIPT_TOOLING_INTERFACE_JS_DEBUGGER_MANAGER_H
18 
19 #include "libpandabase/os/library_loader.h"
20 
21 #include "ecmascript/interpreter/frame_handler.h"
22 #include "ecmascript/napi/include/jsnapi.h"
23 #include "ecmascript/tooling/interface/notification_manager.h"
24 
25 namespace panda::ecmascript::tooling {
26 class ProtocolHandler;
27 class JsDebuggerManager {
28 public:
29     using LibraryHandle = os::library_loader::LibraryHandle;
30     using ObjectUpdaterFunc =
31         std::function<void(const InterpretedFrameHandler *, std::string_view, Local<JSValueRef>)>;
32 
33     JsDebuggerManager() = default;
~JsDebuggerManager()34     ~JsDebuggerManager()
35     {
36         delete notificationManager_;
37     }
38 
39     NO_COPY_SEMANTIC(JsDebuggerManager);
40     NO_MOVE_SEMANTIC(JsDebuggerManager);
41 
Initialize()42     void Initialize()
43     {
44         notificationManager_ = new NotificationManager();
45     }
46 
GetNotificationManager()47     NotificationManager *GetNotificationManager() const
48     {
49         return notificationManager_;
50     }
51 
SetDebugMode(bool isDebugMode)52     void SetDebugMode(bool isDebugMode)
53     {
54         isDebugMode_ = isDebugMode;
55     }
56 
IsDebugMode()57     bool IsDebugMode() const
58     {
59         return isDebugMode_;
60     }
61 
SetDebuggerHandler(ProtocolHandler * debuggerHandler)62     void SetDebuggerHandler(ProtocolHandler *debuggerHandler)
63     {
64         debuggerHandler_ = debuggerHandler;
65     }
66 
GetDebuggerHandler()67     ProtocolHandler *GetDebuggerHandler() const
68     {
69         return debuggerHandler_;
70     }
71 
SetDebugLibraryHandle(LibraryHandle handle)72     void SetDebugLibraryHandle(LibraryHandle handle)
73     {
74         debuggerLibraryHandle_ = std::move(handle);
75     }
76 
GetDebugLibraryHandle()77     const LibraryHandle &GetDebugLibraryHandle() const
78     {
79         return debuggerLibraryHandle_;
80     }
81 
SetEvalFrameHandler(std::shared_ptr<InterpretedFrameHandler> frameHandler)82     void SetEvalFrameHandler(std::shared_ptr<InterpretedFrameHandler> frameHandler)
83     {
84         frameHandler_ = frameHandler;
85     }
86 
GetEvalFrameHandler()87     const std::shared_ptr<InterpretedFrameHandler> &GetEvalFrameHandler() const
88     {
89         return frameHandler_;
90     }
91 
SetLocalScopeUpdater(ObjectUpdaterFunc * updaterFunc)92     void SetLocalScopeUpdater(ObjectUpdaterFunc *updaterFunc)
93     {
94         updaterFunc_ = updaterFunc;
95     }
96 
NotifyLocalScopeUpdated(std::string_view varName,Local<JSValueRef> value)97     void NotifyLocalScopeUpdated(std::string_view varName, Local<JSValueRef> value)
98     {
99         if (updaterFunc_ != nullptr) {
100             (*updaterFunc_)(frameHandler_.get(), varName, value);
101         }
102     }
103 
104 private:
105     bool isDebugMode_ {false};
106     ProtocolHandler *debuggerHandler_ {nullptr};
107     LibraryHandle debuggerLibraryHandle_ {nullptr};
108     NotificationManager *notificationManager_ {nullptr};
109     ObjectUpdaterFunc *updaterFunc_ {nullptr};
110 
111     std::shared_ptr<InterpretedFrameHandler> frameHandler_;
112 };
113 }  // panda::ecmascript::tooling
114 
115 #endif  // ECMASCRIPT_TOOLING_INTERFACE_JS_DEBUGGER_MANAGER_H