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