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