From bd650c241fc3f16fcd28de9579b9857b597633b9 Mon Sep 17 00:00:00 2001 From: wengchangcheng Date: Sat, 11 Jun 2022 21:36:43 +0800 Subject: [PATCH 1/2] Descriptor: debugger refactor of independent js_runtime [ part-3 ] details: modify Params::Create to cJson issue: https://gitee.com/openharmony/ark_js_runtime/issues/I5BUI2 Signed-off-by: wengchangcheng Change-Id: I7a89ef24a0c8e999fc76429cda34f5f0e05f4946 --- ecmascript/tooling/agent/debugger_impl.cpp | 24 +- .../tooling/agent/heapprofiler_impl.cpp | 20 +- ecmascript/tooling/agent/profiler_impl.cpp | 6 +- ecmascript/tooling/agent/runtime_impl.cpp | 6 +- ecmascript/tooling/base/pt_json.cpp | 11 + ecmascript/tooling/base/pt_json.h | 1 + ecmascript/tooling/base/pt_params.cpp | 1083 +++++++---------- ecmascript/tooling/base/pt_params.h | 69 +- ecmascript/tooling/base/pt_types.cpp | 258 +--- ecmascript/tooling/base/pt_types.h | 70 +- .../tooling/test/debugger_params_test.cpp | 162 +-- 11 files changed, 608 insertions(+), 1102 deletions(-) diff --git a/ecmascript/tooling/agent/debugger_impl.cpp b/ecmascript/tooling/agent/debugger_impl.cpp index d46f14610..a6927a4e1 100644 --- a/ecmascript/tooling/agent/debugger_impl.cpp +++ b/ecmascript/tooling/agent/debugger_impl.cpp @@ -286,8 +286,7 @@ void DebuggerImpl::DispatcherImpl::Disable(const DispatchRequest &request) void DebuggerImpl::DispatcherImpl::EvaluateOnCallFrame(const DispatchRequest &request) { - std::unique_ptr params = - EvaluateOnCallFrameParams::Create(request.GetEcmaVM(), request.GetParamsObj()); + std::unique_ptr params = EvaluateOnCallFrameParams::Create(request.GetParams()); if (params == nullptr) { SendResponse(request, DispatchResponse::Fail("wrong params")); return; @@ -301,8 +300,7 @@ void DebuggerImpl::DispatcherImpl::EvaluateOnCallFrame(const DispatchRequest &re void DebuggerImpl::DispatcherImpl::GetPossibleBreakpoints(const DispatchRequest &request) { - std::unique_ptr params = - GetPossibleBreakpointsParams::Create(request.GetEcmaVM(), request.GetParamsObj()); + std::unique_ptr params = GetPossibleBreakpointsParams::Create(request.GetParams()); if (params == nullptr) { SendResponse(request, DispatchResponse::Fail("wrong params")); return; @@ -315,8 +313,7 @@ void DebuggerImpl::DispatcherImpl::GetPossibleBreakpoints(const DispatchRequest void DebuggerImpl::DispatcherImpl::GetScriptSource(const DispatchRequest &request) { - std::unique_ptr params = - GetScriptSourceParams::Create(request.GetEcmaVM(), request.GetParamsObj()); + std::unique_ptr params = GetScriptSourceParams::Create(request.GetParams()); if (params == nullptr) { SendResponse(request, DispatchResponse::Fail("wrong params")); return; @@ -335,8 +332,7 @@ void DebuggerImpl::DispatcherImpl::Pause(const DispatchRequest &request) void DebuggerImpl::DispatcherImpl::RemoveBreakpoint(const DispatchRequest &request) { - std::unique_ptr params = - RemoveBreakpointParams::Create(request.GetEcmaVM(), request.GetParamsObj()); + std::unique_ptr params = RemoveBreakpointParams::Create(request.GetParams()); if (params == nullptr) { SendResponse(request, DispatchResponse::Fail("wrong params")); return; @@ -347,7 +343,7 @@ void DebuggerImpl::DispatcherImpl::RemoveBreakpoint(const DispatchRequest &reque void DebuggerImpl::DispatcherImpl::Resume(const DispatchRequest &request) { - std::unique_ptr params = ResumeParams::Create(request.GetEcmaVM(), request.GetParamsObj()); + std::unique_ptr params = ResumeParams::Create(request.GetParams()); if (params == nullptr) { SendResponse(request, DispatchResponse::Fail("wrong params")); return; @@ -364,8 +360,7 @@ void DebuggerImpl::DispatcherImpl::SetAsyncCallStackDepth(const DispatchRequest void DebuggerImpl::DispatcherImpl::SetBreakpointByUrl(const DispatchRequest &request) { - std::unique_ptr params = - SetBreakpointByUrlParams::Create(request.GetEcmaVM(), request.GetParamsObj()); + std::unique_ptr params = SetBreakpointByUrlParams::Create(request.GetParams()); if (params == nullptr) { SendResponse(request, DispatchResponse::Fail("wrong params")); return; @@ -380,8 +375,7 @@ void DebuggerImpl::DispatcherImpl::SetBreakpointByUrl(const DispatchRequest &req void DebuggerImpl::DispatcherImpl::SetPauseOnExceptions(const DispatchRequest &request) { - std::unique_ptr params = - SetPauseOnExceptionsParams::Create(request.GetEcmaVM(), request.GetParamsObj()); + std::unique_ptr params = SetPauseOnExceptionsParams::Create(request.GetParams()); if (params == nullptr) { SendResponse(request, DispatchResponse::Fail("wrong params")); return; @@ -393,7 +387,7 @@ void DebuggerImpl::DispatcherImpl::SetPauseOnExceptions(const DispatchRequest &r void DebuggerImpl::DispatcherImpl::StepInto(const DispatchRequest &request) { - std::unique_ptr params = StepIntoParams::Create(request.GetEcmaVM(), request.GetParamsObj()); + std::unique_ptr params = StepIntoParams::Create(request.GetParams()); if (params == nullptr) { SendResponse(request, DispatchResponse::Fail("wrong params")); return; @@ -410,7 +404,7 @@ void DebuggerImpl::DispatcherImpl::StepOut(const DispatchRequest &request) void DebuggerImpl::DispatcherImpl::StepOver(const DispatchRequest &request) { - std::unique_ptr params = StepOverParams::Create(request.GetEcmaVM(), request.GetParamsObj()); + std::unique_ptr params = StepOverParams::Create(request.GetParams()); if (params == nullptr) { SendResponse(request, DispatchResponse::Fail("wrong params")); return; diff --git a/ecmascript/tooling/agent/heapprofiler_impl.cpp b/ecmascript/tooling/agent/heapprofiler_impl.cpp index b88e8272b..cd99f1e8c 100644 --- a/ecmascript/tooling/agent/heapprofiler_impl.cpp +++ b/ecmascript/tooling/agent/heapprofiler_impl.cpp @@ -45,8 +45,7 @@ void HeapProfilerImpl::DispatcherImpl::Dispatch(const DispatchRequest &request) void HeapProfilerImpl::DispatcherImpl::AddInspectedHeapObject(const DispatchRequest &request) { - std::unique_ptr params = - AddInspectedHeapObjectParams::Create(request.GetEcmaVM(), request.GetParamsObj()); + std::unique_ptr params = AddInspectedHeapObjectParams::Create(request.GetParams()); if (params == nullptr) { SendResponse(request, DispatchResponse::Fail("wrong params")); return; @@ -75,8 +74,7 @@ void HeapProfilerImpl::DispatcherImpl::Disable(const DispatchRequest &request) void HeapProfilerImpl::DispatcherImpl::GetHeapObjectId(const DispatchRequest &request) { - std::unique_ptr params = - GetHeapObjectIdParams::Create(request.GetEcmaVM(), request.GetParamsObj()); + std::unique_ptr params = GetHeapObjectIdParams::Create(request.GetParams()); if (params == nullptr) { SendResponse(request, DispatchResponse::Fail("wrong params")); return; @@ -90,8 +88,7 @@ void HeapProfilerImpl::DispatcherImpl::GetHeapObjectId(const DispatchRequest &re void HeapProfilerImpl::DispatcherImpl::GetObjectByHeapObjectId(const DispatchRequest &request) { - std::unique_ptr params = - GetObjectByHeapObjectIdParams::Create(request.GetEcmaVM(), request.GetParamsObj()); + std::unique_ptr params = GetObjectByHeapObjectIdParams::Create(request.GetParams()); if (params == nullptr) { SendResponse(request, DispatchResponse::Fail("wrong params")); return; @@ -114,8 +111,7 @@ void HeapProfilerImpl::DispatcherImpl::GetSamplingProfile(const DispatchRequest void HeapProfilerImpl::DispatcherImpl::StartSampling(const DispatchRequest &request) { - std::unique_ptr params = - StartSamplingParams::Create(request.GetEcmaVM(), request.GetParamsObj()); + std::unique_ptr params = StartSamplingParams::Create(request.GetParams()); if (params == nullptr) { SendResponse(request, DispatchResponse::Fail("wrong params")); return; @@ -127,7 +123,7 @@ void HeapProfilerImpl::DispatcherImpl::StartSampling(const DispatchRequest &requ void HeapProfilerImpl::DispatcherImpl::StartTrackingHeapObjects(const DispatchRequest &request) { std::unique_ptr params = - StartTrackingHeapObjectsParams::Create(request.GetEcmaVM(), request.GetParamsObj()); + StartTrackingHeapObjectsParams::Create(request.GetParams()); if (params == nullptr) { SendResponse(request, DispatchResponse::Fail("wrong params")); return; @@ -147,8 +143,7 @@ void HeapProfilerImpl::DispatcherImpl::StopSampling(const DispatchRequest &reque void HeapProfilerImpl::DispatcherImpl::StopTrackingHeapObjects(const DispatchRequest &request) { - std::unique_ptr params = - StopTrackingHeapObjectsParams::Create(request.GetEcmaVM(), request.GetParamsObj()); + std::unique_ptr params = StopTrackingHeapObjectsParams::Create(request.GetParams()); if (params == nullptr) { SendResponse(request, DispatchResponse::Fail("wrong params")); return; @@ -159,8 +154,7 @@ void HeapProfilerImpl::DispatcherImpl::StopTrackingHeapObjects(const DispatchReq void HeapProfilerImpl::DispatcherImpl::TakeHeapSnapshot(const DispatchRequest &request) { - std::unique_ptr params = - StopTrackingHeapObjectsParams::Create(request.GetEcmaVM(), request.GetParamsObj()); + std::unique_ptr params = StopTrackingHeapObjectsParams::Create(request.GetParams()); if (params == nullptr) { SendResponse(request, DispatchResponse::Fail("wrong params")); return; diff --git a/ecmascript/tooling/agent/profiler_impl.cpp b/ecmascript/tooling/agent/profiler_impl.cpp index 022030a07..78f59f21e 100644 --- a/ecmascript/tooling/agent/profiler_impl.cpp +++ b/ecmascript/tooling/agent/profiler_impl.cpp @@ -76,8 +76,7 @@ void ProfilerImpl::DispatcherImpl::Stop(const DispatchRequest &request) void ProfilerImpl::DispatcherImpl::SetSamplingInterval(const DispatchRequest &request) { - std::unique_ptr params = - SetSamplingIntervalParams::Create(request.GetEcmaVM(), request.GetParamsObj()); + std::unique_ptr params = SetSamplingIntervalParams::Create(request.GetParams()); if (params == nullptr) { SendResponse(request, DispatchResponse::Fail("wrong params")); return; @@ -106,8 +105,7 @@ void ProfilerImpl::DispatcherImpl::TakePreciseCoverage(const DispatchRequest &re void ProfilerImpl::DispatcherImpl::StartPreciseCoverage(const DispatchRequest &request) { - std::unique_ptr params = - StartPreciseCoverageParams::Create(request.GetEcmaVM(), request.GetParamsObj()); + std::unique_ptr params = StartPreciseCoverageParams::Create(request.GetParams()); if (params == nullptr) { SendResponse(request, DispatchResponse::Fail("wrong params")); return; diff --git a/ecmascript/tooling/agent/runtime_impl.cpp b/ecmascript/tooling/agent/runtime_impl.cpp index ded0e698f..885b3ba89 100644 --- a/ecmascript/tooling/agent/runtime_impl.cpp +++ b/ecmascript/tooling/agent/runtime_impl.cpp @@ -65,8 +65,7 @@ void RuntimeImpl::DispatcherImpl::RunIfWaitingForDebugger(const DispatchRequest void RuntimeImpl::DispatcherImpl::GetProperties(const DispatchRequest &request) { - std::unique_ptr params = - GetPropertiesParams::Create(request.GetEcmaVM(), request.GetParamsObj()); + std::unique_ptr params = GetPropertiesParams::Create(request.GetParams()); if (params == nullptr) { SendResponse(request, DispatchResponse::Fail("wrong params")); return; @@ -90,8 +89,7 @@ void RuntimeImpl::DispatcherImpl::GetProperties(const DispatchRequest &request) void RuntimeImpl::DispatcherImpl::CallFunctionOn(const DispatchRequest &request) { - std::unique_ptr params = - CallFunctionOnParams::Create(request.GetEcmaVM(), request.GetParamsObj()); + std::unique_ptr params = CallFunctionOnParams::Create(request.GetParams()); if (params == nullptr) { SendResponse(request, DispatchResponse::Fail("wrong params")); return; diff --git a/ecmascript/tooling/base/pt_json.cpp b/ecmascript/tooling/base/pt_json.cpp index 967206a92..2943e98b2 100644 --- a/ecmascript/tooling/base/pt_json.cpp +++ b/ecmascript/tooling/base/pt_json.cpp @@ -418,4 +418,15 @@ Result PtJson::GetArray(const char *key, std::unique_ptr *value) const *value = std::make_unique(item); return Result::SUCCESS; } + +Result PtJson::GetAny(const char *key, std::unique_ptr *value) const +{ + cJSON *item = cJSON_GetObjectItem(object_, key); + if (item == nullptr) { + return Result::NOT_EXIST; + } + + *value = std::make_unique(item); + return Result::SUCCESS; +} } // namespace panda::ecmascript diff --git a/ecmascript/tooling/base/pt_json.h b/ecmascript/tooling/base/pt_json.h index d38eb3cd9..88f6cc15f 100644 --- a/ecmascript/tooling/base/pt_json.h +++ b/ecmascript/tooling/base/pt_json.h @@ -99,6 +99,7 @@ public: Result GetString(const char *key, std::string *value) const; Result GetObject(const char *key, std::unique_ptr *value) const; Result GetArray(const char *key, std::unique_ptr *value) const; + Result GetAny(const char *key, std::unique_ptr *value) const; private: cJSON *object_ = nullptr; diff --git a/ecmascript/tooling/base/pt_params.cpp b/ecmascript/tooling/base/pt_params.cpp index 2118cc126..1ebfe9e3c 100644 --- a/ecmascript/tooling/base/pt_params.cpp +++ b/ecmascript/tooling/base/pt_params.cpp @@ -16,43 +16,16 @@ #include "ecmascript/tooling/base/pt_params.h" namespace panda::ecmascript::tooling { -std::unique_ptr EnableParams::Create(const EcmaVM *ecmaVm, const Local ¶ms) -{ - ASSERT(ecmaVm); - if (params.IsEmpty()) { - LOG(ERROR, DEBUGGER) << "EnableParams::Create params is nullptr"; - return nullptr; - } - std::string error; - auto paramsObject = std::make_unique(); - - Local result = - Local(params)->Get(ecmaVm, Local(StringRef::NewFromUtf8(ecmaVm, "maxScriptsCacheSize"))); - if (!result.IsEmpty() && !result->IsUndefined()) { - if (result->IsNumber()) { - paramsObject->maxScriptsCacheSize_ = Local(result)->Value(); - } else { - error += "'maxScriptsCacheSize' should be a Number;"; - } - } - if (!error.empty()) { - LOG(ERROR, DEBUGGER) << "EnableParams::Create " << error; - return nullptr; - } - - return paramsObject; -} - std::unique_ptr EnableParams::Create(const PtJson ¶ms) { auto paramsObject = std::make_unique(); std::string error; Result ret; - double result; - ret = params.GetDouble("maxScriptsCacheSize", &result); + double maxScriptsCacheSize; + ret = params.GetDouble("maxScriptsCacheSize", &maxScriptsCacheSize); if (ret == Result::SUCCESS) { - paramsObject->maxScriptsCacheSize_ = result; + paramsObject->maxScriptsCacheSize_ = maxScriptsCacheSize; } else if (ret == Result::TYPE_ERROR) { // optional value error += "Unknown 'maxScriptsCacheSize';"; } @@ -65,71 +38,67 @@ std::unique_ptr EnableParams::Create(const PtJson ¶ms) return paramsObject; } -std::unique_ptr EvaluateOnCallFrameParams::Create(const EcmaVM *ecmaVm, - const Local ¶ms) +std::unique_ptr EvaluateOnCallFrameParams::Create(const PtJson ¶ms) { - ASSERT(ecmaVm); - if (params.IsEmpty()) { - LOG(ERROR, DEBUGGER) << "EvaluateOnCallFrameParams::Create params is nullptr"; - return nullptr; - } - std::string error; auto paramsObject = std::make_unique(); + std::string error; + Result ret; - Local result = - Local(params)->Get(ecmaVm, Local(StringRef::NewFromUtf8(ecmaVm, "callFrameId"))); - if (!result.IsEmpty() && !result->IsUndefined()) { - if (result->IsString()) { - paramsObject->callFrameId_ = static_cast(DebuggerApi::StringToInt(result)); - } else { - error += "'callframeid' should be a String;"; - } + std::string callFrameId; + ret = params.GetString("callFrameId", &callFrameId); + if (ret == Result::SUCCESS) { + paramsObject->callFrameId_ = std::stoi(callFrameId); } else { - error += "should contain 'callframeid';"; + error += "Unknown 'callFrameId';"; } - - result = Local(params)->Get(ecmaVm, Local(StringRef::NewFromUtf8(ecmaVm, "expression"))); - if (!result.IsEmpty() && !result->IsUndefined()) { - if (result->IsString()) { - paramsObject->expression_ = DebuggerApi::ToStdString(result); - } else { - error += "'expression' should be a String;"; - } + std::string expression; + ret = params.GetString("expression", &expression); + if (ret == Result::SUCCESS) { + paramsObject->expression_ = std::move(expression); } else { - error += "should contain 'expression';"; + error += "Unknown 'expression';"; } - - result = Local(params)->Get(ecmaVm, Local(StringRef::NewFromUtf8(ecmaVm, "objectGroup"))); - if (!result.IsEmpty() && result->IsString()) { - paramsObject->objectGroup_ = DebuggerApi::ToStdString(result); + std::string objectGroup; + ret = params.GetString("objectGroup", &objectGroup); + if (ret == Result::SUCCESS) { + paramsObject->objectGroup_ = std::move(objectGroup); + } else if (ret == Result::TYPE_ERROR) { // optional value + error += "Unknown 'objectGroup';"; } - - result = Local(params)->Get(ecmaVm, - Local(StringRef::NewFromUtf8(ecmaVm, "includeCommandLineAPI"))); - if (!result.IsEmpty() && result->IsBoolean()) { - paramsObject->includeCommandLineApi_ = result->IsTrue(); + bool includeCommandLineAPI; + ret = params.GetBool("includeCommandLineAPI", &includeCommandLineAPI); + if (ret == Result::SUCCESS) { + paramsObject->includeCommandLineAPI_ = includeCommandLineAPI; + } else if (ret == Result::TYPE_ERROR) { // optional value + error += "Unknown 'includeCommandLineAPI';"; } - - result = Local(params)->Get(ecmaVm, Local(StringRef::NewFromUtf8(ecmaVm, "silent"))); - if (!result.IsEmpty() && result->IsBoolean()) { - paramsObject->silent_ = result->IsTrue(); + bool silent; + ret = params.GetBool("silent", &silent); + if (ret == Result::SUCCESS) { + paramsObject->silent_ = silent; + } else if (ret == Result::TYPE_ERROR) { // optional value + error += "Unknown 'silent';"; } - - result = Local(params)->Get(ecmaVm, Local(StringRef::NewFromUtf8(ecmaVm, "returnByValue"))); - if (!result.IsEmpty() && result->IsBoolean()) { - paramsObject->returnByValue_ = result->IsTrue(); + bool returnByValue; + ret = params.GetBool("returnByValue", &returnByValue); + if (ret == Result::SUCCESS) { + paramsObject->returnByValue_ = returnByValue; + } else if (ret == Result::TYPE_ERROR) { // optional value + error += "Unknown 'returnByValue';"; } - - result = - Local(params)->Get(ecmaVm, Local(StringRef::NewFromUtf8(ecmaVm, "generatePreview"))); - if (!result.IsEmpty() && result->IsBoolean()) { - paramsObject->generatePreview_ = result->IsTrue(); + bool generatePreview; + ret = params.GetBool("generatePreview", &generatePreview); + if (ret == Result::SUCCESS) { + paramsObject->generatePreview_ = generatePreview; + } else if (ret == Result::TYPE_ERROR) { // optional value + error += "Unknown 'generatePreview';"; } - - result = - Local(params)->Get(ecmaVm, Local(StringRef::NewFromUtf8(ecmaVm, "throwOnSideEffect"))); - if (!result.IsEmpty() && result->IsBoolean()) { - paramsObject->throwOnSideEffect_ = result->IsTrue(); + bool throwOnSideEffect; + ret = params.GetBool("throwOnSideEffect", &throwOnSideEffect); + if (ret == Result::SUCCESS) { + paramsObject->throwOnSideEffect_ = throwOnSideEffect; + } else if (ret == Result::TYPE_ERROR) { // optional value + error += "Unknown 'throwOnSideEffect';"; } if (!error.empty()) { @@ -139,55 +108,44 @@ std::unique_ptr EvaluateOnCallFrameParams::Create(con return paramsObject; } -std::unique_ptr GetPossibleBreakpointsParams::Create(const EcmaVM *ecmaVm, - const Local ¶ms) +std::unique_ptr GetPossibleBreakpointsParams::Create(const PtJson ¶ms) { - ASSERT(ecmaVm); - if (params.IsEmpty()) { - LOG(ERROR, DEBUGGER) << "RemoteObject::Create params is nullptr"; - return nullptr; - } - std::string error; auto paramsObject = std::make_unique(); + std::string error; + Result ret; - Local result = - Local(params)->Get(ecmaVm, Local(StringRef::NewFromUtf8(ecmaVm, "start"))); - if (!result.IsEmpty() && !result->IsUndefined()) { - if (result->IsObject()) { - std::unique_ptr obj = Location::Create(ecmaVm, result); - if (obj == nullptr) { - error += "'start' format error;"; - } else { - paramsObject->start_ = std::move(obj); - } + std::unique_ptr start; + ret = params.GetObject("start", &start); + if (ret == Result::SUCCESS) { + std::unique_ptr location = Location::Create(*start); + if (location == nullptr) { + error += "Unknown 'start';"; } else { - error += "'start' should be an Object;"; + paramsObject->start_ = std::move(location); } } else { - error += "should contain 'start';"; + error += "Unknown 'start';"; } - result = Local(params)->Get(ecmaVm, Local(StringRef::NewFromUtf8(ecmaVm, "end"))); - if (!result.IsEmpty() && !result->IsUndefined()) { - if (result->IsObject()) { - std::unique_ptr obj = Location::Create(ecmaVm, result); - if (obj == nullptr) { - error += "'end' format error;"; - } else { - paramsObject->end_ = std::move(obj); - } + std::unique_ptr end; + ret = params.GetObject("start", &end); + if (ret == Result::SUCCESS) { + std::unique_ptr location = Location::Create(*end); + if (location == nullptr) { + error += "Unknown 'end';"; } else { - error += "'end' should be an Object;"; + paramsObject->end_ = std::move(location); } + } else if (ret == Result::TYPE_ERROR) { // optional value + error += "Unknown 'end';"; } - result = - Local(params)->Get(ecmaVm, Local(StringRef::NewFromUtf8(ecmaVm, "restrictToFunction"))); - if (!result.IsEmpty() && !result->IsUndefined()) { - if (result->IsBoolean()) { - paramsObject->restrictToFunction_ = result->IsTrue(); - } else { - error += "'restrictToFunction' should be a Boolean;"; - } + bool restrictToFunction; + ret = params.GetBool("restrictToFunction", &restrictToFunction); + if (ret == Result::SUCCESS) { + paramsObject->restrictToFunction_ = restrictToFunction; + } else if (ret == Result::TYPE_ERROR) { // optional value + error += "Unknown 'restrictToFunction';"; } + if (!error.empty()) { LOG(ERROR, DEBUGGER) << "GetPossibleBreakpointsParams::Create " << error; return nullptr; @@ -196,28 +154,20 @@ std::unique_ptr GetPossibleBreakpointsParams::Crea return paramsObject; } -std::unique_ptr GetScriptSourceParams::Create(const EcmaVM *ecmaVm, - const Local ¶ms) +std::unique_ptr GetScriptSourceParams::Create(const PtJson ¶ms) { - ASSERT(ecmaVm); - if (params.IsEmpty()) { - LOG(ERROR, DEBUGGER) << "RemoteObject::Create params is nullptr"; - return nullptr; - } - std::string error; auto paramsObject = std::make_unique(); + std::string error; + Result ret; - Local result = - Local(params)->Get(ecmaVm, Local(StringRef::NewFromUtf8(ecmaVm, "scriptId"))); - if (!result.IsEmpty() && !result->IsUndefined()) { - if (result->IsString()) { - paramsObject->scriptId_ = static_cast(DebuggerApi::StringToInt(result)); - } else { - error += "'scriptId' should be a String;"; - } + std::string scriptId; + ret = params.GetString("scriptId", &scriptId); + if (ret == Result::SUCCESS) { + paramsObject->scriptId_ = std::stoi(scriptId); } else { - error += "should contain 'scriptId';"; + error += "Unknown 'scriptId';"; } + if (!error.empty()) { LOG(ERROR, DEBUGGER) << "GetScriptSourceParams::Create " << error; return nullptr; @@ -226,28 +176,20 @@ std::unique_ptr GetScriptSourceParams::Create(const EcmaV return paramsObject; } -std::unique_ptr RemoveBreakpointParams::Create(const EcmaVM *ecmaVm, - const Local ¶ms) +std::unique_ptr RemoveBreakpointParams::Create(const PtJson ¶ms) { - ASSERT(ecmaVm); - if (params.IsEmpty()) { - LOG(ERROR, DEBUGGER) << "RemoteObject::Create params is nullptr"; - return nullptr; - } - std::string error; auto paramsObject = std::make_unique(); + std::string error; + Result ret; - Local result = - Local(params)->Get(ecmaVm, Local(StringRef::NewFromUtf8(ecmaVm, "breakpointId"))); - if (!result.IsEmpty() && !result->IsUndefined()) { - if (result->IsString()) { - paramsObject->breakpointId_ = DebuggerApi::ToStdString(result); - } else { - error += "'breakpointId' should be a String;"; - } + std::string breakpointId; + ret = params.GetString("breakpointId", &breakpointId); + if (ret == Result::SUCCESS) { + paramsObject->breakpointId_ = std::move(breakpointId); } else { - error += "should contain 'breakpointId';"; + error += "Unknown 'breakpointId';"; } + if (!error.empty()) { LOG(ERROR, DEBUGGER) << "RemoveBreakpointParams::Create " << error; return nullptr; @@ -256,25 +198,20 @@ std::unique_ptr RemoveBreakpointParams::Create(const Ecm return paramsObject; } -std::unique_ptr ResumeParams::Create(const EcmaVM *ecmaVm, const Local ¶ms) +std::unique_ptr ResumeParams::Create(const PtJson ¶ms) { - ASSERT(ecmaVm); - if (params.IsEmpty()) { - LOG(ERROR, DEBUGGER) << "RemoteObject::Create params is nullptr"; - return nullptr; - } - std::string error; auto paramsObject = std::make_unique(); + std::string error; + Result ret; - Local result = - Local(params)->Get(ecmaVm, Local(StringRef::NewFromUtf8(ecmaVm, "terminateOnResume"))); - if (!result.IsEmpty() && !result->IsUndefined()) { - if (result->IsBoolean()) { - paramsObject->terminateOnResume_ = result->IsTrue(); - } else { - error += "'terminateOnResume' should be a Boolean;"; - } + bool terminateOnResume; + ret = params.GetBool("terminateOnResume", &terminateOnResume); + if (ret == Result::SUCCESS) { + paramsObject->terminateOnResume_ = terminateOnResume; + } else if (ret == Result::TYPE_ERROR) { // optional value + error += "Unknown 'terminateOnResume';"; } + if (!error.empty()) { LOG(ERROR, DEBUGGER) << "ResumeParams::Create " << error; return nullptr; @@ -283,28 +220,20 @@ std::unique_ptr ResumeParams::Create(const EcmaVM *ecmaVm, const L return paramsObject; } -std::unique_ptr SetAsyncCallStackDepthParams::Create(const EcmaVM *ecmaVm, - const Local ¶ms) +std::unique_ptr SetAsyncCallStackDepthParams::Create(const PtJson ¶ms) { - ASSERT(ecmaVm); - if (params.IsEmpty()) { - LOG(ERROR, DEBUGGER) << "RemoteObject::Create params is nullptr"; - return nullptr; - } - std::string error; auto paramsObject = std::make_unique(); + std::string error; + Result ret; - Local result = - Local(params)->Get(ecmaVm, Local(StringRef::NewFromUtf8(ecmaVm, "maxDepth"))); - if (!result.IsEmpty() && !result->IsUndefined()) { - if (result->IsNumber()) { - paramsObject->maxDepth_ = static_cast(Local(result)->Value()); - } else { - error += "'maxDepth' should be a Number;"; - } + int32_t maxDepth; + ret = params.GetInt("maxDepth", &maxDepth); + if (ret == Result::SUCCESS) { + paramsObject->maxDepth_ = maxDepth; } else { - error += "should contain 'maxDepth';"; + error += "Unknown 'maxDepth';"; } + if (!error.empty()) { LOG(ERROR, DEBUGGER) << "SetAsyncCallStackDepthParams::Create " << error; return nullptr; @@ -313,40 +242,28 @@ std::unique_ptr SetAsyncCallStackDepthParams::Crea return paramsObject; } -std::unique_ptr SetBlackboxPatternsParams::Create(const EcmaVM *ecmaVm, - const Local ¶ms) +std::unique_ptr SetBlackboxPatternsParams::Create(const PtJson ¶ms) { - ASSERT(ecmaVm); - if (params.IsEmpty()) { - LOG(ERROR, DEBUGGER) << "RemoteObject::Create params is nullptr"; - return nullptr; - } - std::string error; auto paramsObject = std::make_unique(); + std::string error; + Result ret; - Local result = - Local(params)->Get(ecmaVm, Local(StringRef::NewFromUtf8(ecmaVm, "patterns"))); - if (!result.IsEmpty() && !result->IsUndefined()) { - if (result->IsArray(ecmaVm)) { - Local array = Local(result); - int32_t len = array->Length(ecmaVm); - Local key = JSValueRef::Undefined(ecmaVm); - for (int32_t i = 0; i < len; i++) { - key = IntegerRef::New(ecmaVm, i); - Local value = Local(array)->Get(ecmaVm, key->ToString(ecmaVm)); - if (value->IsString()) { - paramsObject->patterns_.emplace_back( - DebuggerApi::ToStdString(value)); - } else { + std::unique_ptr patterns; + ret = params.GetArray("patterns", &patterns); + if (ret == Result::SUCCESS) { + int32_t len = patterns->GetSize(); + for (int32_t i = 0; i < len; ++i) { + std::unique_ptr item = patterns->Get(i); + if (item->IsString()) { + paramsObject->patterns_.emplace_back(item->GetString()); + } else { error += "'patterns' items should be a String;"; - } } - } else { - error += "'patterns' should be an Array;"; } } else { - error += "should contain 'patterns';"; + error += "Unknown 'patterns';"; } + if (!error.empty()) { LOG(ERROR, DEBUGGER) << "SetBlackboxPatternsParams::Create " << error; return nullptr; @@ -355,67 +272,53 @@ std::unique_ptr SetBlackboxPatternsParams::Create(con return paramsObject; } -std::unique_ptr SetBreakpointByUrlParams::Create(const EcmaVM *ecmaVm, - const Local ¶ms) +std::unique_ptr SetBreakpointByUrlParams::Create(const PtJson ¶ms) { - ASSERT(ecmaVm); - if (params.IsEmpty()) { - LOG(ERROR, DEBUGGER) << "RemoteObject::Create params is nullptr"; - return nullptr; - } - std::string error; auto paramsObject = std::make_unique(); + std::string error; + Result ret; - Local result = - Local(params)->Get(ecmaVm, Local(StringRef::NewFromUtf8(ecmaVm, "lineNumber"))); - if (!result.IsEmpty() && !result->IsUndefined()) { - if (result->IsNumber()) { - paramsObject->line_ = static_cast(Local(result)->Value()); - } else { - error += "'lineNumber' should be a Number;"; - } + int32_t lineNumber; + ret = params.GetInt("lineNumber", &lineNumber); + if (ret == Result::SUCCESS) { + paramsObject->lineNumber_ = lineNumber; } else { - error += "should contain 'lineNumber';"; + error += "Unknown 'lineNumber';"; } - result = Local(params)->Get(ecmaVm, Local(StringRef::NewFromUtf8(ecmaVm, "url"))); - if (!result.IsEmpty() && !result->IsUndefined()) { - if (result->IsString()) { - paramsObject->url_ = DebuggerApi::ToStdString(result); - } else { - error += "'url' should be a String;"; - } + std::string url; + ret = params.GetString("url", &url); + if (ret == Result::SUCCESS) { + paramsObject->url_ = std::move(url); + } else if (ret == Result::TYPE_ERROR) { // optional value + error += "Unknown 'url';"; } - result = Local(params)->Get(ecmaVm, Local(StringRef::NewFromUtf8(ecmaVm, "urlRegex"))); - if (!result.IsEmpty() && !result->IsUndefined()) { - if (result->IsString()) { - paramsObject->urlRegex_ = DebuggerApi::ToStdString(result); - } else { - error += "'urlRegex' should be a String;"; - } + std::string urlRegex; + ret = params.GetString("urlRegex", &urlRegex); + if (ret == Result::SUCCESS) { + paramsObject->urlRegex_ = std::move(urlRegex); + } else if (ret == Result::TYPE_ERROR) { // optional value + error += "Unknown 'urlRegex';"; } - result = Local(params)->Get(ecmaVm, Local(StringRef::NewFromUtf8(ecmaVm, "scriptHash"))); - if (!result.IsEmpty() && !result->IsUndefined()) { - if (result->IsString()) { - paramsObject->scriptHash_ = DebuggerApi::ToStdString(result); - } else { - error += "'scriptHash' should be a String;"; - } + std::string scriptHash; + ret = params.GetString("scriptHash", &scriptHash); + if (ret == Result::SUCCESS) { + paramsObject->scriptHash_ = std::move(scriptHash); + } else if (ret == Result::TYPE_ERROR) { // optional value + error += "Unknown 'scriptHash';"; } - result = Local(params)->Get(ecmaVm, Local(StringRef::NewFromUtf8(ecmaVm, "columnNumber"))); - if (!result.IsEmpty() && !result->IsUndefined()) { - if (result->IsNumber()) { - paramsObject->column_ = static_cast(Local(result)->Value()); - } else { - error += "'columnNumber' should be a Number;"; - } + int32_t columnNumber; + ret = params.GetInt("columnNumber", &columnNumber); + if (ret == Result::SUCCESS) { + paramsObject->columnNumber_ = columnNumber; + } else if (ret == Result::TYPE_ERROR) { // optional value + error += "Unknown 'columnNumber';"; } - result = Local(params)->Get(ecmaVm, Local(StringRef::NewFromUtf8(ecmaVm, "condition"))); - if (!result.IsEmpty() && !result->IsUndefined()) { - if (result->IsString()) { - paramsObject->condition_ = DebuggerApi::ToStdString(result); - } else { - error += "'condition' should be a String;"; - } + std::string condition; + ret = params.GetString("condition", &condition); + if (ret == Result::SUCCESS) { + paramsObject->condition_ = std::move(condition); + } else if (ret == Result::TYPE_ERROR) { // optional value + error += "Unknown 'condition';"; } if (!error.empty()) { LOG(ERROR, DEBUGGER) << "SetBreakpointByUrlParams::Create " << error; @@ -425,30 +328,20 @@ std::unique_ptr SetBreakpointByUrlParams::Create(const return paramsObject; } -std::unique_ptr SetPauseOnExceptionsParams::Create(const EcmaVM *ecmaVm, - const Local ¶ms) +std::unique_ptr SetPauseOnExceptionsParams::Create(const PtJson ¶ms) { - ASSERT(ecmaVm); - if (params.IsEmpty()) { - LOG(ERROR, DEBUGGER) << "RemoteObject::Create params is nullptr"; - return nullptr; - } - std::string error; auto paramsObject = std::make_unique(); + std::string error; + Result ret; - Local result = - Local(params)->Get(ecmaVm, Local(StringRef::NewFromUtf8(ecmaVm, "state"))); - if (!result.IsEmpty() && !result->IsUndefined()) { - if (result->IsString()) { - if (!paramsObject->StoreState(DebuggerApi::ToStdString(result))) { - error += "'state' is invalid;"; - } - } else { - error += "'state' should be a String;"; - } + std::string state; + ret = params.GetString("state", &state); + if (ret == Result::SUCCESS) { + paramsObject->StoreState(state); } else { - error += "should contain 'state';"; + error += "Unknown 'state';"; } + if (!error.empty()) { LOG(ERROR, DEBUGGER) << "SetPauseOnExceptionsParams::Create " << error; return nullptr; @@ -457,49 +350,35 @@ std::unique_ptr SetPauseOnExceptionsParams::Create(c return paramsObject; } -std::unique_ptr StepIntoParams::Create(const EcmaVM *ecmaVm, const Local ¶ms) +std::unique_ptr StepIntoParams::Create(const PtJson ¶ms) { - ASSERT(ecmaVm); - if (params.IsEmpty()) { - LOG(ERROR, DEBUGGER) << "RemoteObject::Create params is nullptr"; - return nullptr; - } - std::string error; auto paramsObject = std::make_unique(); + std::string error; + Result ret; - Local result = - Local(params)->Get(ecmaVm, Local(StringRef::NewFromUtf8(ecmaVm, "breakOnAsyncCall"))); - if (!result.IsEmpty() && !result->IsUndefined()) { - if (result->IsBoolean()) { - paramsObject->breakOnAsyncCall_ = result->IsTrue(); - } else { - error += "'terminateOnResume' should be a Boolean;"; - } + bool breakOnAsyncCall; + ret = params.GetBool("breakOnAsyncCall", &breakOnAsyncCall); + if (ret == Result::SUCCESS) { + paramsObject->breakOnAsyncCall_ = breakOnAsyncCall; + } else if (ret == Result::TYPE_ERROR) { // optional value + error += "Unknown 'breakOnAsyncCall';"; } - result = Local(params)->Get(ecmaVm, Local(StringRef::NewFromUtf8(ecmaVm, "skipList"))); - if (!result.IsEmpty() && !result->IsUndefined()) { - if (result->IsArray(ecmaVm)) { - Local array = Local(result); - int32_t len = array->Length(ecmaVm); - Local key = JSValueRef::Undefined(ecmaVm); - for (int32_t i = 0; i < len; i++) { - key = IntegerRef::New(ecmaVm, i); - Local value = Local(array)->Get(ecmaVm, key->ToString(ecmaVm)); - if (value->IsObject()) { - std::unique_ptr obj = LocationRange::Create(ecmaVm, value); - if (obj != nullptr) { - paramsObject->skipList_->emplace_back(std::move(obj)); - } else { - error += "'skipList' items LocationRange is invalid;"; - } - } else { - error += "'skipList' items should be an Object;"; - } + std::unique_ptr skipList; + ret = params.GetArray("skipList", &skipList); + if (ret == Result::SUCCESS) { + int32_t len = skipList->GetSize(); + for (int32_t i = 0; i < len; ++i) { + std::unique_ptr obj = LocationRange::Create(*skipList->Get(i)); + if (obj == nullptr) { + error += "'skipList' items LocationRange is invalid;"; + } else { + paramsObject->skipList_->emplace_back(std::move(obj)); } - } else { - error += "'skipList' should be an Array;"; } + } else if (ret == Result::TYPE_ERROR) { // optional value + error += "Unknown 'skipList';"; } + if (!error.empty()) { LOG(ERROR, DEBUGGER) << "StepIntoParams::Create " << error; return nullptr; @@ -508,41 +387,28 @@ std::unique_ptr StepIntoParams::Create(const EcmaVM *ecmaVm, con return paramsObject; } -std::unique_ptr StepOverParams::Create(const EcmaVM *ecmaVm, const Local ¶ms) +std::unique_ptr StepOverParams::Create(const PtJson ¶ms) { - ASSERT(ecmaVm); - if (params.IsEmpty()) { - LOG(ERROR, DEBUGGER) << "RemoteObject::Create params is nullptr"; - return nullptr; - } - std::string error; auto paramsObject = std::make_unique(); + std::string error; + Result ret; - Local result = - Local(params)->Get(ecmaVm, Local(StringRef::NewFromUtf8(ecmaVm, "skipList"))); - if (!result.IsEmpty() && !result->IsUndefined()) { - if (result->IsArray(ecmaVm)) { - Local array = Local(result); - int32_t len = array->Length(ecmaVm); - Local key = JSValueRef::Undefined(ecmaVm); - for (int32_t i = 0; i < len; i++) { - key = IntegerRef::New(ecmaVm, i); - Local value = Local(array)->Get(ecmaVm, key->ToString(ecmaVm)); - if (value->IsObject()) { - std::unique_ptr obj = LocationRange::Create(ecmaVm, value); - if (obj != nullptr) { - paramsObject->skipList_->emplace_back(std::move(obj)); - } else { - error += "'skipList' items LocationRange is invalid;"; - } - } else { - error += "'skipList' items should be an Object;"; - } + std::unique_ptr skipList; + ret = params.GetArray("skipList", &skipList); + if (ret == Result::SUCCESS) { + int32_t len = skipList->GetSize(); + for (int32_t i = 0; i < len; ++i) { + std::unique_ptr obj = LocationRange::Create(*skipList->Get(i)); + if (obj == nullptr) { + error += "'skipList' items LocationRange is invalid;"; + } else { + paramsObject->skipList_->emplace_back(std::move(obj)); } - } else { - error += "'skipList' should be an Array;"; } + } else if (ret == Result::TYPE_ERROR) { // optional value + error += "Unknown 'skipList';"; } + if (!error.empty()) { LOG(ERROR, DEBUGGER) << "StepOverParams::Create " << error; return nullptr; @@ -551,52 +417,39 @@ std::unique_ptr StepOverParams::Create(const EcmaVM *ecmaVm, con return paramsObject; } -std::unique_ptr GetPropertiesParams::Create(const EcmaVM *ecmaVm, const Local ¶ms) +std::unique_ptr GetPropertiesParams::Create(const PtJson ¶ms) { - ASSERT(ecmaVm); - if (params.IsEmpty()) { - LOG(ERROR, DEBUGGER) << "GetPropertiesParams::Create params is nullptr"; - return nullptr; - } - std::string error; auto paramsObject = std::make_unique(); + std::string error; + Result ret; - Local result = - Local(params)->Get(ecmaVm, Local(StringRef::NewFromUtf8(ecmaVm, "objectId"))); - if (!result.IsEmpty() && !result->IsUndefined()) { - if (result->IsString()) { - paramsObject->objectId_ = static_cast(DebuggerApi::StringToInt(result)); - } else { - error += "'objectId' should be a String;"; - } + std::string objectId; + ret = params.GetString("objectId", &objectId); + if (ret == Result::SUCCESS) { + paramsObject->objectId_ = std::stoi(objectId); } else { - error += "should contain 'objectId';"; + error += "Unknown 'objectId';"; } - result = Local(params)->Get(ecmaVm, Local(StringRef::NewFromUtf8(ecmaVm, "ownProperties"))); - if (!result.IsEmpty() && !result->IsUndefined()) { - if (result->IsBoolean()) { - paramsObject->ownProperties_ = result->IsTrue(); - } else { - error += "'ownProperties' should be a Boolean;"; - } + bool ownProperties; + ret = params.GetBool("ownProperties", &ownProperties); + if (ret == Result::SUCCESS) { + paramsObject->ownProperties_ = ownProperties; + } else if (ret == Result::TYPE_ERROR) { // optional value + error += "Unknown 'ownProperties';"; } - result = Local(params)->Get(ecmaVm, - Local(StringRef::NewFromUtf8(ecmaVm, "accessorPropertiesOnly"))); - if (!result.IsEmpty() && !result->IsUndefined()) { - if (result->IsBoolean()) { - paramsObject->accessorPropertiesOnly_ = result->IsTrue(); - } else { - error += "'accessorPropertiesOnly' should be a Boolean;"; - } + bool accessorPropertiesOnly; + ret = params.GetBool("accessorPropertiesOnly", &accessorPropertiesOnly); + if (ret == Result::SUCCESS) { + paramsObject->accessorPropertiesOnly_ = accessorPropertiesOnly; + } else if (ret == Result::TYPE_ERROR) { // optional value + error += "Unknown 'accessorPropertiesOnly';"; } - result = - Local(params)->Get(ecmaVm, Local(StringRef::NewFromUtf8(ecmaVm, "generatePreview"))); - if (!result.IsEmpty() && !result->IsUndefined()) { - if (result->IsBoolean()) { - paramsObject->generatePreview_ = result->IsTrue(); - } else { - error += "'generatePreview' should be a Boolean;"; - } + bool generatePreview; + ret = params.GetBool("generatePreview", &generatePreview); + if (ret == Result::SUCCESS) { + paramsObject->generatePreview_ = generatePreview; + } else if (ret == Result::TYPE_ERROR) { // optional value + error += "Unknown 'generatePreview';"; } if (!error.empty()) { LOG(ERROR, DEBUGGER) << "GetPropertiesParams::Create " << error; @@ -606,138 +459,109 @@ std::unique_ptr GetPropertiesParams::Create(const EcmaVM *e return paramsObject; } -std::unique_ptr CallFunctionOnParams::Create(const EcmaVM *ecmaVm, - const Local ¶ms) +std::unique_ptr CallFunctionOnParams::Create(const PtJson ¶ms) { - ASSERT(ecmaVm); - if (params.IsEmpty()) { - LOG(ERROR, DEBUGGER) << "CallFunctionOnParams::Create params is nullptr"; - return nullptr; - } - std::string error; auto paramsObject = std::make_unique(); + std::string error; + Result ret; // paramsObject->functionDeclaration_ - Local result = Local(params)->Get(ecmaVm, - Local(StringRef::NewFromUtf8(ecmaVm, "functionDeclaration"))); - if (!result.IsEmpty() && !result->IsUndefined()) { - if (result->IsString()) { - paramsObject->functionDeclaration_ = DebuggerApi::ToStdString(result); - } else { - error += "'functionDeclaration' should be a String;"; - } + std::string functionDeclaration; + ret = params.GetString("functionDeclaration", &functionDeclaration); + if (ret == Result::SUCCESS) { + paramsObject->functionDeclaration_ = std::move(functionDeclaration); } else { - error += "should contain 'functionDeclaration';"; + error += "Unknown 'functionDeclaration';"; } // paramsObject->objectId_ - result = Local(params)->Get(ecmaVm, Local(StringRef::NewFromUtf8(ecmaVm, "objectId"))); - if (!result.IsEmpty() && !result->IsUndefined()) { - if (result->IsString()) { - paramsObject->objectId_ = static_cast(DebuggerApi::StringToInt(result)); - } else { - error += "'objectId' should be a String;"; - } + std::string objectId; + ret = params.GetString("objectId", &objectId); + if (ret == Result::SUCCESS) { + paramsObject->objectId_ = std::stoi(objectId); + } else if (ret == Result::TYPE_ERROR) { // optional value + error += "Unknown 'objectId';"; } // paramsObject->arguments_ - result = Local(params)->Get(ecmaVm, Local(StringRef::NewFromUtf8(ecmaVm, "arguments"))); - if (!result.IsEmpty() && !result->IsUndefined()) { - if (result->IsArray(ecmaVm)) { - Local array = Local(result); - int32_t len = array->Length(ecmaVm); - Local key = JSValueRef::Undefined(ecmaVm); - for (int32_t i = 0; i < len; i++) { - key = IntegerRef::New(ecmaVm, i); - Local value = Local(array)->Get(ecmaVm, key->ToString(ecmaVm)); - if (value->IsObject()) { - std::unique_ptr obj = CallArgument::Create(ecmaVm, value); - if (obj != nullptr) { - paramsObject->arguments_->emplace_back(std::move(obj)); - } else { - error += "'arguments' items CallArgument is invaild;"; - } - } else { - error += "'arguments' items should be an Object;"; - } + std::unique_ptr arguments; + ret = params.GetArray("arguments", &arguments); + if (ret == Result::SUCCESS) { + int32_t len = arguments->GetSize(); + for (int32_t i = 0; i < len; ++i) { + std::unique_ptr obj = CallArgument::Create(*arguments->Get(i)); + if (obj == nullptr) { + error += "'arguments' items CallArgument is invaild;"; + } else { + paramsObject->arguments_->emplace_back(std::move(obj)); } - } else { - error += "'arguments' should be an Array;"; } + } else if (ret == Result::TYPE_ERROR) { // optional value + error += "Unknown 'arguments';"; } // paramsObject->silent_ - result = Local(params)->Get(ecmaVm, Local(StringRef::NewFromUtf8(ecmaVm, "silent"))); - if (!result.IsEmpty() && !result->IsUndefined()) { - if (result->IsBoolean()) { - paramsObject->silent_ = result->IsTrue(); - } else { - error += "'silent' should be a Boolean;"; - } + bool silent; + ret = params.GetBool("silent", &silent); + if (ret == Result::SUCCESS) { + paramsObject->silent_ = silent; + } else if (ret == Result::TYPE_ERROR) { // optional value + error += "Unknown 'silent';"; } // paramsObject->returnByValue_ - result = Local(params)->Get(ecmaVm, Local(StringRef::NewFromUtf8(ecmaVm, "returnByValue"))); - if (!result.IsEmpty() && !result->IsUndefined()) { - if (result->IsBoolean()) { - paramsObject->returnByValue_ = result->IsTrue(); - } else { - error += "'returnByValue' should be a Boolean;"; - } + bool returnByValue; + ret = params.GetBool("returnByValue", &returnByValue); + if (ret == Result::SUCCESS) { + paramsObject->returnByValue_ = returnByValue; + } else if (ret == Result::TYPE_ERROR) { // optional value + error += "Unknown 'returnByValue';"; } // paramsObject->generatePreview_ - result = Local(params)->Get(ecmaVm, - Local(StringRef::NewFromUtf8(ecmaVm, "generatePreview"))); - if (!result.IsEmpty() && !result->IsUndefined()) { - if (result->IsBoolean()) { - paramsObject->generatePreview_ = result->IsTrue(); - } else { - error += "'generatePreview' should be a Boolean;"; - } + bool generatePreview; + ret = params.GetBool("generatePreview", &generatePreview); + if (ret == Result::SUCCESS) { + paramsObject->generatePreview_ = generatePreview; + } else if (ret == Result::TYPE_ERROR) { // optional value + error += "Unknown 'generatePreview';"; } // paramsObject->userGesture_ - result = Local(params)->Get(ecmaVm, Local(StringRef::NewFromUtf8(ecmaVm, "userGesture"))); - if (!result.IsEmpty() && !result->IsUndefined()) { - if (result->IsBoolean()) { - paramsObject->userGesture_ = result->IsTrue(); - } else { - error += "'userGesture' should be a Boolean;"; - } + bool userGesture; + ret = params.GetBool("userGesture", &userGesture); + if (ret == Result::SUCCESS) { + paramsObject->userGesture_ = userGesture; + } else if (ret == Result::TYPE_ERROR) { // optional value + error += "Unknown 'userGesture';"; } // paramsObject->awaitPromise_ - result = Local(params)->Get(ecmaVm, Local(StringRef::NewFromUtf8(ecmaVm, "awaitPromise"))); - if (!result.IsEmpty() && !result->IsUndefined()) { - if (result->IsBoolean()) { - paramsObject->awaitPromise_ = result->IsTrue(); - } else { - error += "'awaitPromise' should be a Boolean;"; - } + bool awaitPromise; + ret = params.GetBool("awaitPromise", &awaitPromise); + if (ret == Result::SUCCESS) { + paramsObject->awaitPromise_ = awaitPromise; + } else if (ret == Result::TYPE_ERROR) { // optional value + error += "Unknown 'awaitPromise';"; } // paramsObject->executionContextId_ - result = Local(params)->Get(ecmaVm, - Local(StringRef::NewFromUtf8(ecmaVm, "executionContextId"))); - if (!result.IsEmpty() && !result->IsUndefined()) { - if (result->IsNumber()) { - paramsObject->executionContextId_ = static_cast(Local(result)->Value()); - } else { - error += "'executionContextId' should be a Number;"; - } + int32_t executionContextId; + ret = params.GetInt("executionContextId", &executionContextId); + if (ret == Result::SUCCESS) { + paramsObject->executionContextId_ = executionContextId; + } else if (ret == Result::TYPE_ERROR) { // optional value + error += "Unknown 'executionContextId';"; } // paramsObject->objectGroup_ - result = Local(params)->Get(ecmaVm, Local(StringRef::NewFromUtf8(ecmaVm, "objectGroup"))); - if (!result.IsEmpty() && !result->IsUndefined()) { - if (result->IsString()) { - paramsObject->objectGroup_ = DebuggerApi::ToStdString(result); - } else { - error += "'objectGroup' should be a String;"; - } + std::string objectGroup; + ret = params.GetString("objectGroup", &objectGroup); + if (ret == Result::SUCCESS) { + paramsObject->objectGroup_ = std::move(objectGroup); + } else if (ret == Result::TYPE_ERROR) { // optional value + error += "Unknown 'objectGroup';"; } // paramsObject->throwOnSideEffect_ - result = Local(params)->Get(ecmaVm, - Local(StringRef::NewFromUtf8(ecmaVm, "throwOnSideEffect"))); - if (!result.IsEmpty() && !result->IsUndefined()) { - if (result->IsBoolean()) { - paramsObject->throwOnSideEffect_ = result->IsTrue(); - } else { - error += "'throwOnSideEffect' should be a Boolean;"; - } + bool throwOnSideEffect; + ret = params.GetBool("throwOnSideEffect", &throwOnSideEffect); + if (ret == Result::SUCCESS) { + paramsObject->throwOnSideEffect_ = throwOnSideEffect; + } else if (ret == Result::TYPE_ERROR) { // optional value + error += "Unknown 'throwOnSideEffect';"; } + // Check whether the error is empty. if (!error.empty()) { LOG(ERROR, DEBUGGER) << "CallFunctionOnParams::Create " << error; @@ -747,25 +571,18 @@ std::unique_ptr CallFunctionOnParams::Create(const EcmaVM return paramsObject; } -std::unique_ptr StartSamplingParams::Create(const EcmaVM *ecmaVm, - const Local ¶ms) +std::unique_ptr StartSamplingParams::Create(const PtJson ¶ms) { - ASSERT(ecmaVm); - if (params.IsEmpty()) { - LOG(ERROR, DEBUGGER) << "StartSamplingParams::Create params is nullptr"; - return nullptr; - } - std::string error; auto paramsObject = std::make_unique(); + std::string error; + Result ret; - Local result = Local(params)->Get(ecmaVm, - Local(StringRef::NewFromUtf8(ecmaVm, "samplingInterval"))); - if (!result.IsEmpty() && !result->IsUndefined()) { - if (result->IsNumber()) { - paramsObject->samplingInterval_ = static_cast(Local(result)->Value()); - } else { - error += "'samplingInterval' should be a Number;"; - } + int32_t samplingInterval; + ret = params.GetInt("samplingInterval", &samplingInterval); + if (ret == Result::SUCCESS) { + paramsObject->samplingInterval_ = samplingInterval; + } else if (ret == Result::TYPE_ERROR) { // optional value + error += "Unknown 'samplingInterval';"; } if (!error.empty()) { @@ -775,26 +592,20 @@ std::unique_ptr StartSamplingParams::Create(const EcmaVM *e return paramsObject; } -std::unique_ptr StartTrackingHeapObjectsParams::Create(const EcmaVM *ecmaVm, - const Local ¶ms) +std::unique_ptr StartTrackingHeapObjectsParams::Create(const PtJson ¶ms) { - ASSERT(ecmaVm); - if (params.IsEmpty()) { - LOG(ERROR, DEBUGGER) << "StartTrackingHeapObjectsParams::Create params is nullptr"; - return nullptr; - } - std::string error; auto paramsObject = std::make_unique(); + std::string error; + Result ret; - Local result = Local(params)->Get(ecmaVm, - Local(StringRef::NewFromUtf8(ecmaVm, "trackAllocations"))); - if (!result.IsEmpty() && !result->IsUndefined()) { - if (result->IsBoolean()) { - paramsObject->trackAllocations_ = result->IsTrue(); - } else { - error += "'trackAllocations' should be a boolean;"; - } + bool trackAllocations; + ret = params.GetBool("trackAllocations", &trackAllocations); + if (ret == Result::SUCCESS) { + paramsObject->trackAllocations_ = trackAllocations; + } else if (ret == Result::TYPE_ERROR) { // optional value + error += "Unknown 'trackAllocations';"; } + if (!error.empty()) { LOG(ERROR, DEBUGGER) << "StartTrackingHeapObjectsParams::Create " << error; return nullptr; @@ -802,45 +613,34 @@ std::unique_ptr StartTrackingHeapObjectsParams:: return paramsObject; } -std::unique_ptr StopTrackingHeapObjectsParams::Create(const EcmaVM *ecmaVm, - const Local ¶ms) +std::unique_ptr StopTrackingHeapObjectsParams::Create(const PtJson ¶ms) { - ASSERT(ecmaVm); - if (params.IsEmpty()) { - LOG(ERROR, DEBUGGER) << "StopTrackingHeapObjectsParams::Create params is nullptr"; - return nullptr; - } - std::string error; auto paramsObject = std::make_unique(); + std::string error; + Result ret; - Local result = Local(params)->Get(ecmaVm, - Local(StringRef::NewFromUtf8(ecmaVm, "reportProgress"))); - if (!result.IsEmpty() && !result->IsUndefined()) { - if (result->IsBoolean()) { - paramsObject->reportProgress_ = result->IsTrue(); - } else { - error += "'reportProgress' should be a boolean;"; - } + bool reportProgress; + ret = params.GetBool("reportProgress", &reportProgress); + if (ret == Result::SUCCESS) { + paramsObject->reportProgress_ = reportProgress; + } else if (ret == Result::TYPE_ERROR) { // optional value + error += "Unknown 'reportProgress';"; } - result = Local(params)->Get(ecmaVm, - Local(StringRef::NewFromUtf8(ecmaVm, "treatGlobalObjectsAsRoots"))); - if (!result.IsEmpty() && !result->IsUndefined()) { - if (result->IsBoolean()) { - paramsObject->treatGlobalObjectsAsRoots_ = result->IsTrue(); - } else { - error += "'treatGlobalObjectsAsRoots' should be a boolean;"; - } + bool treatGlobalObjectsAsRoots; + ret = params.GetBool("treatGlobalObjectsAsRoots", &treatGlobalObjectsAsRoots); + if (ret == Result::SUCCESS) { + paramsObject->treatGlobalObjectsAsRoots_ = treatGlobalObjectsAsRoots; + } else if (ret == Result::TYPE_ERROR) { // optional value + error += "Unknown 'treatGlobalObjectsAsRoots';"; } - result = Local(params)->Get(ecmaVm, - Local(StringRef::NewFromUtf8(ecmaVm, "captureNumericValue"))); - if (!result.IsEmpty() && !result->IsUndefined()) { - if (result->IsBoolean()) { - paramsObject->captureNumericValue_ = result->IsTrue(); - } else { - error += "'captureNumericValue' should be a boolean;"; - } + bool captureNumericValue; + ret = params.GetBool("captureNumericValue", &captureNumericValue); + if (ret == Result::SUCCESS) { + paramsObject->captureNumericValue_ = captureNumericValue; + } else if (ret == Result::TYPE_ERROR) { // optional value + error += "Unknown 'captureNumericValue';"; } if (!error.empty()) { @@ -850,27 +650,18 @@ std::unique_ptr StopTrackingHeapObjectsParams::Cr return paramsObject; } -std::unique_ptr AddInspectedHeapObjectParams::Create(const EcmaVM *ecmaVm, - const Local ¶ms) +std::unique_ptr AddInspectedHeapObjectParams::Create(const PtJson ¶ms) { - ASSERT(ecmaVm); - if (params.IsEmpty()) { - LOG(ERROR, DEBUGGER) << "AddInspectedHeapObjectParams::Create params is nullptr"; - return nullptr; - } - std::string error; auto paramsObject = std::make_unique(); + std::string error; + Result ret; - Local result = Local(params)->Get(ecmaVm, - Local(StringRef::NewFromUtf8(ecmaVm, "heapObjectId"))); - if (!result.IsEmpty() && !result->IsUndefined()) { - if (result->IsString()) { - paramsObject->heapObjectId_ = static_cast(DebuggerApi::StringToInt(result)); - } else { - error += "'heapObjectId' should be a String;"; - } + std::string heapObjectId; + ret = params.GetString("heapObjectId", &heapObjectId); + if (ret == Result::SUCCESS) { + paramsObject->heapObjectId_ = std::stoi(heapObjectId); } else { - error += "should contain 'heapObjectId';"; + error += "Unknown 'heapObjectId';"; } if (!error.empty()) { @@ -880,27 +671,18 @@ std::unique_ptr AddInspectedHeapObjectParams::Crea return paramsObject; } -std::unique_ptr GetHeapObjectIdParams::Create(const EcmaVM *ecmaVm, - const Local ¶ms) +std::unique_ptr GetHeapObjectIdParams::Create(const PtJson ¶ms) { - ASSERT(ecmaVm); - if (params.IsEmpty()) { - LOG(ERROR, DEBUGGER) << "GetHeapObjectIdParams::Create params is nullptr"; - return nullptr; - } - std::string error; auto paramsObject = std::make_unique(); + std::string error; + Result ret; - Local result = Local(params)->Get(ecmaVm, - Local(StringRef::NewFromUtf8(ecmaVm, "objectId"))); - if (!result.IsEmpty() && !result->IsUndefined()) { - if (result->IsString()) { - paramsObject->objectId_ = static_cast(DebuggerApi::StringToInt(result)); - } else { - error += "'objectId' should be a String;"; - } - } else { - error += "should contain 'objectId';"; + std::string objectId; + ret = params.GetString("objectId", &objectId); + if (ret == Result::SUCCESS) { + paramsObject->objectId_ = std::stoi(objectId); + } else if (ret == Result::TYPE_ERROR) { // optional value + error += "Unknown 'objectId';"; } if (!error.empty()) { @@ -910,37 +692,26 @@ std::unique_ptr GetHeapObjectIdParams::Create(const EcmaV return paramsObject; } -std::unique_ptr GetObjectByHeapObjectIdParams::Create(const EcmaVM *ecmaVm, - const Local ¶ms) +std::unique_ptr GetObjectByHeapObjectIdParams::Create(const PtJson ¶ms) { - ASSERT(ecmaVm); - if (params.IsEmpty()) { - LOG(ERROR, DEBUGGER) << "GetObjectByHeapObjectIdParams::Create params is nullptr"; - return nullptr; - } - std::string error; auto paramsObject = std::make_unique(); + std::string error; + Result ret; - Local result = Local(params)->Get(ecmaVm, - Local(StringRef::NewFromUtf8(ecmaVm, "objectId"))); - if (!result.IsEmpty() && !result->IsUndefined()) { - if (result->IsString()) { - paramsObject->objectId_ = static_cast(DebuggerApi::StringToInt(result)); - } else { - error += "'objectId' should be a String;"; - } - } else { - error += "should contain 'objectId';"; + std::string objectId; + ret = params.GetString("objectId", &objectId); + if (ret == Result::SUCCESS) { + paramsObject->objectId_ = std::stoi(objectId); + } else if (ret == Result::TYPE_ERROR) { // optional value + error += "Unknown 'objectId';"; } - result = Local(params)->Get(ecmaVm, - Local(StringRef::NewFromUtf8(ecmaVm, "objectGroup"))); - if (!result.IsEmpty() && !result->IsUndefined()) { - if (result->IsString()) { - paramsObject->objectGroup_ = DebuggerApi::ToStdString(result); - } else { - error += "'objectGroup' should be a String;"; - } + std::string objectGroup; + ret = params.GetString("objectGroup", &objectGroup); + if (ret == Result::SUCCESS) { + paramsObject->objectGroup_ = std::move(objectGroup); + } else if (ret == Result::TYPE_ERROR) { // optional value + error += "Unknown 'objectGroup';"; } if (!error.empty()) { @@ -950,45 +721,34 @@ std::unique_ptr GetObjectByHeapObjectIdParams::Cr return paramsObject; } -std::unique_ptr StartPreciseCoverageParams::Create(const EcmaVM *ecmaVm, - const Local ¶ms) +std::unique_ptr StartPreciseCoverageParams::Create(const PtJson ¶ms) { - ASSERT(ecmaVm); - if (params.IsEmpty()) { - LOG(ERROR, DEBUGGER) << "StartPreciseCoverageParams::Create params is nullptr"; - return nullptr; - } - std::string error; auto paramsObject = std::make_unique(); + std::string error; + Result ret; - Local result = Local(params)->Get(ecmaVm, - Local(StringRef::NewFromUtf8(ecmaVm, "callCount"))); - if (!result.IsEmpty() && !result->IsUndefined()) { - if (result->IsBoolean()) { - paramsObject->callCount_ = result->IsTrue(); - } else { - error += "'callCount' should be a boolean;"; - } + bool callCount; + ret = params.GetBool("callCount", &callCount); + if (ret == Result::SUCCESS) { + paramsObject->callCount_ = callCount; + } else if (ret == Result::TYPE_ERROR) { // optional value + error += "Unknown 'callCount';"; } - result = Local(params)->Get(ecmaVm, - Local(StringRef::NewFromUtf8(ecmaVm, "detailed"))); - if (!result.IsEmpty() && !result->IsUndefined()) { - if (result->IsBoolean()) { - paramsObject->detailed_ = result->IsTrue(); - } else { - error += "'detailed' should be a boolean;"; - } + bool detailed; + ret = params.GetBool("detailed", &detailed); + if (ret == Result::SUCCESS) { + paramsObject->detailed_ = detailed; + } else if (ret == Result::TYPE_ERROR) { // optional value + error += "Unknown 'detailed';"; } - result = Local(params)->Get(ecmaVm, - Local(StringRef::NewFromUtf8(ecmaVm, "allowTriggeredUpdates"))); - if (!result.IsEmpty() && !result->IsUndefined()) { - if (result->IsBoolean()) { - paramsObject->allowTriggeredUpdates_ = result->IsTrue(); - } else { - error += "'allowTriggeredUpdates' should be a boolean;"; - } + bool allowTriggeredUpdates; + ret = params.GetBool("allowTriggeredUpdates", &allowTriggeredUpdates); + if (ret == Result::SUCCESS) { + paramsObject->allowTriggeredUpdates_ = allowTriggeredUpdates; + } else if (ret == Result::TYPE_ERROR) { // optional value + error += "Unknown 'allowTriggeredUpdates';"; } if (!error.empty()) { @@ -998,27 +758,18 @@ std::unique_ptr StartPreciseCoverageParams::Create(c return paramsObject; } -std::unique_ptr SetSamplingIntervalParams::Create(const EcmaVM *ecmaVm, - const Local ¶ms) +std::unique_ptr SetSamplingIntervalParams::Create(const PtJson ¶ms) { - ASSERT(ecmaVm); - if (params.IsEmpty()) { - LOG(ERROR, DEBUGGER) << "SetSamplingIntervalParams::Create params is nullptr"; - return nullptr; - } - std::string error; auto paramsObject = std::make_unique(); + std::string error; + Result ret; - Local result = - Local(params)->Get(ecmaVm, Local(StringRef::NewFromUtf8(ecmaVm, "interval"))); - if (!result.IsEmpty() && !result->IsUndefined()) { - if (result->IsNumber()) { - paramsObject->interval_ = static_cast(Local(result)->Value()); - } else { - error += "'interval' should be a Number;"; - } + int32_t interval; + ret = params.GetInt("interval", &interval); + if (ret == Result::SUCCESS) { + paramsObject->interval_ = interval; } else { - error += "should contain 'interval';"; + error += "Unknown 'interval';"; } if (!error.empty()) { diff --git a/ecmascript/tooling/base/pt_params.h b/ecmascript/tooling/base/pt_params.h index a160040ad..7fe6278cc 100644 --- a/ecmascript/tooling/base/pt_params.h +++ b/ecmascript/tooling/base/pt_params.h @@ -39,7 +39,6 @@ public: EnableParams() = default; ~EnableParams() override = default; - static std::unique_ptr Create(const EcmaVM *ecmaVm, const Local ¶ms); static std::unique_ptr Create(const PtJson ¶ms); double GetMaxScriptsCacheSize() const @@ -64,7 +63,7 @@ public: EvaluateOnCallFrameParams() = default; ~EvaluateOnCallFrameParams() override = default; - static std::unique_ptr Create(const EcmaVM *ecmaVm, const Local ¶ms); + static std::unique_ptr Create(const PtJson ¶ms); CallFrameId GetCallFrameId() const { @@ -83,7 +82,7 @@ private: CallFrameId callFrameId_ {}; std::string expression_ {}; std::optional objectGroup_ {}; - std::optional includeCommandLineApi_ {}; + std::optional includeCommandLineAPI_ {}; std::optional silent_ {}; std::optional returnByValue_ {}; std::optional generatePreview_ {}; @@ -95,7 +94,7 @@ public: GetPossibleBreakpointsParams() = default; ~GetPossibleBreakpointsParams() override = default; - static std::unique_ptr Create(const EcmaVM *ecmaVm, const Local ¶ms); + static std::unique_ptr Create(const PtJson ¶ms); Location *GetStart() const { @@ -139,7 +138,7 @@ public: GetScriptSourceParams() = default; ~GetScriptSourceParams() override = default; - static std::unique_ptr Create(const EcmaVM *ecmaVm, const Local ¶ms); + static std::unique_ptr Create(const PtJson ¶ms); ScriptId GetScriptId() const { @@ -158,7 +157,7 @@ public: RemoveBreakpointParams() = default; ~RemoveBreakpointParams() override = default; - static std::unique_ptr Create(const EcmaVM *ecmaVm, const Local ¶ms); + static std::unique_ptr Create(const PtJson ¶ms); BreakpointId GetBreakpointId() const { @@ -177,7 +176,7 @@ public: ResumeParams() = default; ~ResumeParams() override = default; - static std::unique_ptr Create(const EcmaVM *ecmaVm, const Local ¶ms); + static std::unique_ptr Create(const PtJson ¶ms); bool GetTerminateOnResume() const { @@ -201,9 +200,9 @@ public: SetAsyncCallStackDepthParams() = default; ~SetAsyncCallStackDepthParams() override = default; - static std::unique_ptr Create(const EcmaVM *ecmaVm, const Local ¶ms); + static std::unique_ptr Create(const PtJson ¶ms); - uint32_t GetMaxDepth() const + int32_t GetMaxDepth() const { return maxDepth_; } @@ -212,14 +211,14 @@ private: NO_COPY_SEMANTIC(SetAsyncCallStackDepthParams); NO_MOVE_SEMANTIC(SetAsyncCallStackDepthParams); - uint32_t maxDepth_ {0}; + int32_t maxDepth_ {0}; }; class SetBlackboxPatternsParams : public PtBaseParams { public: SetBlackboxPatternsParams() = default; ~SetBlackboxPatternsParams() override = default; - static std::unique_ptr Create(const EcmaVM *ecmaVm, const Local ¶ms); + static std::unique_ptr Create(const PtJson ¶ms); std::list GetPatterns() const { @@ -238,11 +237,11 @@ public: SetBreakpointByUrlParams() = default; ~SetBreakpointByUrlParams() override = default; - static std::unique_ptr Create(const EcmaVM *ecmaVm, const Local ¶ms); + static std::unique_ptr Create(const PtJson ¶ms); int32_t GetLine() const { - return line_; + return lineNumber_; } const std::string &GetUrl() const @@ -280,12 +279,12 @@ public: int32_t GetColumn() const { - return column_.value_or(0); + return columnNumber_.value_or(0); } bool HasColumn() const { - return column_.has_value(); + return columnNumber_.has_value(); } const std::string &GetCondition() const @@ -303,11 +302,11 @@ private: NO_COPY_SEMANTIC(SetBreakpointByUrlParams); NO_MOVE_SEMANTIC(SetBreakpointByUrlParams); - int32_t line_ {0}; + int32_t lineNumber_ {0}; std::optional url_ {}; std::optional urlRegex_ {}; std::optional scriptHash_ {}; - std::optional column_ {0}; + std::optional columnNumber_ {0}; std::optional condition_ {}; }; @@ -317,7 +316,7 @@ class SetPauseOnExceptionsParams : public PtBaseParams { public: SetPauseOnExceptionsParams() = default; ~SetPauseOnExceptionsParams() override = default; - static std::unique_ptr Create(const EcmaVM *ecmaVm, const Local ¶ms); + static std::unique_ptr Create(const PtJson ¶ms); PauseOnExceptionsState GetState() const { @@ -353,7 +352,7 @@ public: StepIntoParams() = default; ~StepIntoParams() override = default; - static std::unique_ptr Create(const EcmaVM *ecmaVm, const Local ¶ms); + static std::unique_ptr Create(const PtJson ¶ms); bool GetBreakOnAsyncCall() const { @@ -391,7 +390,7 @@ public: StepOverParams() = default; ~StepOverParams() override = default; - static std::unique_ptr Create(const EcmaVM *ecmaVm, const Local ¶ms); + static std::unique_ptr Create(const PtJson ¶ms); const std::list> *GetSkipList() const { @@ -418,7 +417,7 @@ public: GetPropertiesParams() = default; ~GetPropertiesParams() override = default; - static std::unique_ptr Create(const EcmaVM *ecmaVm, const Local ¶ms); + static std::unique_ptr Create(const PtJson ¶ms); RemoteObjectId GetObjectId() const { @@ -470,7 +469,7 @@ public: CallFunctionOnParams() = default; ~CallFunctionOnParams() override = default; - static std::unique_ptr Create(const EcmaVM *ecmaVm, const Local ¶ms); + static std::unique_ptr Create(const PtJson ¶ms); const std::string &GetFunctionDeclaration() { @@ -615,7 +614,7 @@ public: StartSamplingParams() = default; ~StartSamplingParams() override = default; - static std::unique_ptr Create(const EcmaVM *ecmaVm, const Local ¶ms); + static std::unique_ptr Create(const PtJson ¶ms); int32_t GetSamplingInterval() const { @@ -626,7 +625,7 @@ private: NO_COPY_SEMANTIC(StartSamplingParams); NO_MOVE_SEMANTIC(StartSamplingParams); - std::optional samplingInterval_ {32768}; + std::optional samplingInterval_ {32768}; }; class StartTrackingHeapObjectsParams : public PtBaseParams { @@ -634,8 +633,7 @@ public: StartTrackingHeapObjectsParams() = default; ~StartTrackingHeapObjectsParams() override = default; - static std::unique_ptr Create(const EcmaVM *ecmaVm, - const Local ¶ms); + static std::unique_ptr Create(const PtJson ¶ms); bool GetTrackAllocations() const { @@ -659,7 +657,7 @@ public: StopTrackingHeapObjectsParams() = default; ~StopTrackingHeapObjectsParams() override = default; - static std::unique_ptr Create(const EcmaVM *ecmaVm, const Local ¶ms); + static std::unique_ptr Create(const PtJson ¶ms); bool GetReportProgress() const { @@ -705,7 +703,7 @@ public: AddInspectedHeapObjectParams() = default; ~AddInspectedHeapObjectParams() override = default; - static std::unique_ptr Create(const EcmaVM *ecmaVm, const Local ¶ms); + static std::unique_ptr Create(const PtJson ¶ms); HeapSnapshotObjectId GetHeapObjectId() const { @@ -724,7 +722,7 @@ public: GetHeapObjectIdParams() = default; ~GetHeapObjectIdParams() override = default; - static std::unique_ptr Create(const EcmaVM *ecmaVm, const Local ¶ms); + static std::unique_ptr Create(const PtJson ¶ms); RemoteObjectId GetObjectId() const { @@ -743,7 +741,7 @@ public: GetObjectByHeapObjectIdParams() = default; ~GetObjectByHeapObjectIdParams() override = default; - static std::unique_ptr Create(const EcmaVM *ecmaVm, const Local ¶ms); + static std::unique_ptr Create(const PtJson ¶ms); HeapSnapshotObjectId GetObjectId() const { @@ -774,8 +772,7 @@ public: StartPreciseCoverageParams() = default; ~StartPreciseCoverageParams() override = default; - static std::unique_ptr Create(const EcmaVM *ecmaVm, - const Local ¶ms); + static std::unique_ptr Create(const PtJson ¶ms); bool GetCallCount() const { @@ -821,14 +818,14 @@ public: SetSamplingIntervalParams() = default; ~SetSamplingIntervalParams() override = default; - static std::unique_ptr Create(const EcmaVM *ecmaVm, const Local ¶ms); + static std::unique_ptr Create(const PtJson ¶ms); - int GetInterval() const + int32_t GetInterval() const { return interval_; } - SetSamplingIntervalParams &SetInterval(int interval) + SetSamplingIntervalParams &SetInterval(int32_t interval) { interval_ = interval; return *this; @@ -838,7 +835,7 @@ private: NO_COPY_SEMANTIC(SetSamplingIntervalParams); NO_MOVE_SEMANTIC(SetSamplingIntervalParams); - int interval_ {0}; + int32_t interval_ {0}; }; } // namespace panda::ecmascript::tooling #endif \ No newline at end of file diff --git a/ecmascript/tooling/base/pt_types.cpp b/ecmascript/tooling/base/pt_types.cpp index 457b9de34..5cb250dea 100644 --- a/ecmascript/tooling/base/pt_types.cpp +++ b/ecmascript/tooling/base/pt_types.cpp @@ -557,7 +557,7 @@ std::unique_ptr ExceptionDetails::Create(const EcmaVM *ecmaVm, result = Local(params)->Get(ecmaVm, Local(StringRef::NewFromUtf8(ecmaVm, "lineNumber"))); if (!result.IsEmpty() && !result->IsUndefined()) { if (result->IsNumber()) { - exceptionDetails->line_ = static_cast(Local(result)->Value()); + exceptionDetails->lineNumber_ = static_cast(Local(result)->Value()); } else { error += "'lineNumber' should be a Number;"; } @@ -567,7 +567,7 @@ std::unique_ptr ExceptionDetails::Create(const EcmaVM *ecmaVm, result = Local(params)->Get(ecmaVm, Local(StringRef::NewFromUtf8(ecmaVm, "columnNumber"))); if (!result.IsEmpty() && !result->IsUndefined()) { if (result->IsNumber()) { - exceptionDetails->column_ = static_cast(Local(result)->Value()); + exceptionDetails->columnNumber_ = static_cast(Local(result)->Value()); } else { error += "'columnNumber' should be a Number;"; } @@ -643,18 +643,18 @@ std::unique_ptr ExceptionDetails::Create(const PtJson ¶ms) error += "Unknown 'text';"; } - int32_t line; - ret = params.GetInt("lineNumber", &line); + int32_t lineNumber; + ret = params.GetInt("lineNumber", &lineNumber); if (ret == Result::SUCCESS) { - exceptionDetails->line_ = line; + exceptionDetails->lineNumber_ = lineNumber; } else { error += "Unknown 'lineNumber';"; } - int32_t column; - ret = params.GetInt("columnNumber", &column); + int32_t columnNumber; + ret = params.GetInt("columnNumber", &columnNumber); if (ret == Result::SUCCESS) { - exceptionDetails->column_ = column; + exceptionDetails->columnNumber_ = columnNumber; } else { error += "Unknown 'columnNumber';"; } @@ -715,9 +715,9 @@ Local ExceptionDetails::ToObject(const EcmaVM *ecmaVm) const Local(StringRef::NewFromUtf8(ecmaVm, "text")), Local(StringRef::NewFromUtf8(ecmaVm, text_.c_str()))); params->Set(ecmaVm, Local(StringRef::NewFromUtf8(ecmaVm, "lineNumber")), - IntegerRef::New(ecmaVm, line_)); + IntegerRef::New(ecmaVm, lineNumber_)); params->Set(ecmaVm, Local(StringRef::NewFromUtf8(ecmaVm, "columnNumber")), - IntegerRef::New(ecmaVm, column_)); + IntegerRef::New(ecmaVm, columnNumber_)); if (scriptId_) { params->Set(ecmaVm, Local(StringRef::NewFromUtf8(ecmaVm, "scriptId")), @@ -749,8 +749,8 @@ std::unique_ptr ExceptionDetails::ToJson() const result->Add("exceptionId", exceptionId_); result->Add("text", text_.c_str()); - result->Add("lineNumber", line_); - result->Add("columnNumber", column_); + result->Add("lineNumber", lineNumber_); + result->Add("columnNumber", columnNumber_); if (scriptId_) { result->Add("scriptId", std::to_string(scriptId_.value()).c_str()); @@ -1412,64 +1412,24 @@ std::unique_ptr PropertyDescriptor::ToJson() const return result; } -std::unique_ptr CallArgument::Create(const EcmaVM *ecmaVm, const Local ¶ms) -{ - if (params.IsEmpty() || !params->IsObject()) { - LOG(ERROR, DEBUGGER) << "CallArgument::Create params is nullptr"; - return nullptr; - } - std::string error; - auto callArgument = std::make_unique(); - - Local result = - Local(params)->Get(ecmaVm, Local(StringRef::NewFromUtf8(ecmaVm, "value"))); - if (!result.IsEmpty() && !result->IsUndefined()) { - callArgument->value_ = result; - } - result = Local(params)->Get(ecmaVm, - Local(StringRef::NewFromUtf8(ecmaVm, "unserializableValue"))); - if (!result.IsEmpty() && !result->IsUndefined()) { - if (result->IsString()) { - callArgument->unserializableValue_ = DebuggerApi::ToStdString(result); - } else { - error += "'unserializableValue' should be a String;"; - } - } - result = Local(params)->Get(ecmaVm, Local(StringRef::NewFromUtf8(ecmaVm, "objectId"))); - if (!result.IsEmpty() && !result->IsUndefined()) { - if (result->IsString()) { - callArgument->objectId_ = static_cast(DebuggerApi::StringToInt(result)); - } else { - error += "'objectId' should be a String;"; - } - } - if (!error.empty()) { - LOG(ERROR, DEBUGGER) << "CallArgument::Create " << error; - return nullptr; - } - - return callArgument; -} - std::unique_ptr CallArgument::Create(const PtJson ¶ms) { - std::string error; auto callArgument = std::make_unique(); + std::string error; Result ret; std::string unserializableValue; ret = params.GetString("unserializableValue", &unserializableValue); if (ret == Result::SUCCESS) { callArgument->unserializableValue_ = std::move(unserializableValue); - } else if (ret == Result::TYPE_ERROR) { + } else if (ret == Result::TYPE_ERROR) { // optional value error += "Unknown 'unserializableValue';"; } - std::string objectId; ret = params.GetString("objectId", &objectId); if (ret == Result::SUCCESS) { callArgument->objectId_ = std::stoi(objectId); - } else if (ret == Result::TYPE_ERROR) { + } else if (ret == Result::TYPE_ERROR) { // optional value error += "Unknown 'objectId';"; } @@ -1481,27 +1441,6 @@ std::unique_ptr CallArgument::Create(const PtJson ¶ms) return callArgument; } -Local CallArgument::ToObject(const EcmaVM *ecmaVm) const -{ - Local params = NewObject(ecmaVm); - - if (value_) { - params->Set(ecmaVm, Local(StringRef::NewFromUtf8(ecmaVm, "value")), value_.value()); - } - if (unserializableValue_) { - params->Set(ecmaVm, - Local(StringRef::NewFromUtf8(ecmaVm, "unserializableValue")), - Local(StringRef::NewFromUtf8(ecmaVm, unserializableValue_->c_str()))); - } - if (objectId_) { - params->Set(ecmaVm, - Local(StringRef::NewFromUtf8(ecmaVm, "objectId")), - Local(StringRef::NewFromUtf8(ecmaVm, std::to_string(objectId_.value()).c_str()))); - } - - return params; -} - std::unique_ptr CallArgument::ToJson() const { std::unique_ptr result = PtJson::CreateObject(); @@ -1539,7 +1478,7 @@ std::unique_ptr Location::Create(const EcmaVM *ecmaVm, const Local(params)->Get(ecmaVm, Local(StringRef::NewFromUtf8(ecmaVm, "lineNumber"))); if (!result.IsEmpty() && !result->IsUndefined()) { if (result->IsNumber()) { - location->line_ = static_cast(Local(result)->Value()); + location->lineNumber_ = static_cast(Local(result)->Value()); } else { error += "'lineNumber' should be a Number;"; } @@ -1549,7 +1488,7 @@ std::unique_ptr Location::Create(const EcmaVM *ecmaVm, const Local(params)->Get(ecmaVm, Local(StringRef::NewFromUtf8(ecmaVm, "columnNumber"))); if (!result.IsEmpty() && !result->IsUndefined()) { if (result->IsNumber()) { - location->column_ = static_cast(Local(result)->Value()); + location->columnNumber_ = static_cast(Local(result)->Value()); } else { error += "'columnNumber' should be a Number;"; } @@ -1575,17 +1514,17 @@ std::unique_ptr Location::Create(const PtJson ¶ms) } else { error += "Unknown 'scriptId';"; } - int32_t line; - ret = params.GetInt("lineNumber", &line); + int32_t lineNumber; + ret = params.GetInt("lineNumber", &lineNumber); if (ret == Result::SUCCESS) { - location->line_ = line; + location->lineNumber_ = lineNumber; } else { error += "Unknown 'lineNumber';"; } - int32_t column; - ret = params.GetInt("columnNumber", &column); + int32_t columnNumber; + ret = params.GetInt("columnNumber", &columnNumber); if (ret == Result::SUCCESS) { - location->column_ = column; + location->columnNumber_ = columnNumber; } else if (ret == Result::TYPE_ERROR) { // optional value error += "Unknown 'columnNumber';"; } @@ -1606,11 +1545,11 @@ Local Location::ToObject(const EcmaVM *ecmaVm) const Local(StringRef::NewFromUtf8(ecmaVm, "scriptId")), Local(StringRef::NewFromUtf8(ecmaVm, std::to_string(scriptId_).c_str()))); params->Set(ecmaVm, Local(StringRef::NewFromUtf8(ecmaVm, "lineNumber")), - IntegerRef::New(ecmaVm, line_)); - if (column_) { + IntegerRef::New(ecmaVm, lineNumber_)); + if (columnNumber_) { params->Set(ecmaVm, Local(StringRef::NewFromUtf8(ecmaVm, "columnNumber")), - IntegerRef::New(ecmaVm, column_.value())); + IntegerRef::New(ecmaVm, columnNumber_.value())); } return params; @@ -1621,70 +1560,31 @@ std::unique_ptr Location::ToJson() const std::unique_ptr result = PtJson::CreateObject(); result->Add("scriptId", std::to_string(scriptId_).c_str()); - result->Add("lineNumber", line_); - if (column_) { - result->Add("columnNumber", column_.value()); + result->Add("lineNumber", lineNumber_); + if (columnNumber_) { + result->Add("columnNumber", columnNumber_.value()); } return result; } -std::unique_ptr ScriptPosition::Create(const EcmaVM *ecmaVm, const Local ¶ms) -{ - if (params.IsEmpty() || !params->IsObject()) { - LOG(ERROR, DEBUGGER) << "ScriptPosition::Create params is nullptr"; - return nullptr; - } - std::string error; - auto scriptPosition = std::make_unique(); - - Local result = - Local(params)->Get(ecmaVm, Local(StringRef::NewFromUtf8(ecmaVm, "lineNumber"))); - if (!result.IsEmpty() && !result->IsUndefined()) { - if (result->IsNumber()) { - scriptPosition->line_ = static_cast(Local(result)->Value()); - } else { - error += "'lineNumber' should be a Number;"; - } - } else { - error += "should contain 'lineNumber';"; - } - result = Local(params)->Get(ecmaVm, Local(StringRef::NewFromUtf8(ecmaVm, "columnNumber"))); - if (!result.IsEmpty() && !result->IsUndefined()) { - if (result->IsNumber()) { - scriptPosition->column_ = static_cast(Local(result)->Value()); - } else { - error += "'columnNumber' should be a Number;"; - } - } else { - error += "should contain 'columnNumber';"; - } - if (!error.empty()) { - LOG(ERROR, DEBUGGER) << "ScriptPosition::Create " << error; - return nullptr; - } - - return scriptPosition; -} - std::unique_ptr ScriptPosition::Create(const PtJson ¶ms) { - std::string error; auto scriptPosition = std::make_unique(); + std::string error; Result ret; - int32_t line; - ret = params.GetInt("lineNumber", &line); + int32_t lineNumber; + ret = params.GetInt("lineNumber", &lineNumber); if (ret == Result::SUCCESS) { - scriptPosition->line_ = line; + scriptPosition->lineNumber_ = lineNumber; } else { error += "Unknown 'lineNumber';"; } - - int32_t column; - ret = params.GetInt("columnNumber", &column); + int32_t columnNumber; + ret = params.GetInt("columnNumber", &columnNumber); if (ret == Result::SUCCESS) { - scriptPosition->column_ = column; + scriptPosition->columnNumber_ = columnNumber; } else { error += "Unknown 'columnNumber';"; } @@ -1702,9 +1602,9 @@ Local ScriptPosition::ToObject(const EcmaVM *ecmaVm) const Local params = NewObject(ecmaVm); params->Set(ecmaVm, Local(StringRef::NewFromUtf8(ecmaVm, "lineNumber")), - IntegerRef::New(ecmaVm, line_)); + IntegerRef::New(ecmaVm, lineNumber_)); params->Set(ecmaVm, Local(StringRef::NewFromUtf8(ecmaVm, "columnNumber")), - IntegerRef::New(ecmaVm, column_)); + IntegerRef::New(ecmaVm, columnNumber_)); return params; } @@ -1713,8 +1613,8 @@ std::unique_ptr ScriptPosition::ToJson() const { std::unique_ptr result = PtJson::CreateObject(); - result->Add("lineNumber", line_); - result->Add("columnNumber", column_); + result->Add("lineNumber", lineNumber_); + result->Add("columnNumber", columnNumber_); return result; } @@ -1811,64 +1711,6 @@ std::unique_ptr SearchMatch::ToJson() const return result; } -std::unique_ptr LocationRange::Create(const EcmaVM *ecmaVm, const Local ¶ms) -{ - if (params.IsEmpty() || !params->IsObject()) { - LOG(ERROR, DEBUGGER) << "BreakLocation::Create params is nullptr"; - return nullptr; - } - std::string error; - auto locationRange = std::make_unique(); - - Local result = - Local(params)->Get(ecmaVm, Local(StringRef::NewFromUtf8(ecmaVm, "scriptId"))); - if (!result.IsEmpty() && !result->IsUndefined()) { - if (result->IsString()) { - locationRange->scriptId_ = DebuggerApi::StringToInt(result); - } else { - error += "'scriptId' should be a String;"; - } - } else { - error += "should contain 'scriptId';"; - } - result = Local(params)->Get(ecmaVm, Local(StringRef::NewFromUtf8(ecmaVm, "start"))); - if (!result.IsEmpty() && !result->IsUndefined()) { - if (result->IsObject()) { - std::unique_ptr obj = ScriptPosition::Create(ecmaVm, result); - if (obj == nullptr) { - error += "'start' format error;"; - } else { - locationRange->start_ = std::move(obj); - } - } else { - error += "'start' should be an Object;"; - } - } else { - error += "should contain 'start';"; - } - result = Local(params)->Get(ecmaVm, Local(StringRef::NewFromUtf8(ecmaVm, "end"))); - if (!result.IsEmpty() && !result->IsUndefined()) { - if (result->IsObject()) { - std::unique_ptr obj = ScriptPosition::Create(ecmaVm, result); - if (obj == nullptr) { - error += "'end' format error;"; - } else { - locationRange->end_ = std::move(obj); - } - } else { - error += "'end' should be an Object;"; - } - } else { - error += "should contain 'end';"; - } - if (!error.empty()) { - LOG(ERROR, DEBUGGER) << "LocationRange::Create " << error; - return nullptr; - } - - return locationRange; -} - std::unique_ptr LocationRange::Create(const PtJson ¶ms) { std::string error; @@ -1974,7 +1816,7 @@ std::unique_ptr BreakLocation::Create(const EcmaVM *ecmaVm, const result = Local(params)->Get(ecmaVm, Local(StringRef::NewFromUtf8(ecmaVm, "lineNumber"))); if (!result.IsEmpty() && !result->IsUndefined()) { if (result->IsNumber()) { - breakLocation->line_ = static_cast(Local(result)->Value()); + breakLocation->lineNumber_ = static_cast(Local(result)->Value()); } else { error += "'lineNumber' should be a Number;"; } @@ -1984,7 +1826,7 @@ std::unique_ptr BreakLocation::Create(const EcmaVM *ecmaVm, const result = Local(params)->Get(ecmaVm, Local(StringRef::NewFromUtf8(ecmaVm, "columnNumber"))); if (!result.IsEmpty() && !result->IsUndefined()) { if (result->IsNumber()) { - breakLocation->column_ = static_cast(Local(result)->Value()); + breakLocation->columnNumber_ = static_cast(Local(result)->Value()); } else { error += "'columnNumber' should be a Number;"; } @@ -2027,7 +1869,7 @@ std::unique_ptr BreakLocation::Create(const PtJson ¶ms) int32_t lineNumber; ret = params.GetInt("lineNumber", &lineNumber); if (ret == Result::SUCCESS) { - breakLocation->line_ = lineNumber; + breakLocation->lineNumber_ = lineNumber; } else { error += "Unknown 'lineNumber';"; } @@ -2035,7 +1877,7 @@ std::unique_ptr BreakLocation::Create(const PtJson ¶ms) int32_t columnNumber; ret = params.GetInt("columnNumber", &columnNumber); if (ret == Result::SUCCESS) { - breakLocation->column_ = columnNumber; + breakLocation->columnNumber_ = columnNumber; } else if (ret == Result::TYPE_ERROR) { error += "Unknown 'columnNumber';"; } @@ -2068,11 +1910,11 @@ Local BreakLocation::ToObject(const EcmaVM *ecmaVm) const Local(StringRef::NewFromUtf8(ecmaVm, "scriptId")), Local(StringRef::NewFromUtf8(ecmaVm, std::to_string(scriptId_).c_str()))); params->Set(ecmaVm, Local(StringRef::NewFromUtf8(ecmaVm, "lineNumber")), - IntegerRef::New(ecmaVm, line_)); - if (column_) { + IntegerRef::New(ecmaVm, lineNumber_)); + if (columnNumber_) { params->Set(ecmaVm, Local(StringRef::NewFromUtf8(ecmaVm, "columnNumber")), - IntegerRef::New(ecmaVm, column_.value())); + IntegerRef::New(ecmaVm, columnNumber_.value())); } if (type_) { params->Set(ecmaVm, @@ -2088,9 +1930,9 @@ std::unique_ptr BreakLocation::ToJson() const std::unique_ptr result = PtJson::CreateObject(); result->Add("scriptId", std::to_string(scriptId_).c_str()); - result->Add("lineNumber", line_); - if (column_) { - result->Add("columnNumber", column_.value()); + result->Add("lineNumber", lineNumber_); + if (columnNumber_) { + result->Add("columnNumber", columnNumber_.value()); } if (type_) { result->Add("type", type_->c_str()); diff --git a/ecmascript/tooling/base/pt_types.h b/ecmascript/tooling/base/pt_types.h index 3913c8e55..c752210c9 100644 --- a/ecmascript/tooling/base/pt_types.h +++ b/ecmascript/tooling/base/pt_types.h @@ -440,23 +440,23 @@ public: int32_t GetLine() const { - return line_; + return lineNumber_; } - ExceptionDetails &SetLine(int32_t line) + ExceptionDetails &SetLine(int32_t lineNumber) { - line_ = line; + lineNumber_ = lineNumber; return *this; } int32_t GetColumn() const { - return column_; + return columnNumber_; } - ExceptionDetails &SetColumn(int32_t column) + ExceptionDetails &SetColumn(int32_t columnNumber) { - column_ = column; + columnNumber_ = columnNumber; return *this; } @@ -534,8 +534,8 @@ private: int32_t exceptionId_ {0}; std::string text_ {}; - int32_t line_ {0}; - int32_t column_ {0}; + int32_t lineNumber_ {0}; + int32_t columnNumber_ {0}; std::optional scriptId_ {}; std::optional url_ {}; std::optional> exception_ {}; @@ -872,9 +872,11 @@ public: CallArgument() = default; ~CallArgument() override = default; - static std::unique_ptr Create(const EcmaVM *ecmaVm, const Local ¶ms); static std::unique_ptr Create(const PtJson ¶ms); - Local ToObject(const EcmaVM *ecmaVm) const override; + Local ToObject([[maybe_unused]] const EcmaVM *ecmaVm) const override + { + return Local(); + } std::unique_ptr ToJson() const override; Local GetValue() const @@ -976,29 +978,29 @@ public: int32_t GetLine() const { - return line_; + return lineNumber_; } Location &SetLine(int32_t line) { - line_ = line; + lineNumber_ = line; return *this; } int32_t GetColumn() const { - return column_.value_or(-1); + return columnNumber_.value_or(-1); } Location &SetColumn(int32_t column) { - column_ = column; + columnNumber_ = column; return *this; } bool HasColumn() const { - return column_.has_value(); + return columnNumber_.has_value(); } private: @@ -1006,8 +1008,8 @@ private: NO_MOVE_SEMANTIC(Location); ScriptId scriptId_ {}; - int32_t line_ {0}; - std::optional column_ {}; + int32_t lineNumber_ {0}; + std::optional columnNumber_ {}; }; // Debugger.ScriptPosition @@ -1016,30 +1018,29 @@ public: ScriptPosition() = default; ~ScriptPosition() override = default; - static std::unique_ptr Create(const EcmaVM *ecmaVm, const Local ¶ms); static std::unique_ptr Create(const PtJson ¶ms); Local ToObject(const EcmaVM *ecmaVm) const override; std::unique_ptr ToJson() const override; int32_t GetLine() const { - return line_; + return lineNumber_; } ScriptPosition &SetLine(int32_t line) { - line_ = line; + lineNumber_ = line; return *this; } int32_t GetColumn() const { - return column_; + return columnNumber_; } ScriptPosition &SetColumn(int32_t column) { - column_ = column; + columnNumber_ = column; return *this; } @@ -1047,8 +1048,8 @@ private: NO_COPY_SEMANTIC(ScriptPosition); NO_MOVE_SEMANTIC(ScriptPosition); - int32_t line_ {0}; - int32_t column_ {0}; + int32_t lineNumber_ {0}; + int32_t columnNumber_ {0}; }; // Debugger.SearchMatch @@ -1075,7 +1076,6 @@ public: LocationRange() = default; ~LocationRange() override = default; - static std::unique_ptr Create(const EcmaVM *ecmaVm, const Local ¶ms); static std::unique_ptr Create(const PtJson ¶ms); Local ToObject(const EcmaVM *ecmaVm) const override; std::unique_ptr ToJson() const override; @@ -1146,29 +1146,29 @@ public: int32_t GetLine() const { - return line_; + return lineNumber_; } - BreakLocation &SetLine(int32_t line) + BreakLocation &SetLine(int32_t lineNumber) { - line_ = line; + lineNumber_ = lineNumber; return *this; } int32_t GetColumn() const { - return column_.value_or(-1); + return columnNumber_.value_or(-1); } - BreakLocation &SetColumn(int32_t column) + BreakLocation &SetColumn(int32_t columnNumber) { - column_ = column; + columnNumber_ = columnNumber; return *this; } bool HasColumn() const { - return column_.has_value(); + return columnNumber_.has_value(); } /* @@ -1215,8 +1215,8 @@ private: NO_MOVE_SEMANTIC(BreakLocation); ScriptId scriptId_ {}; - int32_t line_ {0}; - std::optional column_ {}; + int32_t lineNumber_ {0}; + std::optional columnNumber_ {}; std::optional type_ {}; }; using BreakType = BreakLocation::Type; @@ -1515,7 +1515,7 @@ private: // ========== Heapprofiler types begin -using HeapSnapshotObjectId = uint32_t; +using HeapSnapshotObjectId = int32_t; class SamplingHeapProfileSample final : public PtBaseTypes { public: diff --git a/ecmascript/tooling/test/debugger_params_test.cpp b/ecmascript/tooling/test/debugger_params_test.cpp index b9802d058..61825046c 100644 --- a/ecmascript/tooling/test/debugger_params_test.cpp +++ b/ecmascript/tooling/test/debugger_params_test.cpp @@ -88,41 +88,31 @@ HWTEST_F_L0(DebuggerParamsTest, StartSamplingParamsCreateTest) std::string msg; std::unique_ptr startSamplingData; - // abnormal params of null msg - msg = std::string() + R"({})"; - startSamplingData = StartSamplingParams::Create(ecmaVm, DispatchRequest(ecmaVm, msg).GetParamsObj()); - EXPECT_EQ(startSamplingData, nullptr); - - // abnormal params of unexist key params - msg = std::string() + R"({"id":0,"method":"Debugger.Test"})"; - startSamplingData = StartSamplingParams::Create(ecmaVm, DispatchRequest(ecmaVm, msg).GetParamsObj()); - EXPECT_EQ(startSamplingData, nullptr); - // abnormal params of null params.sub-key msg = std::string() + R"({"id":0,"method":"Debugger.Test","params":{}})"; - startSamplingData = StartSamplingParams::Create(ecmaVm, DispatchRequest(ecmaVm, msg).GetParamsObj()); + startSamplingData = StartSamplingParams::Create(DispatchRequest(ecmaVm, msg).GetParams()); ASSERT_NE(startSamplingData, nullptr); EXPECT_EQ(startSamplingData->GetSamplingInterval(), 32768); // abnormal params of unknown params.sub-key msg = std::string() + R"({"id":0,"method":"Debugger.Test","params":{"unknownKey":100}})"; - startSamplingData = StartSamplingParams::Create(ecmaVm, DispatchRequest(ecmaVm, msg).GetParamsObj()); + startSamplingData = StartSamplingParams::Create(DispatchRequest(ecmaVm, msg).GetParams()); ASSERT_NE(startSamplingData, nullptr); EXPECT_EQ(startSamplingData->GetSamplingInterval(), 32768); // abnormal params of params.sub-key=["samplingInterval":true] msg = std::string() + R"({"id":0,"method":"Debugger.Test","params":{"samplingInterval":true}})"; - startSamplingData = StartSamplingParams::Create(ecmaVm, DispatchRequest(ecmaVm, msg).GetParamsObj()); + startSamplingData = StartSamplingParams::Create(DispatchRequest(ecmaVm, msg).GetParams()); EXPECT_EQ(startSamplingData, nullptr); // abnormal params of params.sub-key=["samplingInterval":true] msg = std::string() + R"({"id":0,"method":"Debugger.Test","params":{"samplingInterval":"Test"}})"; - startSamplingData = StartSamplingParams::Create(ecmaVm, DispatchRequest(ecmaVm, msg).GetParamsObj()); + startSamplingData = StartSamplingParams::Create(DispatchRequest(ecmaVm, msg).GetParams()); EXPECT_EQ(startSamplingData, nullptr); // abnormal params of params.sub-key = [ "size"=100,"nodeId"=1,"ordinal"=10] msg = std::string() + R"({"id":0,"method":"Debugger.Test","params":{"samplingInterval":1000}})"; - startSamplingData = StartSamplingParams::Create(ecmaVm, DispatchRequest(ecmaVm, msg).GetParamsObj()); + startSamplingData = StartSamplingParams::Create(DispatchRequest(ecmaVm, msg).GetParams()); ASSERT_NE(startSamplingData, nullptr); EXPECT_EQ(startSamplingData->GetSamplingInterval(), 1000); } @@ -132,41 +122,31 @@ HWTEST_F_L0(DebuggerParamsTest, StartTrackingHeapObjectsParamsCreateTest) std::string msg; std::unique_ptr objectData; - // abnormal params of null msg - msg = std::string() + R"({})"; - objectData = StartTrackingHeapObjectsParams::Create(ecmaVm, DispatchRequest(ecmaVm, msg).GetParamsObj()); - EXPECT_EQ(objectData, nullptr); - - // abnormal params of unexist key params - msg = std::string() + R"({"id":0,"method":"Debugger.Test"})"; - objectData = StartTrackingHeapObjectsParams::Create(ecmaVm, DispatchRequest(ecmaVm, msg).GetParamsObj()); - EXPECT_EQ(objectData, nullptr); - // abnormal params of null params.sub-key msg = std::string() + R"({"id":0,"method":"Debugger.Test","params":{}})"; - objectData = StartTrackingHeapObjectsParams::Create(ecmaVm, DispatchRequest(ecmaVm, msg).GetParamsObj()); + objectData = StartTrackingHeapObjectsParams::Create(DispatchRequest(ecmaVm, msg).GetParams()); ASSERT_NE(objectData, nullptr); ASSERT_FALSE(objectData->GetTrackAllocations()); // abnormal params of unknown params.sub-key msg = std::string() + R"({"id":0,"method":"Debugger.Test","params":{"unknownKey":100}})"; - objectData = StartTrackingHeapObjectsParams::Create(ecmaVm, DispatchRequest(ecmaVm, msg).GetParamsObj()); + objectData = StartTrackingHeapObjectsParams::Create(DispatchRequest(ecmaVm, msg).GetParams()); ASSERT_NE(objectData, nullptr); ASSERT_FALSE(objectData->GetTrackAllocations()); // abnormal params of params.sub-key=["trackAllocations":10] msg = std::string() + R"({"id":0,"method":"Debugger.Test","params":{"trackAllocations":10}})"; - objectData = StartTrackingHeapObjectsParams::Create(ecmaVm, DispatchRequest(ecmaVm, msg).GetParamsObj()); + objectData = StartTrackingHeapObjectsParams::Create(DispatchRequest(ecmaVm, msg).GetParams()); EXPECT_EQ(objectData, nullptr); // abnormal params of params.sub-key=["trackAllocations":"Test"] msg = std::string() + R"({"id":0,"method":"Debugger.Test","params":{"trackAllocations":"Test"}})"; - objectData = StartTrackingHeapObjectsParams::Create(ecmaVm, DispatchRequest(ecmaVm, msg).GetParamsObj()); + objectData = StartTrackingHeapObjectsParams::Create(DispatchRequest(ecmaVm, msg).GetParams()); EXPECT_EQ(objectData, nullptr); // abnormal params of params.sub-key=["trackAllocations":true] msg = std::string() + R"({"id":0,"method":"Debugger.Test","params":{"trackAllocations":true}})"; - objectData = StartTrackingHeapObjectsParams::Create(ecmaVm, DispatchRequest(ecmaVm, msg).GetParamsObj()); + objectData = StartTrackingHeapObjectsParams::Create(DispatchRequest(ecmaVm, msg).GetParams()); ASSERT_NE(objectData, nullptr); ASSERT_TRUE(objectData->GetTrackAllocations()); } @@ -176,19 +156,9 @@ HWTEST_F_L0(DebuggerParamsTest, StopTrackingHeapObjectsParamsCreateTest) std::string msg; std::unique_ptr objectData; - // abnormal params of null msg - msg = std::string() + R"({})"; - objectData = StopTrackingHeapObjectsParams::Create(ecmaVm, DispatchRequest(ecmaVm, msg).GetParamsObj()); - EXPECT_EQ(objectData, nullptr); - - // abnormal params of unexist key params - msg = std::string() + R"({"id":0,"method":"Debugger.Test"})"; - objectData = StopTrackingHeapObjectsParams::Create(ecmaVm, DispatchRequest(ecmaVm, msg).GetParamsObj()); - EXPECT_EQ(objectData, nullptr); - // abnormal params of null params.sub-key msg = std::string() + R"({"id":0,"method":"Debugger.Test","params":{}})"; - objectData = StopTrackingHeapObjectsParams::Create(ecmaVm, DispatchRequest(ecmaVm, msg).GetParamsObj()); + objectData = StopTrackingHeapObjectsParams::Create(DispatchRequest(ecmaVm, msg).GetParams()); ASSERT_NE(objectData, nullptr); ASSERT_FALSE(objectData->GetReportProgress()); ASSERT_FALSE(objectData->GetTreatGlobalObjectsAsRoots()); @@ -196,7 +166,7 @@ HWTEST_F_L0(DebuggerParamsTest, StopTrackingHeapObjectsParamsCreateTest) // abnormal params of unknown params.sub-key msg = std::string() + R"({"id":0,"method":"Debugger.Test","params":{"unknownKey":100}})"; - objectData = StopTrackingHeapObjectsParams::Create(ecmaVm, DispatchRequest(ecmaVm, msg).GetParamsObj()); + objectData = StopTrackingHeapObjectsParams::Create(DispatchRequest(ecmaVm, msg).GetParams()); ASSERT_NE(objectData, nullptr); ASSERT_FALSE(objectData->GetReportProgress()); ASSERT_FALSE(objectData->GetTreatGlobalObjectsAsRoots()); @@ -206,21 +176,21 @@ HWTEST_F_L0(DebuggerParamsTest, StopTrackingHeapObjectsParamsCreateTest) "reportProgress":10, "treatGlobalObjectsAsRoots":10, "captureNumericValue":10}})"; - objectData = StopTrackingHeapObjectsParams::Create(ecmaVm, DispatchRequest(ecmaVm, msg).GetParamsObj()); + objectData = StopTrackingHeapObjectsParams::Create(DispatchRequest(ecmaVm, msg).GetParams()); EXPECT_EQ(objectData, nullptr); msg = std::string() + R"({"id":0,"method":"Debugger.Test","params":{ "reportProgress":"Test", "treatGlobalObjectsAsRoots":"Test", "captureNumericValue":"Test"}})"; - objectData = StopTrackingHeapObjectsParams::Create(ecmaVm, DispatchRequest(ecmaVm, msg).GetParamsObj()); + objectData = StopTrackingHeapObjectsParams::Create(DispatchRequest(ecmaVm, msg).GetParams()); EXPECT_EQ(objectData, nullptr); msg = std::string() + R"({"id":0,"method":"Debugger.Test","params":{ "reportProgress":true, "treatGlobalObjectsAsRoots":true, "captureNumericValue":true}})"; - objectData = StopTrackingHeapObjectsParams::Create(ecmaVm, DispatchRequest(ecmaVm, msg).GetParamsObj()); + objectData = StopTrackingHeapObjectsParams::Create(DispatchRequest(ecmaVm, msg).GetParams()); ASSERT_NE(objectData, nullptr); ASSERT_TRUE(objectData->GetReportProgress()); ASSERT_TRUE(objectData->GetTreatGlobalObjectsAsRoots()); @@ -234,39 +204,39 @@ HWTEST_F_L0(DebuggerParamsTest, AddInspectedHeapObjectParamsCreateTest) // abnormal params of null msg msg = std::string() + R"({})"; - objectData = AddInspectedHeapObjectParams::Create(ecmaVm, DispatchRequest(ecmaVm, msg).GetParamsObj()); + objectData = AddInspectedHeapObjectParams::Create(DispatchRequest(ecmaVm, msg).GetParams()); EXPECT_EQ(objectData, nullptr); // abnormal params of unexist key params msg = std::string() + R"({"id":0,"method":"Debugger.Test"})"; - objectData = AddInspectedHeapObjectParams::Create(ecmaVm, DispatchRequest(ecmaVm, msg).GetParamsObj()); + objectData = AddInspectedHeapObjectParams::Create(DispatchRequest(ecmaVm, msg).GetParams()); EXPECT_EQ(objectData, nullptr); // abnormal params of null params.sub-key msg = std::string() + R"({"id":0,"method":"Debugger.Test","params":{}})"; - objectData = AddInspectedHeapObjectParams::Create(ecmaVm, DispatchRequest(ecmaVm, msg).GetParamsObj()); + objectData = AddInspectedHeapObjectParams::Create(DispatchRequest(ecmaVm, msg).GetParams()); EXPECT_EQ(objectData, nullptr); // abnormal params of unknown params.sub-key msg = std::string() + R"({"id":0,"method":"Debugger.Test","params":{"unknownKey":100}})"; - objectData = AddInspectedHeapObjectParams::Create(ecmaVm, DispatchRequest(ecmaVm, msg).GetParamsObj()); + objectData = AddInspectedHeapObjectParams::Create(DispatchRequest(ecmaVm, msg).GetParams()); EXPECT_EQ(objectData, nullptr); // abnormal params of params.sub-key=["heapObjectId":10] msg = std::string() + R"({"id":0,"method":"Debugger.Test","params":{"heapObjectId":10}})"; - objectData = AddInspectedHeapObjectParams::Create(ecmaVm, DispatchRequest(ecmaVm, msg).GetParamsObj()); + objectData = AddInspectedHeapObjectParams::Create(DispatchRequest(ecmaVm, msg).GetParams()); EXPECT_EQ(objectData, nullptr); // abnormal params of params.sub-key=["heapObjectId":true] msg = std::string() + R"({"id":0,"method":"Debugger.Test","params":{"heapObjectId":true}})"; - objectData = AddInspectedHeapObjectParams::Create(ecmaVm, DispatchRequest(ecmaVm, msg).GetParamsObj()); + objectData = AddInspectedHeapObjectParams::Create(DispatchRequest(ecmaVm, msg).GetParams()); EXPECT_EQ(objectData, nullptr); // abnormal params of params.sub-key=["heapObjectId":“10”] msg = std::string() + R"({"id":0,"method":"Debugger.Test","params":{"heapObjectId":"10"}})"; - objectData = AddInspectedHeapObjectParams::Create(ecmaVm, DispatchRequest(ecmaVm, msg).GetParamsObj()); + objectData = AddInspectedHeapObjectParams::Create(DispatchRequest(ecmaVm, msg).GetParams()); ASSERT_NE(objectData, nullptr); - EXPECT_EQ((int)objectData->GetHeapObjectId(), 10); + EXPECT_EQ(objectData->GetHeapObjectId(), 10); } HWTEST_F_L0(DebuggerParamsTest, GetHeapObjectIdParamsCreateTest) @@ -274,39 +244,19 @@ HWTEST_F_L0(DebuggerParamsTest, GetHeapObjectIdParamsCreateTest) std::string msg; std::unique_ptr objectData; - // abnormal params of null msg - msg = std::string() + R"({})"; - objectData = GetHeapObjectIdParams::Create(ecmaVm, DispatchRequest(ecmaVm, msg).GetParamsObj()); - EXPECT_EQ(objectData, nullptr); - - // abnormal params of unexist key params - msg = std::string() + R"({"id":0,"method":"Debugger.Test"})"; - objectData = GetHeapObjectIdParams::Create(ecmaVm, DispatchRequest(ecmaVm, msg).GetParamsObj()); - EXPECT_EQ(objectData, nullptr); - - // abnormal params of null params.sub-key - msg = std::string() + R"({"id":0,"method":"Debugger.Test","params":{}})"; - objectData = GetHeapObjectIdParams::Create(ecmaVm, DispatchRequest(ecmaVm, msg).GetParamsObj()); - EXPECT_EQ(objectData, nullptr); - - // abnormal params of unknown params.sub-key - msg = std::string() + R"({"id":0,"method":"Debugger.Test","params":{"unknownKey":100}})"; - objectData = GetHeapObjectIdParams::Create(ecmaVm, DispatchRequest(ecmaVm, msg).GetParamsObj()); - EXPECT_EQ(objectData, nullptr); - // abnormal params of params.sub-key=["objectId":10] msg = std::string() + R"({"id":0,"method":"Debugger.Test","params":{"objectId":10}})"; - objectData = GetHeapObjectIdParams::Create(ecmaVm, DispatchRequest(ecmaVm, msg).GetParamsObj()); + objectData = GetHeapObjectIdParams::Create(DispatchRequest(ecmaVm, msg).GetParams()); EXPECT_EQ(objectData, nullptr); // abnormal params of params.sub-key=["objectId":true] msg = std::string() + R"({"id":0,"method":"Debugger.Test","params":{"objectId":true}})"; - objectData = GetHeapObjectIdParams::Create(ecmaVm, DispatchRequest(ecmaVm, msg).GetParamsObj()); + objectData = GetHeapObjectIdParams::Create(DispatchRequest(ecmaVm, msg).GetParams()); EXPECT_EQ(objectData, nullptr); // abnormal params of params.sub-key=["objectId":“10”] msg = std::string() + R"({"id":0,"method":"Debugger.Test","params":{"objectId":"10"}})"; - objectData = GetHeapObjectIdParams::Create(ecmaVm, DispatchRequest(ecmaVm, msg).GetParamsObj()); + objectData = GetHeapObjectIdParams::Create(DispatchRequest(ecmaVm, msg).GetParams()); ASSERT_NE(objectData, nullptr); EXPECT_EQ((int)objectData->GetObjectId(), 10); } @@ -316,45 +266,25 @@ HWTEST_F_L0(DebuggerParamsTest, GetObjectByHeapObjectIdParamsCreateTest) std::string msg; std::unique_ptr objectData; - // abnormal params of null msg - msg = std::string() + R"({})"; - objectData = GetObjectByHeapObjectIdParams::Create(ecmaVm, DispatchRequest(ecmaVm, msg).GetParamsObj()); - EXPECT_EQ(objectData, nullptr); - - // abnormal params of unexist key params - msg = std::string() + R"({"id":0,"method":"Debugger.Test"})"; - objectData = GetObjectByHeapObjectIdParams::Create(ecmaVm, DispatchRequest(ecmaVm, msg).GetParamsObj()); - EXPECT_EQ(objectData, nullptr); - - // abnormal params of null params.sub-key - msg = std::string() + R"({"id":0,"method":"Debugger.Test","params":{}})"; - objectData = GetObjectByHeapObjectIdParams::Create(ecmaVm, DispatchRequest(ecmaVm, msg).GetParamsObj()); - EXPECT_EQ(objectData, nullptr); - - // abnormal params of unknown params.sub-key - msg = std::string() + R"({"id":0,"method":"Debugger.Test","params":{"unknownKey":100}})"; - objectData = GetObjectByHeapObjectIdParams::Create(ecmaVm, DispatchRequest(ecmaVm, msg).GetParamsObj()); - EXPECT_EQ(objectData, nullptr); - // abnormal params of params.sub-key=["objectId":10] msg = std::string() + R"({"id":0,"method":"Debugger.Test","params":{"objectId":10}})"; - objectData = GetObjectByHeapObjectIdParams::Create(ecmaVm, DispatchRequest(ecmaVm, msg).GetParamsObj()); + objectData = GetObjectByHeapObjectIdParams::Create(DispatchRequest(ecmaVm, msg).GetParams()); EXPECT_EQ(objectData, nullptr); // abnormal params of params.sub-key=["objectId":true] msg = std::string() + R"({"id":0,"method":"Debugger.Test","params":{"objectId":"10", "objectGroup":10}})"; - objectData = GetObjectByHeapObjectIdParams::Create(ecmaVm, DispatchRequest(ecmaVm, msg).GetParamsObj()); + objectData = GetObjectByHeapObjectIdParams::Create(DispatchRequest(ecmaVm, msg).GetParams()); EXPECT_EQ(objectData, nullptr); // abnormal params of params.sub-key=["objectId":“10”] msg = std::string() + R"({"id":0,"method":"Debugger.Test","params":{"objectId":"10"}})"; - objectData = GetObjectByHeapObjectIdParams::Create(ecmaVm, DispatchRequest(ecmaVm, msg).GetParamsObj()); + objectData = GetObjectByHeapObjectIdParams::Create(DispatchRequest(ecmaVm, msg).GetParams()); ASSERT_NE(objectData, nullptr); EXPECT_EQ((int)objectData->GetObjectId(), 10); ASSERT_FALSE(objectData->HasObjectGroup()); msg = std::string() + R"({"id":0,"method":"Debugger.Test","params":{"objectId":"10", "objectGroup":"groupname"}})"; - objectData = GetObjectByHeapObjectIdParams::Create(ecmaVm, DispatchRequest(ecmaVm, msg).GetParamsObj()); + objectData = GetObjectByHeapObjectIdParams::Create(DispatchRequest(ecmaVm, msg).GetParams()); ASSERT_NE(objectData, nullptr); EXPECT_EQ((int)objectData->GetObjectId(), 10); EXPECT_EQ(objectData->GetObjectGroup(), "groupname"); @@ -365,45 +295,35 @@ HWTEST_F_L0(DebuggerParamsTest, StartPreciseCoverageParamCreateTest) std::string msg; std::unique_ptr objectData; - // abnormal params of null msg - msg = std::string() + R"({})"; - objectData = StartPreciseCoverageParams::Create(ecmaVm, DispatchRequest(ecmaVm, msg).GetParamsObj()); - EXPECT_EQ(objectData, nullptr); - - // abnormal params of unexist key params - msg = std::string() + R"({"id":0,"method":"Debugger.Test"})"; - objectData = StartPreciseCoverageParams::Create(ecmaVm, DispatchRequest(ecmaVm, msg).GetParamsObj()); - EXPECT_EQ(objectData, nullptr); - // abnormal params of null params.sub-key msg = std::string() + R"({"id":0,"method":"Debugger.Test","params":{}})"; - objectData = StartPreciseCoverageParams::Create(ecmaVm, DispatchRequest(ecmaVm, msg).GetParamsObj()); + objectData = StartPreciseCoverageParams::Create(DispatchRequest(ecmaVm, msg).GetParams()); ASSERT_NE(objectData, nullptr); // abnormal params of unknown params.sub-key msg = std::string() + R"({"id":0,"method":"Debugger.Test","params":{"unknownKey":100}})"; - objectData = StartPreciseCoverageParams::Create(ecmaVm, DispatchRequest(ecmaVm, msg).GetParamsObj()); + objectData = StartPreciseCoverageParams::Create(DispatchRequest(ecmaVm, msg).GetParams()); ASSERT_NE(objectData, nullptr); msg = std::string() + R"({"id":0,"method":"Debugger.Test","params":{ "callCount":8, "detailed":8, "allowTriggeredUpdates":8}})"; - objectData = StartPreciseCoverageParams::Create(ecmaVm, DispatchRequest(ecmaVm, msg).GetParamsObj()); + objectData = StartPreciseCoverageParams::Create(DispatchRequest(ecmaVm, msg).GetParams()); EXPECT_EQ(objectData, nullptr); msg = std::string() + R"({"id":0,"method":"Debugger.Test","params":{ "callCount":"Test", "detailed":"Test", "allowTriggeredUpdates":"Test"}})"; - objectData = StartPreciseCoverageParams::Create(ecmaVm, DispatchRequest(ecmaVm, msg).GetParamsObj()); + objectData = StartPreciseCoverageParams::Create(DispatchRequest(ecmaVm, msg).GetParams()); EXPECT_EQ(objectData, nullptr); msg = std::string() + R"({"id":0,"method":"Debugger.Test","params":{ "callCount":true, "detailed":true, "allowTriggeredUpdates":true}})"; - objectData = StartPreciseCoverageParams::Create(ecmaVm, DispatchRequest(ecmaVm, msg).GetParamsObj()); + objectData = StartPreciseCoverageParams::Create(DispatchRequest(ecmaVm, msg).GetParams()); ASSERT_NE(objectData, nullptr); ASSERT_TRUE(objectData->GetCallCount()); ASSERT_TRUE(objectData->GetDetailed()); @@ -417,31 +337,31 @@ HWTEST_F_L0(DebuggerParamsTest, SetSamplingIntervalParamsCreateTest) // abnormal params of null msg msg = std::string() + R"({})"; - objectData = SetSamplingIntervalParams::Create(ecmaVm, DispatchRequest(ecmaVm, msg).GetParamsObj()); + objectData = SetSamplingIntervalParams::Create(DispatchRequest(ecmaVm, msg).GetParams()); EXPECT_EQ(objectData, nullptr); // abnormal params of unexist key params msg = std::string() + R"({"id":0,"method":"Debugger.Test"})"; - objectData = SetSamplingIntervalParams::Create(ecmaVm, DispatchRequest(ecmaVm, msg).GetParamsObj()); + objectData = SetSamplingIntervalParams::Create(DispatchRequest(ecmaVm, msg).GetParams()); EXPECT_EQ(objectData, nullptr); // abnormal params of null params.sub-key msg = std::string() + R"({"id":0,"method":"Debugger.Test","params":{}})"; - objectData = SetSamplingIntervalParams::Create(ecmaVm, DispatchRequest(ecmaVm, msg).GetParamsObj()); + objectData = SetSamplingIntervalParams::Create(DispatchRequest(ecmaVm, msg).GetParams()); EXPECT_EQ(objectData, nullptr); // abnormal params of unknown params.sub-key msg = std::string() + R"({"id":0,"method":"Debugger.Test","params":{"unknownKey":100}})"; - objectData = SetSamplingIntervalParams::Create(ecmaVm, DispatchRequest(ecmaVm, msg).GetParamsObj()); + objectData = SetSamplingIntervalParams::Create(DispatchRequest(ecmaVm, msg).GetParams()); EXPECT_EQ(objectData, nullptr); msg = std::string() + R"({"id":0,"method":"Debugger.Test","params":{ "interval":"500"}})"; - objectData = SetSamplingIntervalParams::Create(ecmaVm, DispatchRequest(ecmaVm, msg).GetParamsObj()); + objectData = SetSamplingIntervalParams::Create(DispatchRequest(ecmaVm, msg).GetParams()); EXPECT_EQ(objectData, nullptr); msg = std::string() + R"({"id":0,"method":"Debugger.Test","params":{"interval":500}})"; - objectData = SetSamplingIntervalParams::Create(ecmaVm, DispatchRequest(ecmaVm, msg).GetParamsObj()); + objectData = SetSamplingIntervalParams::Create(DispatchRequest(ecmaVm, msg).GetParams()); ASSERT_NE(objectData, nullptr); EXPECT_EQ(objectData->GetInterval(), 500); } -- Gitee From d45530583a16aa9ef693e1c2bcf2050b881d9067 Mon Sep 17 00:00:00 2001 From: wengchangcheng Date: Mon, 13 Jun 2022 22:40:45 +0800 Subject: [PATCH 2/2] Descriptor: debugger refactor of independent js_runtime [ part-4 ] details: 1. Add PtBaseReturns::ToJson 2. Add PtBaseEvents::ToJson issue: https://gitee.com/openharmony/ark_js_runtime/issues/I5C3FS Signed-off-by: wengchangcheng Change-Id: Ic8028d79f62b91724f22c63e8062d57367b5f27e --- ecmascript/dfx/hprof/heap_snapshot.cpp | 20 +- ecmascript/dfx/hprof/heap_snapshot.h | 12 +- .../tooling/agent/heapprofiler_impl.cpp | 12 +- ecmascript/tooling/agent/heapprofiler_impl.h | 12 +- ecmascript/tooling/base/pt_events.cpp | 249 +++++++++++++++ ecmascript/tooling/base/pt_events.h | 33 +- ecmascript/tooling/base/pt_params.cpp | 2 +- ecmascript/tooling/base/pt_returns.cpp | 300 +++++++++++++++++- ecmascript/tooling/base/pt_returns.h | 32 +- ecmascript/tooling/interface/file_stream.cpp | 8 +- ecmascript/tooling/interface/file_stream.h | 12 +- ecmascript/tooling/interface/stream.h | 14 +- .../tooling/test/debugger_events_test.cpp | 2 +- .../tooling/test/debugger_returns_test.cpp | 4 +- 14 files changed, 639 insertions(+), 73 deletions(-) diff --git a/ecmascript/dfx/hprof/heap_snapshot.cpp b/ecmascript/dfx/hprof/heap_snapshot.cpp index ddb448c31..5925e57c1 100644 --- a/ecmascript/dfx/hprof/heap_snapshot.cpp +++ b/ecmascript/dfx/hprof/heap_snapshot.cpp @@ -136,16 +136,16 @@ void HeapSnapshot::PushHeapStat(Stream* stream) LOG(ERROR, DEBUGGER) << "HeapSnapshot::PushHeapStat::stream is nullptr"; return; } - int preChunkSize = stream->GetSize(); - uint32_t sequenceId = 0; + int32_t preChunkSize = stream->GetSize(); + int32_t sequenceId = 0; auto iter = nodes_.begin(); for (size_t timeIndex = 0; timeIndex < timeStamps_.size(); ++timeIndex) { TimeStamp& timeStamp = timeStamps_[timeIndex]; - sequenceId = static_cast(timeStamp.GetLastSequenceId()); - uint32_t nodesSize = 0; - uint32_t nodesCount = 0; + sequenceId = timeStamp.GetLastSequenceId(); + int32_t nodesSize = 0; + int32_t nodesCount = 0; - while (iter != nodes_.end() && (*iter)->GetId() <= sequenceId) { + while (iter != nodes_.end() && (*iter)->GetId() <= static_cast(sequenceId)) { nodesCount++; nodesSize += (*iter)->GetSelfSize(); iter++; @@ -154,16 +154,16 @@ void HeapSnapshot::PushHeapStat(Stream* stream) && ((nodesCount != 0) && (nodesSize != 0))) { timeStamp.SetCount(nodesCount); timeStamp.SetSize(nodesSize); - statsBuffer.emplace_back(static_cast(timeIndex), nodesCount, nodesSize); - if (static_cast(statsBuffer.size()) >= preChunkSize) { - stream->UpdateHeapStats(&statsBuffer.front(), static_cast(statsBuffer.size())); + statsBuffer.emplace_back(static_cast(timeIndex), nodesCount, nodesSize); + if (static_cast(statsBuffer.size()) >= preChunkSize) { + stream->UpdateHeapStats(&statsBuffer.front(), static_cast(statsBuffer.size())); statsBuffer.clear(); } } } if (!statsBuffer.empty()) { - stream->UpdateHeapStats(&statsBuffer.front(), static_cast(statsBuffer.size())); + stream->UpdateHeapStats(&statsBuffer.front(), static_cast(statsBuffer.size())); statsBuffer.clear(); } stream->UpdateLastSeenObjectId(sequenceId); diff --git a/ecmascript/dfx/hprof/heap_snapshot.h b/ecmascript/dfx/hprof/heap_snapshot.h index 5f95f766b..61b0e15c0 100644 --- a/ecmascript/dfx/hprof/heap_snapshot.h +++ b/ecmascript/dfx/hprof/heap_snapshot.h @@ -197,22 +197,22 @@ public: return timeStampUs_; } - uint32_t GetSize() const + int32_t GetSize() const { return size_; } - void SetSize(uint32_t size) + void SetSize(int32_t size) { size_ = size; } - uint32_t GetCount() const + int32_t GetCount() const { return count_; } - void SetCount(uint32_t count) + void SetCount(int32_t count) { count_ = count; } @@ -228,8 +228,8 @@ private: int lastSequenceId_ {0}; int64_t timeStampUs_ {0}; - uint32_t size_ {0}; - uint32_t count_ {0}; + int32_t size_ {0}; + int32_t count_ {0}; }; class HeapEntryMap { diff --git a/ecmascript/tooling/agent/heapprofiler_impl.cpp b/ecmascript/tooling/agent/heapprofiler_impl.cpp index cd99f1e8c..abf5aa9f9 100644 --- a/ecmascript/tooling/agent/heapprofiler_impl.cpp +++ b/ecmascript/tooling/agent/heapprofiler_impl.cpp @@ -168,7 +168,7 @@ bool HeapProfilerImpl::Frontend::AllowNotify() const return channel_ != nullptr; } -void HeapProfilerImpl::Frontend::AddHeapSnapshotChunk(char *data, int size) +void HeapProfilerImpl::Frontend::AddHeapSnapshotChunk(char *data, int32_t size) { if (!AllowNotify()) { return; @@ -176,7 +176,7 @@ void HeapProfilerImpl::Frontend::AddHeapSnapshotChunk(char *data, int size) tooling::AddHeapSnapshotChunk addHeapSnapshotChunk; addHeapSnapshotChunk.GetChunk().resize(size); - for (int i = 0; i < size; ++i) { + for (int32_t i = 0; i < size; ++i) { addHeapSnapshotChunk.GetChunk()[i] = data[i]; } @@ -197,13 +197,13 @@ void HeapProfilerImpl::Frontend::ReportHeapSnapshotProgress(int32_t done, int32_ channel_->SendNotification(reportHeapSnapshotProgress); } -void HeapProfilerImpl::Frontend::HeapStatsUpdate(HeapStat* updateData, int count) +void HeapProfilerImpl::Frontend::HeapStatsUpdate(HeapStat* updateData, int32_t count) { if (!AllowNotify()) { return; } - std::vector statsDiff; - for (int i = 0; i < count; ++i) { + std::vector statsDiff; + for (int32_t i = 0; i < count; ++i) { statsDiff.emplace_back(updateData[i].index_); statsDiff.emplace_back(updateData[i].count_); statsDiff.emplace_back(updateData[i].size_); @@ -213,7 +213,7 @@ void HeapProfilerImpl::Frontend::HeapStatsUpdate(HeapStat* updateData, int count channel_->SendNotification(heapStatsUpdate); } -void HeapProfilerImpl::Frontend::LastSeenObjectId(uint32_t lastSeenObjectId) +void HeapProfilerImpl::Frontend::LastSeenObjectId(int32_t lastSeenObjectId) { if (!AllowNotify()) { return; diff --git a/ecmascript/tooling/agent/heapprofiler_impl.h b/ecmascript/tooling/agent/heapprofiler_impl.h index a5c2bc60c..e74e6241a 100644 --- a/ecmascript/tooling/agent/heapprofiler_impl.h +++ b/ecmascript/tooling/agent/heapprofiler_impl.h @@ -89,10 +89,10 @@ private: public: explicit Frontend(ProtocolChannel *channel) : channel_(channel) {} - void AddHeapSnapshotChunk(char *data, int size); + void AddHeapSnapshotChunk(char *data, int32_t size); void ReportHeapSnapshotProgress(int32_t done, int32_t total); - void HeapStatsUpdate(HeapStat* updateData, int count); - void LastSeenObjectId(uint32_t lastSeenObjectId); + void HeapStatsUpdate(HeapStat* updateData, int32_t count); + void LastSeenObjectId(int32_t lastSeenObjectId); void ResetProfiles(); private: @@ -112,7 +112,7 @@ private: static const int heapProfilerChunkSise = 102400; return heapProfilerChunkSise; } - bool WriteChunk(char *data, int size) override + bool WriteChunk(char *data, int32_t size) override { if (!Good()) { return false; @@ -125,7 +125,7 @@ private: return frontend_ != nullptr; } - void UpdateHeapStats(HeapStat* updateData, int count) override + void UpdateHeapStats(HeapStat* updateData, int32_t count) override { if (!Good()) { return; @@ -133,7 +133,7 @@ private: frontend_->HeapStatsUpdate(updateData, count); } - void UpdateLastSeenObjectId(uint32_t lastSeenObjectId) override + void UpdateLastSeenObjectId(int32_t lastSeenObjectId) override { if (!Good()) { return; diff --git a/ecmascript/tooling/base/pt_events.cpp b/ecmascript/tooling/base/pt_events.cpp index e22aa306d..4dffbd22e 100644 --- a/ecmascript/tooling/base/pt_events.cpp +++ b/ecmascript/tooling/base/pt_events.cpp @@ -86,6 +86,35 @@ Local Paused::ToObject(const EcmaVM *ecmaVm) const return object; } +std::unique_ptr Paused::ToJson() const +{ + std::unique_ptr result = PtJson::CreateObject(); + + std::unique_ptr array = PtJson::CreateArray(); + size_t len = callFrames_.size(); + for (size_t i = 0; i < len; i++) { + array->Push(callFrames_[i]->ToJson()); + } + result->Add("callFrames", array); + result->Add("reason", reason_.c_str()); + if (data_) { + result->Add("data", data_.value()->ToJson()); + } + if (hitBreakpoints_) { + std::unique_ptr breakpoints = PtJson::CreateArray(); + len = hitBreakpoints_->size(); + for (size_t i = 0; i < len; i++) { + array->Push(hitBreakpoints_.value()[i].c_str()); + } + } + + std::unique_ptr object = PtJson::CreateObject(); + object->Add("method", GetName().c_str()); + object->Add("params", result); + + return object; +} + Local Resumed::ToObject(const EcmaVM *ecmaVm) const { Local params = NewObject(ecmaVm); @@ -99,6 +128,17 @@ Local Resumed::ToObject(const EcmaVM *ecmaVm) const return object; } +std::unique_ptr Resumed::ToJson() const +{ + std::unique_ptr result = PtJson::CreateObject(); + + std::unique_ptr object = PtJson::CreateObject(); + object->Add("method", GetName().c_str()); + object->Add("params", result); + + return object; +} + Local ScriptFailedToParse::ToObject(const EcmaVM *ecmaVm) const { Local params = NewObject(ecmaVm); @@ -174,6 +214,47 @@ Local ScriptFailedToParse::ToObject(const EcmaVM *ecmaVm) const return object; } +std::unique_ptr ScriptFailedToParse::ToJson() const +{ + std::unique_ptr result = PtJson::CreateObject(); + + result->Add("scriptId", std::to_string(scriptId_).c_str()); + result->Add("url", url_.c_str()); + result->Add("startLine", startLine_); + result->Add("startColumn", startColumn_); + result->Add("endLine", endLine_); + result->Add("endColumn", endColumn_); + result->Add("executionContextId", executionContextId_); + result->Add("hash", hash_.c_str()); + if (sourceMapUrl_) { + result->Add("sourceMapURL", sourceMapUrl_->c_str()); + } + if (hasSourceUrl_) { + result->Add("hasSourceURL", hasSourceUrl_.value()); + } + if (isModule_) { + result->Add("isModule", isModule_.value()); + } + if (length_) { + result->Add("length", length_.value()); + } + if (codeOffset_) { + result->Add("codeOffset", codeOffset_.value()); + } + if (scriptLanguage_) { + result->Add("scriptLanguage", scriptLanguage_->c_str()); + } + if (embedderName_) { + result->Add("embedderName", embedderName_->c_str()); + } + + std::unique_ptr object = PtJson::CreateObject(); + object->Add("method", GetName().c_str()); + object->Add("params", result); + + return object; +} + Local ScriptParsed::ToObject(const EcmaVM *ecmaVm) const { Local params = NewObject(ecmaVm); @@ -253,6 +334,50 @@ Local ScriptParsed::ToObject(const EcmaVM *ecmaVm) const return object; } +std::unique_ptr ScriptParsed::ToJson() const +{ + std::unique_ptr result = PtJson::CreateObject(); + + result->Add("scriptId", std::to_string(scriptId_).c_str()); + result->Add("url", url_.c_str()); + result->Add("startLine", startLine_); + result->Add("startColumn", startColumn_); + result->Add("endLine", endLine_); + result->Add("endColumn", endColumn_); + result->Add("executionContextId", executionContextId_); + result->Add("hash", hash_.c_str()); + if (isLiveEdit_) { + result->Add("isLiveEdit", isLiveEdit_.value()); + } + if (sourceMapUrl_) { + result->Add("sourceMapURL", sourceMapUrl_->c_str()); + } + if (hasSourceUrl_) { + result->Add("hasSourceURL", hasSourceUrl_.value()); + } + if (isModule_) { + result->Add("isModule", isModule_.value()); + } + if (length_) { + result->Add("length", length_.value()); + } + if (codeOffset_) { + result->Add("codeOffset", codeOffset_.value()); + } + if (scriptLanguage_) { + result->Add("scriptLanguage", scriptLanguage_->c_str()); + } + if (embedderName_) { + result->Add("embedderName", embedderName_->c_str()); + } + + std::unique_ptr object = PtJson::CreateObject(); + object->Add("method", GetName().c_str()); + object->Add("params", result); + + return object; +} + Local AddHeapSnapshotChunk::ToObject(const EcmaVM *ecmaVm) const { Local params = NewObject(ecmaVm); @@ -270,6 +395,19 @@ Local AddHeapSnapshotChunk::ToObject(const EcmaVM *ecmaVm) const return object; } +std::unique_ptr AddHeapSnapshotChunk::ToJson() const +{ + std::unique_ptr result = PtJson::CreateObject(); + + result->Add("chunk", chunk_.c_str()); + + std::unique_ptr object = PtJson::CreateObject(); + object->Add("method", GetName().c_str()); + object->Add("params", result); + + return object; +} + Local ConsoleProfileFinished::ToObject(const EcmaVM *ecmaVm) const { Local params = NewObject(ecmaVm); @@ -298,6 +436,28 @@ Local ConsoleProfileFinished::ToObject(const EcmaVM *ecmaVm) const return object; } +std::unique_ptr ConsoleProfileFinished::ToJson() const +{ + std::unique_ptr result = PtJson::CreateObject(); + + result->Add("id", id_.c_str()); + if (location_ != nullptr) { + result->Add("location", location_->ToJson()); + } + if (profile_ != nullptr) { + result->Add("profile", profile_->ToJson()); + } + if (title_) { + result->Add("title", title_->c_str()); + } + + std::unique_ptr object = PtJson::CreateObject(); + object->Add("method", GetName().c_str()); + object->Add("params", result); + + return object; +} + Local ConsoleProfileStarted::ToObject(const EcmaVM *ecmaVm) const { Local params = NewObject(ecmaVm); @@ -323,6 +483,25 @@ Local ConsoleProfileStarted::ToObject(const EcmaVM *ecmaVm) const return object; } +std::unique_ptr ConsoleProfileStarted::ToJson() const +{ + std::unique_ptr result = PtJson::CreateObject(); + + result->Add("id", id_.c_str()); + if (location_ != nullptr) { + result->Add("location", location_->ToJson()); + } + if (title_) { + result->Add("title", title_->c_str()); + } + + std::unique_ptr object = PtJson::CreateObject(); + object->Add("method", GetName().c_str()); + object->Add("params", result); + + return object; +} + Local PreciseCoverageDeltaUpdate::ToObject(const EcmaVM *ecmaVm) const { Local params = NewObject(ecmaVm); @@ -349,6 +528,27 @@ Local PreciseCoverageDeltaUpdate::ToObject(const EcmaVM *ecmaVm) cons return object; } +std::unique_ptr PreciseCoverageDeltaUpdate::ToJson() const +{ + std::unique_ptr result = PtJson::CreateObject(); + + result->Add("timestamp", timestamp_); + result->Add("occasion", occasion_.c_str()); + std::unique_ptr array = PtJson::CreateArray(); + size_t len = result_.size(); + for (size_t i = 0; i < len; i++) { + std::unique_ptr res = result_[i]->ToJson(); + array->Push(res); + } + result->Add("result", array); + + std::unique_ptr object = PtJson::CreateObject(); + object->Add("method", GetName().c_str()); + object->Add("params", result); + + return object; +} + Local HeapStatsUpdate::ToObject(const EcmaVM *ecmaVm) const { Local params = NewObject(ecmaVm); @@ -370,6 +570,24 @@ Local HeapStatsUpdate::ToObject(const EcmaVM *ecmaVm) const return object; } +std::unique_ptr HeapStatsUpdate::ToJson() const +{ + std::unique_ptr result = PtJson::CreateObject(); + + std::unique_ptr array = PtJson::CreateArray(); + size_t len = statsUpdate_.size(); + for (size_t i = 0; i < len; i++) { + array->Push(statsUpdate_[i]); + } + result->Add("statsUpdate", array); + + std::unique_ptr object = PtJson::CreateObject(); + object->Add("method", GetName().c_str()); + object->Add("params", result); + + return object; +} + Local LastSeenObjectId::ToObject(const EcmaVM *ecmaVm) const { Local params = NewObject(ecmaVm); @@ -388,6 +606,20 @@ Local LastSeenObjectId::ToObject(const EcmaVM *ecmaVm) const return object; } +std::unique_ptr LastSeenObjectId::ToJson() const +{ + std::unique_ptr result = PtJson::CreateObject(); + + result->Add("lastSeenObjectId", lastSeenObjectId_); + result->Add("timestamp", timestamp_); + + std::unique_ptr object = PtJson::CreateObject(); + object->Add("method", GetName().c_str()); + object->Add("params", result); + + return object; +} + Local ReportHeapSnapshotProgress::ToObject(const EcmaVM *ecmaVm) const { Local params = NewObject(ecmaVm); @@ -411,4 +643,21 @@ Local ReportHeapSnapshotProgress::ToObject(const EcmaVM *ecmaVm) cons return object; } + +std::unique_ptr ReportHeapSnapshotProgress::ToJson() const +{ + std::unique_ptr result = PtJson::CreateObject(); + + result->Add("done", done_); + result->Add("total", total_); + if (finished_) { + result->Add("finished", finished_.value()); + } + + std::unique_ptr object = PtJson::CreateObject(); + object->Add("method", GetName().c_str()); + object->Add("params", result); + + return object; +} } // namespace panda::ecmascript::tooling diff --git a/ecmascript/tooling/base/pt_events.h b/ecmascript/tooling/base/pt_events.h index 5044ff875..8e9290524 100644 --- a/ecmascript/tooling/base/pt_events.h +++ b/ecmascript/tooling/base/pt_events.h @@ -84,6 +84,7 @@ public: Paused() = default; ~Paused() override = default; Local ToObject(const EcmaVM *ecmaVm) const override; + std::unique_ptr ToJson() const override; std::string GetName() const override { @@ -208,6 +209,7 @@ public: Resumed() = default; ~Resumed() override = default; Local ToObject(const EcmaVM *ecmaVm) const override; + std::unique_ptr ToJson() const override; std::string GetName() const override { @@ -224,6 +226,7 @@ public: ScriptFailedToParse() = default; ~ScriptFailedToParse() override = default; Local ToObject(const EcmaVM *ecmaVm) const override; + std::unique_ptr ToJson() const override; std::string GetName() const override { @@ -476,6 +479,7 @@ public: ScriptParsed() = default; ~ScriptParsed() override = default; Local ToObject(const EcmaVM *ecmaVm) const override; + std::unique_ptr ToJson() const override; std::string GetName() const override { @@ -651,12 +655,12 @@ public: return isModule_.has_value(); } - uint32_t GetLength() const + int32_t GetLength() const { return length_.value_or(0); } - ScriptParsed &SetLength(uint32_t length) + ScriptParsed &SetLength(int32_t length) { length_ = length; return *this; @@ -667,12 +671,12 @@ public: return length_.has_value(); } - uint32_t GetCodeOffset() const + int32_t GetCodeOffset() const { return codeOffset_.value_or(0); } - ScriptParsed &SetCodeOffset(uint32_t codeOffset) + ScriptParsed &SetCodeOffset(int32_t codeOffset) { codeOffset_ = codeOffset; return *this; @@ -734,8 +738,8 @@ private: std::optional sourceMapUrl_ {}; std::optional hasSourceUrl_ {}; std::optional isModule_ {}; - std::optional length_ {}; - std::optional codeOffset_ {}; + std::optional length_ {}; + std::optional codeOffset_ {}; std::optional scriptLanguage_ {}; std::optional embedderName_ {}; }; @@ -745,6 +749,7 @@ public: AddHeapSnapshotChunk() = default; ~AddHeapSnapshotChunk() override = default; Local ToObject(const EcmaVM *ecmaVm) const override; + std::unique_ptr ToJson() const override; std::string GetName() const override { @@ -768,6 +773,7 @@ public: ConsoleProfileFinished() = default; ~ConsoleProfileFinished() override = default; Local ToObject(const EcmaVM *ecmaVm) const override; + std::unique_ptr ToJson() const override; std::string GetName() const override { return "Profile.ConsoleProfileFinished"; @@ -838,6 +844,7 @@ public: ConsoleProfileStarted() = default; ~ConsoleProfileStarted() override = default; Local ToObject(const EcmaVM *ecmaVm) const override; + std::unique_ptr ToJson() const override; std::string GetName() const override { return "Profile.ConsoleProfileStarted"; @@ -896,6 +903,7 @@ public: PreciseCoverageDeltaUpdate() = default; ~PreciseCoverageDeltaUpdate() override = default; Local ToObject(const EcmaVM *ecmaVm) const override; + std::unique_ptr ToJson() const override; std::string GetName() const override { return "Profile.PreciseCoverageDeltaUpdate"; @@ -948,18 +956,19 @@ public: HeapStatsUpdate() = default; ~HeapStatsUpdate() override = default; Local ToObject(const EcmaVM *ecmaVm) const override; + std::unique_ptr ToJson() const override; std::string GetName() const override { return "HeapProfiler.heapStatsUpdate"; } - const std::vector *GetStatsUpdate() const + const std::vector *GetStatsUpdate() const { return &statsUpdate_; } - HeapStatsUpdate &SetStatsUpdate(std::vector statsUpdate) + HeapStatsUpdate &SetStatsUpdate(std::vector statsUpdate) { statsUpdate_ = std::move(statsUpdate); return *this; @@ -969,7 +978,7 @@ private: NO_COPY_SEMANTIC(HeapStatsUpdate); NO_MOVE_SEMANTIC(HeapStatsUpdate); - std::vector statsUpdate_ {}; + std::vector statsUpdate_ {}; }; class LastSeenObjectId final : public PtBaseEvents { @@ -977,6 +986,7 @@ public: LastSeenObjectId() = default; ~LastSeenObjectId() override = default; Local ToObject(const EcmaVM *ecmaVm) const override; + std::unique_ptr ToJson() const override; std::string GetName() const override { @@ -988,7 +998,7 @@ public: return lastSeenObjectId_; } - LastSeenObjectId &SetLastSeenObjectId(uint32_t lastSeenObjectId) + LastSeenObjectId &SetLastSeenObjectId(int32_t lastSeenObjectId) { lastSeenObjectId_ = lastSeenObjectId; return *this; @@ -1009,7 +1019,7 @@ private: NO_COPY_SEMANTIC(LastSeenObjectId); NO_MOVE_SEMANTIC(LastSeenObjectId); - uint32_t lastSeenObjectId_ {}; + int32_t lastSeenObjectId_ {}; int64_t timestamp_ {}; }; @@ -1018,6 +1028,7 @@ public: ReportHeapSnapshotProgress() = default; ~ReportHeapSnapshotProgress() override = default; Local ToObject(const EcmaVM *ecmaVm) const override; + std::unique_ptr ToJson() const override; std::string GetName() const override { diff --git a/ecmascript/tooling/base/pt_params.cpp b/ecmascript/tooling/base/pt_params.cpp index 1ebfe9e3c..35fff8e17 100644 --- a/ecmascript/tooling/base/pt_params.cpp +++ b/ecmascript/tooling/base/pt_params.cpp @@ -257,7 +257,7 @@ std::unique_ptr SetBlackboxPatternsParams::Create(con if (item->IsString()) { paramsObject->patterns_.emplace_back(item->GetString()); } else { - error += "'patterns' items should be a String;"; + error += "'patterns' items should be a String;"; } } } else { diff --git a/ecmascript/tooling/base/pt_returns.cpp b/ecmascript/tooling/base/pt_returns.cpp index e3b36fb45..bba89d4e0 100644 --- a/ecmascript/tooling/base/pt_returns.cpp +++ b/ecmascript/tooling/base/pt_returns.cpp @@ -54,6 +54,22 @@ Local SetBreakpointByUrlReturns::ToObject(const EcmaVM *ecmaVm) const return result; } +std::unique_ptr SetBreakpointByUrlReturns::ToJson() const +{ + std::unique_ptr result = PtJson::CreateObject(); + + result->Add("breakpointId", id_.c_str()); + std::unique_ptr array = PtJson::CreateArray(); + size_t len = locations_.size(); + for (size_t i = 0; i < len; i++) { + std::unique_ptr location = locations_[i]->ToJson(); + array->Push(location); + } + result->Add("locations", array); + + return result; +} + Local EvaluateOnCallFrameReturns::ToObject(const EcmaVM *ecmaVm) const { Local result = NewObject(ecmaVm); @@ -70,6 +86,20 @@ Local EvaluateOnCallFrameReturns::ToObject(const EcmaVM *ecmaVm) cons return result; } +std::unique_ptr EvaluateOnCallFrameReturns::ToJson() const +{ + std::unique_ptr result = PtJson::CreateObject(); + + if (result_ != nullptr) { + result->Add("result", result_->ToJson()); + } + if (exceptionDetails_ && exceptionDetails_.value() != nullptr) { + result->Add("exceptionDetails", exceptionDetails_.value()->ToJson()); + } + + return result; +} + Local GetPossibleBreakpointsReturns::ToObject(const EcmaVM *ecmaVm) const { size_t len = locations_.size(); @@ -85,6 +115,21 @@ Local GetPossibleBreakpointsReturns::ToObject(const EcmaVM *ecmaVm) c return result; } +std::unique_ptr GetPossibleBreakpointsReturns::ToJson() const +{ + std::unique_ptr result = PtJson::CreateObject(); + + std::unique_ptr array = PtJson::CreateArray(); + size_t len = locations_.size(); + for (size_t i = 0; i < len; i++) { + std::unique_ptr location = locations_[i]->ToJson(); + array->Push(location); + } + result->Add("locations", array); + + return result; +} + Local GetScriptSourceReturns::ToObject(const EcmaVM *ecmaVm) const { Local result = NewObject(ecmaVm); @@ -101,6 +146,18 @@ Local GetScriptSourceReturns::ToObject(const EcmaVM *ecmaVm) const return result; } +std::unique_ptr GetScriptSourceReturns::ToJson() const +{ + std::unique_ptr result = PtJson::CreateObject(); + + result->Add("scriptSource", scriptSource_.c_str()); + if (bytecode_) { + result->Add("bytecode", bytecode_->c_str()); + } + + return result; +} + Local RestartFrameReturns::ToObject(const EcmaVM *ecmaVm) const { size_t len = callFrames_.size(); @@ -115,13 +172,28 @@ Local RestartFrameReturns::ToObject(const EcmaVM *ecmaVm) const return result; } +std::unique_ptr RestartFrameReturns::ToJson() const +{ + std::unique_ptr result = PtJson::CreateObject(); + + std::unique_ptr array = PtJson::CreateArray(); + size_t len = callFrames_.size(); + for (size_t i = 0; i < len; i++) { + std::unique_ptr location = callFrames_[i]->ToJson(); + array->Push(location); + } + result->Add("callFrames", array); + + return result; +} + Local SearchInContentReturns::ToObject(const EcmaVM *ecmaVm) const { size_t len = result_.size(); Local values = ArrayRef::New(ecmaVm, len); for (size_t i = 0; i < len; i++) { - Local location = result_[i]->ToObject(ecmaVm); - values->Set(ecmaVm, i, location); + Local res = result_[i]->ToObject(ecmaVm); + values->Set(ecmaVm, i, res); } Local result = NewObject(ecmaVm); @@ -130,6 +202,21 @@ Local SearchInContentReturns::ToObject(const EcmaVM *ecmaVm) const return result; } +std::unique_ptr SearchInContentReturns::ToJson() const +{ + std::unique_ptr result = PtJson::CreateObject(); + + std::unique_ptr array = PtJson::CreateArray(); + size_t len = result_.size(); + for (size_t i = 0; i < len; i++) { + std::unique_ptr res = result_[i]->ToJson(); + array->Push(res); + } + result->Add("result", array); + + return result; +} + Local SetBreakpointReturns::ToObject(const EcmaVM *ecmaVm) const { Local result = NewObject(ecmaVm); @@ -145,6 +232,18 @@ Local SetBreakpointReturns::ToObject(const EcmaVM *ecmaVm) const return result; } +std::unique_ptr SetBreakpointReturns::ToJson() const +{ + std::unique_ptr result = PtJson::CreateObject(); + + result->Add("breakpointId", breakpointId_.c_str()); + if (location_ != nullptr) { + result->Add("actualLocation", location_->ToJson()); + } + + return result; +} + Local SetInstrumentationBreakpointReturns::ToObject(const EcmaVM *ecmaVm) const { Local result = NewObject(ecmaVm); @@ -156,6 +255,15 @@ Local SetInstrumentationBreakpointReturns::ToObject(const EcmaVM *ecm return result; } +std::unique_ptr SetInstrumentationBreakpointReturns::ToJson() const +{ + std::unique_ptr result = PtJson::CreateObject(); + + result->Add("breakpointId", breakpointId_.c_str()); + + return result; +} + Local SetScriptSourceReturns::ToObject(const EcmaVM *ecmaVm) const { Local result = NewObject(ecmaVm); @@ -186,6 +294,29 @@ Local SetScriptSourceReturns::ToObject(const EcmaVM *ecmaVm) const return result; } +std::unique_ptr SetScriptSourceReturns::ToJson() const +{ + std::unique_ptr result = PtJson::CreateObject(); + + if (callFrames_) { + std::unique_ptr array = PtJson::CreateArray(); + size_t len = callFrames_->size(); + for (size_t i = 0; i < len; i++) { + std::unique_ptr location = callFrames_.value()[i]->ToJson(); + array->Push(location); + } + result->Add("callFrames", array); + } + if (stackChanged_) { + result->Add("stackChanged", stackChanged_.value()); + } + if (exceptionDetails_ && exceptionDetails_.value() != nullptr) { + result->Add("exceptionDetails", exceptionDetails_.value()->ToJson()); + } + + return result; +} + Local GetPropertiesReturns::ToObject(const EcmaVM *ecmaVm) const { Local result = NewObject(ecmaVm); @@ -226,6 +357,42 @@ Local GetPropertiesReturns::ToObject(const EcmaVM *ecmaVm) const return result; } +std::unique_ptr GetPropertiesReturns::ToJson() const +{ + std::unique_ptr result = PtJson::CreateObject(); + + std::unique_ptr array = PtJson::CreateArray(); + size_t len = result_.size(); + for (size_t i = 0; i < len; i++) { + std::unique_ptr location = result_[i]->ToJson(); + array->Push(location); + } + result->Add("result", array); + if (internalPropertyDescripties_) { + array = PtJson::CreateArray(); + len = internalPropertyDescripties_->size(); + for (size_t i = 0; i < len; i++) { + std::unique_ptr location = internalPropertyDescripties_.value()[i]->ToJson(); + array->Push(location); + } + result->Add("internalProperties", array); + } + if (privateProperties_) { + array = PtJson::CreateArray(); + len = privateProperties_->size(); + for (size_t i = 0; i < len; i++) { + std::unique_ptr location = privateProperties_.value()[i]->ToJson(); + array->Push(location); + } + result->Add("privateProperties", array); + } + if (exceptionDetails_ && exceptionDetails_.value() != nullptr) { + result->Add("exceptionDetails", exceptionDetails_.value()->ToJson()); + } + + return result; +} + Local CallFunctionOnReturns::ToObject(const EcmaVM *ecmaVm) const { // For this @@ -244,6 +411,20 @@ Local CallFunctionOnReturns::ToObject(const EcmaVM *ecmaVm) const return returns; } +std::unique_ptr CallFunctionOnReturns::ToJson() const +{ + std::unique_ptr result = PtJson::CreateObject(); + + if (result_ != nullptr) { + result->Add("result", result_->ToJson()); + } + if (exceptionDetails_ && exceptionDetails_.value() != nullptr) { + result->Add("exceptionDetails", exceptionDetails_.value()->ToJson()); + } + + return result; +} + Local StopSamplingReturns::ToObject(const EcmaVM *ecmaVm) const { Local result = NewObject(ecmaVm); @@ -256,6 +437,17 @@ Local StopSamplingReturns::ToObject(const EcmaVM *ecmaVm) const return result; } +std::unique_ptr StopSamplingReturns::ToJson() const +{ + std::unique_ptr result = PtJson::CreateObject(); + + if (profile_ != nullptr) { + result->Add("profile", profile_->ToJson()); + } + + return result; +} + Local GetHeapObjectIdReturns::ToObject(const EcmaVM *ecmaVm) const { Local result = NewObject(ecmaVm); @@ -267,6 +459,15 @@ Local GetHeapObjectIdReturns::ToObject(const EcmaVM *ecmaVm) const return result; } +std::unique_ptr GetHeapObjectIdReturns::ToJson() const +{ + std::unique_ptr result = PtJson::CreateObject(); + + result->Add("heapSnapshotObjectId", std::to_string(heapSnapshotObjectId_).c_str()); + + return result; +} + Local GetObjectByHeapObjectIdReturns::ToObject(const EcmaVM *ecmaVm) const { Local result = NewObject(ecmaVm); @@ -280,6 +481,17 @@ Local GetObjectByHeapObjectIdReturns::ToObject(const EcmaVM *ecmaVm) return result; } +std::unique_ptr GetObjectByHeapObjectIdReturns::ToJson() const +{ + std::unique_ptr result = PtJson::CreateObject(); + + if (remoteObjectResult_ != nullptr) { + result->Add("result", remoteObjectResult_->ToJson()); + } + + return result; +} + Local StopReturns::ToObject(const EcmaVM *ecmaVm) const { Local result = NewObject(ecmaVm); @@ -290,6 +502,17 @@ Local StopReturns::ToObject(const EcmaVM *ecmaVm) const return result; } +std::unique_ptr StopReturns::ToJson() const +{ + std::unique_ptr result = PtJson::CreateObject(); + + if (profile_ != nullptr) { + result->Add("profile", profile_->ToJson()); + } + + return result; +} + Local GetHeapUsageReturns::ToObject(const EcmaVM *ecmaVm) const { Local result = NewObject(ecmaVm); @@ -304,6 +527,16 @@ Local GetHeapUsageReturns::ToObject(const EcmaVM *ecmaVm) const return result; } +std::unique_ptr GetHeapUsageReturns::ToJson() const +{ + std::unique_ptr result = PtJson::CreateObject(); + + result->Add("usedSize", usedSize_); + result->Add("totalSize", totalSize_); + + return result; +} + Local GetBestEffortCoverageReturns::ToObject(const EcmaVM *ecmaVm) const { Local result = NewObject(ecmaVm); @@ -319,6 +552,21 @@ Local GetBestEffortCoverageReturns::ToObject(const EcmaVM *ecmaVm) co return result; } +std::unique_ptr GetBestEffortCoverageReturns::ToJson() const +{ + std::unique_ptr result = PtJson::CreateObject(); + + std::unique_ptr array = PtJson::CreateArray(); + size_t len = result_.size(); + for (size_t i = 0; i < len; i++) { + std::unique_ptr scriptCoverage = result_[i]->ToJson(); + array->Push(scriptCoverage); + } + result->Add("result", array); + + return result; +} + Local StartPreciseCoverageReturns::ToObject(const EcmaVM *ecmaVm) const { Local result = NewObject(ecmaVm); @@ -328,6 +576,15 @@ Local StartPreciseCoverageReturns::ToObject(const EcmaVM *ecmaVm) con return result; } +std::unique_ptr StartPreciseCoverageReturns::ToJson() const +{ + std::unique_ptr result = PtJson::CreateObject(); + + result->Add("timestamp", timestamp_); + + return result; +} + Local TakePreciseCoverageReturns::ToObject(const EcmaVM *ecmaVm) const { Local returns = NewObject(ecmaVm); @@ -339,15 +596,29 @@ Local TakePreciseCoverageReturns::ToObject(const EcmaVM *ecmaVm) cons values->Set(ecmaVm, i, scriptCoverage); } returns->Set(ecmaVm, Local(StringRef::NewFromUtf8(ecmaVm, "result")), values); - if (timestamp_) { - returns->Set(ecmaVm, Local(StringRef::NewFromUtf8(ecmaVm, "timestamp")), - NumberRef::New(ecmaVm, timestamp_)); - } + returns->Set(ecmaVm, Local(StringRef::NewFromUtf8(ecmaVm, "timestamp")), + NumberRef::New(ecmaVm, timestamp_)); return returns; } -Local TakeTypeProfileturns::ToObject(const EcmaVM *ecmaVm) const +std::unique_ptr TakePreciseCoverageReturns::ToJson() const +{ + std::unique_ptr result = PtJson::CreateObject(); + + std::unique_ptr array = PtJson::CreateArray(); + size_t len = result_.size(); + for (size_t i = 0; i < len; i++) { + std::unique_ptr scriptTypeProfile = result_[i]->ToJson(); + array->Push(scriptTypeProfile); + } + result->Add("result", array); + result->Add("timestamp", timestamp_); + + return result; +} + +Local TakeTypeProfileReturns::ToObject(const EcmaVM *ecmaVm) const { Local result = NewObject(ecmaVm); @@ -360,4 +631,19 @@ Local TakeTypeProfileturns::ToObject(const EcmaVM *ecmaVm) const result->Set(ecmaVm, Local(StringRef::NewFromUtf8(ecmaVm, "result")), values); return result; } + +std::unique_ptr TakeTypeProfileReturns::ToJson() const +{ + std::unique_ptr result = PtJson::CreateObject(); + + std::unique_ptr array = PtJson::CreateArray(); + size_t len = result_.size(); + for (size_t i = 0; i < len; i++) { + std::unique_ptr scriptTypeProfile = result_[i]->ToJson(); + array->Push(scriptTypeProfile); + } + result->Add("result", array); + + return result; +} } // namespace panda::ecmascript::tooling \ No newline at end of file diff --git a/ecmascript/tooling/base/pt_returns.h b/ecmascript/tooling/base/pt_returns.h index 69231a6c1..6c46925da 100644 --- a/ecmascript/tooling/base/pt_returns.h +++ b/ecmascript/tooling/base/pt_returns.h @@ -62,6 +62,7 @@ public: ~SetBreakpointByUrlReturns() override = default; Local ToObject(const EcmaVM *ecmaVm) const override; + std::unique_ptr ToJson() const override; private: SetBreakpointByUrlReturns() = default; @@ -80,6 +81,7 @@ public: {} ~EvaluateOnCallFrameReturns() override = default; Local ToObject(const EcmaVM *ecmaVm) const override; + std::unique_ptr ToJson() const override; private: EvaluateOnCallFrameReturns() = default; @@ -98,6 +100,7 @@ public: ~GetPossibleBreakpointsReturns() override = default; Local ToObject(const EcmaVM *ecmaVm) const override; + std::unique_ptr ToJson() const override; private: GetPossibleBreakpointsReturns() = default; @@ -115,6 +118,7 @@ public: ~GetScriptSourceReturns() override = default; Local ToObject(const EcmaVM *ecmaVm) const override; + std::unique_ptr ToJson() const override; private: GetScriptSourceReturns() = default; @@ -132,6 +136,7 @@ public: {} ~RestartFrameReturns() override = default; Local ToObject(const EcmaVM *ecmaVm) const override; + std::unique_ptr ToJson() const override; private: RestartFrameReturns() = default; @@ -147,6 +152,7 @@ public: {} ~SearchInContentReturns() override = default; Local ToObject(const EcmaVM *ecmaVm) const override; + std::unique_ptr ToJson() const override; private: SearchInContentReturns() = default; @@ -163,6 +169,7 @@ public: {} ~SetBreakpointReturns() override = default; Local ToObject(const EcmaVM *ecmaVm) const override; + std::unique_ptr ToJson() const override; private: SetBreakpointReturns() = default; @@ -178,6 +185,7 @@ public: {} ~SetInstrumentationBreakpointReturns() override = default; Local ToObject(const EcmaVM *ecmaVm) const override; + std::unique_ptr ToJson() const override; private: SetInstrumentationBreakpointReturns() = default; @@ -198,6 +206,7 @@ public: {} ~SetScriptSourceReturns() override = default; Local ToObject(const EcmaVM *ecmaVm) const override; + std::unique_ptr ToJson() const override; private: SetScriptSourceReturns() = default; @@ -222,6 +231,7 @@ public: {} ~GetPropertiesReturns() override = default; Local ToObject(const EcmaVM *ecmaVm) const override; + std::unique_ptr ToJson() const override; private: GetPropertiesReturns() = default; @@ -243,6 +253,7 @@ public: {} ~CallFunctionOnReturns() override = default; Local ToObject(const EcmaVM *ecmaVm) const override; + std::unique_ptr ToJson() const override; private: CallFunctionOnReturns() = default; @@ -261,6 +272,7 @@ public: ~StopSamplingReturns() override = default; Local ToObject(const EcmaVM *ecmaVm) const override; + std::unique_ptr ToJson() const override; private: StopSamplingReturns() = default; @@ -278,6 +290,7 @@ public: ~GetHeapObjectIdReturns() override = default; Local ToObject(const EcmaVM *ecmaVm) const override; + std::unique_ptr ToJson() const override; private: GetHeapObjectIdReturns() = default; @@ -295,6 +308,7 @@ public: ~GetObjectByHeapObjectIdReturns() override = default; Local ToObject(const EcmaVM *ecmaVm) const override; + std::unique_ptr ToJson() const override; private: GetObjectByHeapObjectIdReturns() = default; @@ -309,6 +323,7 @@ public: explicit StopReturns(std::unique_ptr profile) : profile_(std::move(profile)) {} ~StopReturns() override = default; Local ToObject(const EcmaVM *ecmaVm) const override; + std::unique_ptr ToJson() const override; private: StopReturns() = default; @@ -324,6 +339,7 @@ public: : usedSize_(usedSize), totalSize_(totalSize) {} ~GetHeapUsageReturns() override = default; Local ToObject(const EcmaVM *ecmaVm) const override; + std::unique_ptr ToJson() const override; private: GetHeapUsageReturns() = default; @@ -341,6 +357,7 @@ public: {} ~GetBestEffortCoverageReturns() override = default; Local ToObject(const EcmaVM *ecmaVm) const override; + std::unique_ptr ToJson() const override; private: GetBestEffortCoverageReturns() = default; @@ -355,6 +372,7 @@ public: explicit StartPreciseCoverageReturns(int64_t tamp) : timestamp_(tamp) {} ~StartPreciseCoverageReturns() override = default; Local ToObject(const EcmaVM *ecmaVm) const override; + std::unique_ptr ToJson() const override; private: StartPreciseCoverageReturns() = default; @@ -372,6 +390,7 @@ public: {} ~TakePreciseCoverageReturns() override = default; Local ToObject(const EcmaVM *ecmaVm) const override; + std::unique_ptr ToJson() const override; private: TakePreciseCoverageReturns() = default; @@ -382,18 +401,19 @@ private: int64_t timestamp_ {0}; }; -class TakeTypeProfileturns : public PtBaseReturns { +class TakeTypeProfileReturns : public PtBaseReturns { public: - explicit TakeTypeProfileturns(std::vector> result) + explicit TakeTypeProfileReturns(std::vector> result) : result_(std::move(result)) {} - ~TakeTypeProfileturns() override = default; + ~TakeTypeProfileReturns() override = default; Local ToObject(const EcmaVM *ecmaVm) const override; + std::unique_ptr ToJson() const override; private: - TakeTypeProfileturns() = default; - NO_COPY_SEMANTIC(TakeTypeProfileturns); - NO_MOVE_SEMANTIC(TakeTypeProfileturns); + TakeTypeProfileReturns() = default; + NO_COPY_SEMANTIC(TakeTypeProfileReturns); + NO_MOVE_SEMANTIC(TakeTypeProfileReturns); std::vector> result_ {}; }; diff --git a/ecmascript/tooling/interface/file_stream.cpp b/ecmascript/tooling/interface/file_stream.cpp index 6c02144bd..48bc240fc 100644 --- a/ecmascript/tooling/interface/file_stream.cpp +++ b/ecmascript/tooling/interface/file_stream.cpp @@ -69,7 +69,7 @@ std::pair FileStream::FilePathValid(const std::string &fileNa } // Writes the chunk of data into the stream -bool FileStream::WriteChunk(char *data, int size) +bool FileStream::WriteChunk(char *data, int32_t size) { if (fileStream_.fail()) { return false; @@ -77,7 +77,7 @@ bool FileStream::WriteChunk(char *data, int size) std::string str; str.resize(size); - for (int i = 0; i < size; ++i) { + for (int32_t i = 0; i < size; ++i) { str[i] = data[i]; } @@ -99,7 +99,7 @@ bool FileDescriptorStream::Good() } // Writes the chunk of data into the stream -bool FileDescriptorStream::WriteChunk(char *data, int size) +bool FileDescriptorStream::WriteChunk(char *data, int32_t size) { if (fd_ < 0) { return false; @@ -107,7 +107,7 @@ bool FileDescriptorStream::WriteChunk(char *data, int size) std::string str; str.resize(size); - for (int i = 0; i < size; ++i) { + for (int32_t i = 0; i < size; ++i) { str[i] = data[i]; } int ret = dprintf(fd_, "%s", str.c_str()); diff --git a/ecmascript/tooling/interface/file_stream.h b/ecmascript/tooling/interface/file_stream.h index 0f57f8f07..eba3c3e8e 100644 --- a/ecmascript/tooling/interface/file_stream.h +++ b/ecmascript/tooling/interface/file_stream.h @@ -36,12 +36,12 @@ public: } // Writes the chunk of data into the stream - bool WriteChunk(char* data, int size) override; + bool WriteChunk(char* data, int32_t size) override; bool Good() override; - void UpdateHeapStats([[maybe_unused]]HeapStat* data, [[maybe_unused]]int count) override + void UpdateHeapStats([[maybe_unused]] HeapStat* data, [[maybe_unused]] int32_t count) override { } - void UpdateLastSeenObjectId([[maybe_unused]]uint32_t lastSeenObjectId) override + void UpdateLastSeenObjectId([[maybe_unused]] int32_t lastSeenObjectId) override { } @@ -67,12 +67,12 @@ public: } // Writes the chunk of data into the stream - bool WriteChunk(char *data, int size) override; + bool WriteChunk(char *data, int32_t size) override; bool Good() override; - void UpdateHeapStats([[maybe_unused]]HeapStat* data, [[maybe_unused]]int count) override + void UpdateHeapStats([[maybe_unused]] HeapStat* data, [[maybe_unused]] int32_t count) override { } - void UpdateLastSeenObjectId([[maybe_unused]]uint32_t lastSeenObjectId) override + void UpdateLastSeenObjectId([[maybe_unused]] int32_t lastSeenObjectId) override { } diff --git a/ecmascript/tooling/interface/stream.h b/ecmascript/tooling/interface/stream.h index 771895c3e..cd7285b65 100644 --- a/ecmascript/tooling/interface/stream.h +++ b/ecmascript/tooling/interface/stream.h @@ -19,12 +19,12 @@ namespace panda::ecmascript { class HeapStat { public: - HeapStat(uint32_t index, uint32_t count, uint32_t size) + HeapStat(int32_t index, int32_t count, int32_t size) : index_(index), count_(count), size_(size) {} - uint32_t index_; - uint32_t count_; - uint32_t size_; + int32_t index_; + int32_t count_; + int32_t size_; }; class Stream { @@ -37,10 +37,10 @@ public: virtual int GetSize() = 0; // Writes the chunk of data into the stream - virtual bool WriteChunk(char *data, int size) = 0; + virtual bool WriteChunk(char *data, int32_t size) = 0; virtual bool Good() = 0; - virtual void UpdateHeapStats(HeapStat* data, int count) = 0; - virtual void UpdateLastSeenObjectId(uint32_t lastSeenObjectId) = 0; + virtual void UpdateHeapStats(HeapStat* data, int32_t count) = 0; + virtual void UpdateLastSeenObjectId(int32_t lastSeenObjectId) = 0; }; } // namespace panda::ecmascript diff --git a/ecmascript/tooling/test/debugger_events_test.cpp b/ecmascript/tooling/test/debugger_events_test.cpp index 175420a99..ff1f8e93b 100644 --- a/ecmascript/tooling/test/debugger_events_test.cpp +++ b/ecmascript/tooling/test/debugger_events_test.cpp @@ -527,7 +527,7 @@ HWTEST_F_L0(DebuggerEventsTest, HeapStatsUpdateToObjectTest) HeapStatsUpdate heapStatsUpdate; Local tmpStr = StringRef::NewFromUtf8(ecmaVm, "params"); - heapStatsUpdate.SetStatsUpdate(std::vector {}); + heapStatsUpdate.SetStatsUpdate(std::vector {}); Local object1 = heapStatsUpdate.ToObject(ecmaVm); Local result = object1->Get(ecmaVm, tmpStr); ASSERT_TRUE(!result.IsEmpty() && !result->IsUndefined()); diff --git a/ecmascript/tooling/test/debugger_returns_test.cpp b/ecmascript/tooling/test/debugger_returns_test.cpp index 1d60edf8e..04cfa21dc 100644 --- a/ecmascript/tooling/test/debugger_returns_test.cpp +++ b/ecmascript/tooling/test/debugger_returns_test.cpp @@ -372,8 +372,8 @@ HWTEST_F_L0(DebuggerReturnsTest, TakeTypeProfileturnsToObjectTest) { auto result = std::vector>(); std::unique_ptr scriptTypeProfile = std::make_unique(); - std::unique_ptr takeTypeProfileturns = std::make_unique - (std::move(result)); + std::unique_ptr takeTypeProfileturns = std::make_unique + (std::move(result)); Local getObject = takeTypeProfileturns->ToObject(ecmaVm); Local tmpStr = StringRef::NewFromUtf8(ecmaVm, "result"); ASSERT_TRUE(getObject->Has(ecmaVm, tmpStr)); -- Gitee