diff --git a/tooling/client/utils/cli_command.cpp b/tooling/client/utils/cli_command.cpp index abde734053d22e09057061d14c241b65533b758e..80810248d4958c9c82cccab4352d2dd5ea393216 100644 --- a/tooling/client/utils/cli_command.cpp +++ b/tooling/client/utils/cli_command.cpp @@ -547,7 +547,8 @@ ErrCode CliCommand::ShowstackCommand(const std::string &cmd) ErrCode CliCommand::PrintCommand(const std::string &cmd) { - if (GetArgList().size() > 1) { + int TWO_ARGS = 2; + if (GetArgList().size() > TWO_ARGS) { OutputCommand(cmd, false); return ErrCode::ERR_FAIL; } @@ -563,6 +564,15 @@ ErrCode CliCommand::PrintCommand(const std::string &cmd) int32_t objectId = variableManager.FindObjectIdWithIndex(std::stoi(GetArgList()[0])); runtimeClient.SetObjectId(std::to_string(objectId)); } + if (GetArgList().size() == TWO_ARGS) { + if (!Utils::IsNumber(GetArgList()[1])) { + return ErrCode::ERR_FAIL; + } + runtimeClient.SetIsInitializeTree(false); + VariableManager &variableManager = session->GetVariableManager(); + int32_t objectId = std::stoi(GetArgList()[1]); + runtimeClient.SetObjectId(std::to_string(objectId)); + } result = runtimeClient.DispatcherCmd(cmd); if (result) { runtimeClient.SetObjectId("0"); diff --git a/tooling/test/BUILD.gn b/tooling/test/BUILD.gn index 7c6c7fe64cf668ccf400bfcbd0d1a478b3df9ff1..ae5d327ac0d7f14d57366bcda398d3c46bafb439 100644 --- a/tooling/test/BUILD.gn +++ b/tooling/test/BUILD.gn @@ -48,6 +48,8 @@ test_js_files = [ "export_variable_first", "export_variable_second", "module_variable", + "local_export", + "module_watch", "dropframe", "local_variable_scope", "container", @@ -71,7 +73,8 @@ foreach(file, test_js_files) { dst_file = rebase_path(test_abc) extra_args = [ "--debug" ] if (file == "module_variable" || file == "export_variable_first" || - file == "export_variable_second") { + file == "export_variable_second" || file == "local_export" || + file == "module_watch") { extra_args += [ "--module" ] } extra_args += [ "--merge-abc" ] diff --git a/tooling/test/client_utils/test_list.cpp b/tooling/test/client_utils/test_list.cpp index ad742ab9023b01aee31aabbadd6f650939baea40..fbb937740f0f99d5e1656c3e39e721f5c9456d44 100644 --- a/tooling/test/client_utils/test_list.cpp +++ b/tooling/test/client_utils/test_list.cpp @@ -69,6 +69,7 @@ #include "tooling/test/testcases/js_tracing_test.h" #include "tooling/test/testcases/js_watch_basic_type_test.h" #include "tooling/test/testcases/js_watch_closure_variable_test.h" +#include "tooling/test/testcases/js_watch_module_test.h" #include "tooling/test/testcases/js_watch_other_type_test.h" #include "tooling/test/testcases/js_watch_set_type_test.h" #include "tooling/test/testcases/js_watch_test.h" @@ -90,6 +91,7 @@ static void RegisterTests() TestUtil::RegisterTest("JsExceptionTest", GetJsExceptionTest()); TestUtil::RegisterTest("JsContainerTest", GetJsContainerTest()); TestUtil::RegisterTest("JsModuleVariableTest", GetJsModuleVariableTest()); + TestUtil::RegisterTest("JsWatchModuleTest", GetJsWatchModuleTest()); TestUtil::RegisterTest("JsSourceTest", GetJsSourceTest()); TestUtil::RegisterTest("JsTracingTest", GetJsTracingTest()); TestUtil::RegisterTest("JsWatchTest", GetJsWatchTest()); diff --git a/tooling/test/testcases/js/local_export.js b/tooling/test/testcases/js/local_export.js new file mode 100644 index 0000000000000000000000000000000000000000..216c4471e8067622265a63e38412f7d0d22ec848 --- /dev/null +++ b/tooling/test/testcases/js/local_export.js @@ -0,0 +1,19 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +var A = 555 +export {A as A_E} + +export var B = 200 diff --git a/tooling/test/testcases/js/module_watch.js b/tooling/test/testcases/js/module_watch.js new file mode 100644 index 0000000000000000000000000000000000000000..400c05b8ea95dcb555991bbf787a62579c5878a0 --- /dev/null +++ b/tooling/test/testcases/js/module_watch.js @@ -0,0 +1,26 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import * as all from "./local_export.js" + +export function Func1() +{ + var count = 111; +} +export {Func1 as Func1_I} + +let allTest = all +export {allTest} +let a = 0 diff --git a/tooling/test/testcases/js_watch_module_test.h b/tooling/test/testcases/js_watch_module_test.h new file mode 100644 index 0000000000000000000000000000000000000000..884cb8ad5d1ec51bc93b8358cd1c2b41362724e5 --- /dev/null +++ b/tooling/test/testcases/js_watch_module_test.h @@ -0,0 +1,161 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef ECMASCRIPT_TOOLING_TEST_TESTCASES_JS_WATCH_MODULE_TEST_H +#define ECMASCRIPT_TOOLING_TEST_TESTCASES_JS_WATCH_MODULE_TEST_H + +#include "tooling/test/client_utils/test_util.h" +#include "ecmascript/tests/test_helper.h" + +namespace panda::ecmascript::tooling::test { +class JsWatchModuleTest : public TestActions { +public: + JsWatchModuleTest() + { + testAction = { + {SocketAction::SEND, "enable"}, + {SocketAction::RECV, "", ActionRule::CUSTOM_RULE, MatchRule::replySuccess}, + {SocketAction::SEND, "runtime-enable"}, + {SocketAction::RECV, "", ActionRule::CUSTOM_RULE, MatchRule::replySuccess}, + {SocketAction::SEND, "run"}, + {SocketAction::RECV, "", ActionRule::CUSTOM_RULE, MatchRule::replySuccess}, + // load local_export.js + {SocketAction::RECV, "Debugger.scriptParsed", ActionRule::STRING_CONTAIN}, + {SocketAction::RECV, "Debugger.paused", ActionRule::STRING_CONTAIN}, + {SocketAction::SEND, "resume"}, + {SocketAction::RECV, "Debugger.resumed", ActionRule::STRING_CONTAIN}, + {SocketAction::RECV, "", ActionRule::CUSTOM_RULE, MatchRule::replySuccess}, + // load module_watch.js + {SocketAction::RECV, "Debugger.scriptParsed", ActionRule::STRING_CONTAIN}, + // break on start + {SocketAction::RECV, "Debugger.paused", ActionRule::STRING_CONTAIN}, + + // set breakpoint + {SocketAction::SEND, "b " DEBUGGER_JS_DIR "module_watch.js 26"}, + {SocketAction::RECV, "", ActionRule::CUSTOM_RULE, MatchRule::replySuccess}, + + // hit breakpoint after resume first time + {SocketAction::SEND, "resume"}, + {SocketAction::RECV, "Debugger.resumed", ActionRule::STRING_CONTAIN}, + {SocketAction::RECV, "", ActionRule::CUSTOM_RULE, MatchRule::replySuccess}, + {SocketAction::RECV, "Debugger.paused", ActionRule::CUSTOM_RULE, + [this](auto recv, auto, auto) -> bool { + return RecvHitBreakInfo(recv, 25); + } + }, + {SocketAction::SEND, "p o 1"}, + {SocketAction::RECV, "", ActionRule::CUSTOM_RULE, + [this] (auto recv, auto, auto) -> bool { + return GetPropertiesInfo(recv); + } + }, + // reply success and run + {SocketAction::SEND, "success"}, + {SocketAction::SEND, "resume"}, + {SocketAction::RECV, "Debugger.resumed", ActionRule::STRING_CONTAIN}, + {SocketAction::RECV, "", ActionRule::CUSTOM_RULE, MatchRule::replySuccess}, + }; + } + bool GetPropertiesInfo(std::string recv) + { + std::unique_ptr json = PtJson::Parse(recv); + + std::unique_ptr result; + GTEST_LOG_(ERROR) << "JsWatchModuleTestChannel: SendNotification 3:\n" << json->Stringify(); + int id; + Result ret = json->GetInt("id", &id); + if (ret != Result::SUCCESS) { + return false; + } + + ret = json->GetObject("result", &result); + if (ret != Result::SUCCESS) { + return false; + } + + std::unique_ptr innerResult; + ret = result->GetArray("result", &innerResult); + if (ret != Result::SUCCESS) { + return false; + } + std::unique_ptr value; + GTEST_LOG_(ERROR) << "JsWatchModuleTestChannel: object:\n" << innerResult->Get(1)->Stringify(); + ret = innerResult->Get(1)->GetObject("value", &value); + if (ret != Result::SUCCESS) { + return false; + } + std::string type; + ret = value->GetString("type", &type); + if (ret != Result::SUCCESS) { + return false; + } + GTEST_LOG_(ERROR) << "JsWatchModuleTestChannel: type:\n" << type.c_str(); + if (type == "undefined") { + return false; + } + RuntimeClient runtimeClient(0); + runtimeClient.HandleGetProperties(std::move(json), id); + return true; + } + bool RecvHitBreakInfo(std::string recv, int line) + { + std::unique_ptr json = PtJson::Parse(recv); + Result ret; + std::string method = ""; + ret = json->GetString("method", &method); + if (ret != Result::SUCCESS || method != "Debugger.paused") { + return false; + } + + std::unique_ptr params = nullptr; + ret = json->GetObject("params", ¶ms); + if (ret != Result::SUCCESS) { + return false; + } + + std::unique_ptr hitBreakpoints = nullptr; + ret = params->GetArray("hitBreakpoints", &hitBreakpoints); + if (ret != Result::SUCCESS) { + return false; + } + + std::string breakpoint = ""; + breakpoint = hitBreakpoints->Get(0)->GetString(); + if (ret != Result::SUCCESS || breakpoint.find(sourceFile_) == std::string::npos || + breakpoint.find(std::to_string(line)) == std::string::npos) { + return false; + } + return true; + } + + std::pair GetEntryPoint() override + { + return {pandaFile_, entryPoint_}; + } + ~JsWatchModuleTest() = default; + +private: + std::string pandaFile_ = DEBUGGER_ABC_DIR "module_watch.abc"; + std::string sourceFile_ = DEBUGGER_JS_DIR "module_watch.js"; + std::string entryPoint_ = "module_watch"; +}; + +std::unique_ptr GetJsWatchModuleTest() +{ + return std::make_unique(); +} +} // namespace panda::ecmascript::tooling::test + +#endif // ECMASCRIPT_TOOLING_TEST_TESTCASES_JS_WATCH_MODULE_TEST_H