Files
ark_js_runtime/ecmascript/tooling/agent/runtime_impl.cpp
T
zhangyukun 7ffcc4b20f Sync js_runtime to openharmony
Signed-off-by: zhangyukun <zhangyukun8@huawei.com>
2021-09-08 09:20:53 +08:00

99 lines
4.0 KiB
C++

/*
* Copyright (c) 2021 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "ecmascript/tooling/agent/runtime_impl.h"
#include "ecmascript/tooling/base/pt_returns.h"
#include "libpandabase/utils/logger.h"
namespace panda::tooling::ecmascript {
RuntimeImpl::DispatcherImpl::DispatcherImpl(FrontEnd *frontend, std::unique_ptr<RuntimeImpl> runtime)
: DispatcherBase(frontend), runtime_(std::move(runtime))
{
dispatcherTable_["enable"] = &RuntimeImpl::DispatcherImpl::Enable;
dispatcherTable_["getProperties"] = &RuntimeImpl::DispatcherImpl::GetProperties;
dispatcherTable_["runIfWaitingForDebugger"] = &RuntimeImpl::DispatcherImpl::RunIfWaitingForDebugger;
}
void RuntimeImpl::DispatcherImpl::Dispatch(const DispatchRequest &request)
{
CString method = request.GetMethod();
LOG(DEBUG, DEBUGGER) << "dispatch [" << method << "] to RuntimeImpl";
auto entry = dispatcherTable_.find(method);
if (entry != dispatcherTable_.end()) {
(this->*(entry->second))(request);
} else {
LOG(ERROR, DEBUGGER) << "unknown method: " << method;
SendResponse(request, DispatchResponse::Fail("unknown method: " + method), nullptr);
}
}
void RuntimeImpl::DispatcherImpl::Enable(const DispatchRequest &request)
{
DispatchResponse response = runtime_->Enable();
SendResponse(request, response, nullptr);
}
void RuntimeImpl::DispatcherImpl::RunIfWaitingForDebugger(const DispatchRequest &request)
{
DispatchResponse response = runtime_->RunIfWaitingForDebugger();
SendResponse(request, response, nullptr);
}
void RuntimeImpl::DispatcherImpl::GetProperties(const DispatchRequest &request)
{
std::unique_ptr<GetPropertiesParams> params = GetPropertiesParams::Create(request.GetEcmaVM(), request.GetParams());
CVector<std::unique_ptr<PropertyDescriptor>> outPropertyDesc;
std::optional<CVector<std::unique_ptr<InternalPropertyDescriptor>>> outInternalDescs;
std::optional<CVector<std::unique_ptr<PrivatePropertyDescriptor>>> outPrivateProperties;
std::optional<std::unique_ptr<ExceptionDetails>> outExceptionDetails;
DispatchResponse response = runtime_->GetProperties(std::move(params), &outPropertyDesc, &outInternalDescs,
&outPrivateProperties, &outExceptionDetails);
if (outExceptionDetails) {
LOG(WARNING, DEBUGGER) << "GetProperties thrown an exception";
}
std::unique_ptr<GetPropertiesReturns> result = std::make_unique<GetPropertiesReturns>(std::move(outPropertyDesc),
std::move(outInternalDescs),
std::move(outPrivateProperties),
std::move(outExceptionDetails));
SendResponse(request, response, std::move(result));
}
DispatchResponse RuntimeImpl::Enable()
{
return DispatchResponse::Ok();
}
DispatchResponse RuntimeImpl::RunIfWaitingForDebugger()
{
return DispatchResponse::Create(backend_->Resume());
}
DispatchResponse RuntimeImpl::GetProperties(std::unique_ptr<GetPropertiesParams> params,
CVector<std::unique_ptr<PropertyDescriptor>> *outPropertyDesc,
[[maybe_unused]] std::optional<CVector<std::unique_ptr<InternalPropertyDescriptor>>> *outInternalDescs,
[[maybe_unused]] std::optional<CVector<std::unique_ptr<PrivatePropertyDescriptor>>> *outPrivateProps,
[[maybe_unused]] std::optional<std::unique_ptr<ExceptionDetails>> *outExceptionDetails)
{
backend_->GetProperties(DebuggerApi::CStringToULL(params->GetObjectId()),
params->GetOwnProperties(),
params->GetAccessPropertiesOnly(),
outPropertyDesc);
return DispatchResponse::Ok();
}
} // namespace panda::tooling::ecmascript