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 ECMASCRIPT_TOOLING_BACKEND_DEBUGGER_EXECUTOR_H
17#define ECMASCRIPT_TOOLING_BACKEND_DEBUGGER_EXECUTOR_H
18
19#include "ecmascript/napi/include/jsnapi.h"
20
21#include "libpandabase/macros.h"
22
23namespace panda::ecmascript {
24class FrameHandler;
25namespace tooling {
26class DebuggerExecutor {
27public:
28    DebuggerExecutor() = default;
29    ~DebuggerExecutor() = default;
30
31    static void Initialize(const EcmaVM *vm);
32
33    static Local<JSValueRef> GetValue(const EcmaVM *vm, const FrameHandler *frameHandler, Local<StringRef> name);
34    static bool SetValue(const EcmaVM *vm, FrameHandler *frameHandler,
35                         Local<StringRef> name, Local<JSValueRef> value);
36
37private:
38    NO_COPY_SEMANTIC(DebuggerExecutor);
39    NO_MOVE_SEMANTIC(DebuggerExecutor);
40
41    static Local<JSValueRef> DebuggerGetValue(JsiRuntimeCallInfo *runtimeCallInfo);
42    static Local<JSValueRef> DebuggerSetValue(JsiRuntimeCallInfo *runtimeCallInfo);
43
44    static void ThrowException(const EcmaVM *vm, const std::string &error);
45
46    static Local<JSValueRef> GetLocalValue(const EcmaVM *vm, const FrameHandler *frameHandler, Local<StringRef> name);
47    static Local<JSValueRef> GetLexicalValue(const EcmaVM *vm, const FrameHandler *frameHandler,
48                                             Local<StringRef> name);
49    static Local<JSValueRef> GetModuleValue(const EcmaVM *vm, const FrameHandler *frameHandler, Local<StringRef> name);
50    static Local<JSValueRef> GetGlobalValue(const EcmaVM *vm, Local<StringRef> name);
51
52    static bool SetLocalValue(const EcmaVM *vm, FrameHandler *frameHandler,
53                              Local<StringRef> name, Local<JSValueRef> value);
54    static bool SetLexicalValue(const EcmaVM *vm, const FrameHandler *frameHandler,
55                                Local<StringRef> name, Local<JSValueRef> value);
56    static bool SetModuleValue(const EcmaVM *vm, const FrameHandler *frameHandler,
57                               Local<StringRef> name, Local<JSValueRef> value);
58    static bool SetGlobalValue(const EcmaVM *vm, Local<StringRef> name, Local<JSValueRef> value);
59
60    static constexpr uint32_t NUM_ARGS = 2;
61};
62}  // namespace tooling
63}  // namespace panda::ecmascript
64
65#endif  // ECMASCRIPT_TOOLING_BACKEND_DEBUGGER_EXECUTOR_H
66