1e509ee18Sopenharmony_ci/*
2e509ee18Sopenharmony_ci * Copyright (c) 2021 Huawei Device Co., Ltd.
3e509ee18Sopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License");
4e509ee18Sopenharmony_ci * you may not use this file except in compliance with the License.
5e509ee18Sopenharmony_ci * You may obtain a copy of the License at
6e509ee18Sopenharmony_ci *
7e509ee18Sopenharmony_ci *     http://www.apache.org/licenses/LICENSE-2.0
8e509ee18Sopenharmony_ci *
9e509ee18Sopenharmony_ci * Unless required by applicable law or agreed to in writing, software
10e509ee18Sopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS,
11e509ee18Sopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12e509ee18Sopenharmony_ci * See the License for the specific language governing permissions and
13e509ee18Sopenharmony_ci * limitations under the License.
14e509ee18Sopenharmony_ci */
15e509ee18Sopenharmony_ci
16e509ee18Sopenharmony_ci#include "tooling/base/pt_params.h"
17e509ee18Sopenharmony_ci
18e509ee18Sopenharmony_cinamespace panda::ecmascript::tooling {
19e509ee18Sopenharmony_cistd::unique_ptr<EnableParams> EnableParams::Create(const PtJson &params)
20e509ee18Sopenharmony_ci{
21e509ee18Sopenharmony_ci    auto paramsObject = std::make_unique<EnableParams>();
22e509ee18Sopenharmony_ci    std::string error;
23e509ee18Sopenharmony_ci    Result ret;
24e509ee18Sopenharmony_ci
25e509ee18Sopenharmony_ci    double maxScriptsCacheSize;
26e509ee18Sopenharmony_ci    ret = params.GetDouble("maxScriptsCacheSize", &maxScriptsCacheSize);
27e509ee18Sopenharmony_ci    if (ret == Result::SUCCESS) {
28e509ee18Sopenharmony_ci        paramsObject->maxScriptsCacheSize_ = maxScriptsCacheSize;
29e509ee18Sopenharmony_ci    } else if (ret == Result::TYPE_ERROR) {
30e509ee18Sopenharmony_ci        error += "Wrong type of 'maxScriptsCacheSize';";
31e509ee18Sopenharmony_ci    }
32e509ee18Sopenharmony_ci
33e509ee18Sopenharmony_ci    if (!error.empty()) {
34e509ee18Sopenharmony_ci        LOG_DEBUGGER(ERROR) << "EnableParams::Create " << error;
35e509ee18Sopenharmony_ci        return nullptr;
36e509ee18Sopenharmony_ci    }
37e509ee18Sopenharmony_ci
38e509ee18Sopenharmony_ci    return paramsObject;
39e509ee18Sopenharmony_ci}
40e509ee18Sopenharmony_ci
41e509ee18Sopenharmony_cistd::unique_ptr<EvaluateOnCallFrameParams> EvaluateOnCallFrameParams::Create(const PtJson &params)
42e509ee18Sopenharmony_ci{
43e509ee18Sopenharmony_ci    auto paramsObject = std::make_unique<EvaluateOnCallFrameParams>();
44e509ee18Sopenharmony_ci    std::string error;
45e509ee18Sopenharmony_ci    Result ret;
46e509ee18Sopenharmony_ci
47e509ee18Sopenharmony_ci    std::string callFrameId;
48e509ee18Sopenharmony_ci    ret = params.GetString("callFrameId", &callFrameId);
49e509ee18Sopenharmony_ci    if (ret == Result::SUCCESS) {
50e509ee18Sopenharmony_ci        if (!ToolchainUtils::StrToInt32(callFrameId, paramsObject->callFrameId_)) {
51e509ee18Sopenharmony_ci            error += "Failed to convert 'callFrameId' from string to int;";
52e509ee18Sopenharmony_ci        }
53e509ee18Sopenharmony_ci    } else {
54e509ee18Sopenharmony_ci        error += "Unknown or wrong type of 'callFrameId';";
55e509ee18Sopenharmony_ci    }
56e509ee18Sopenharmony_ci    std::string expression;
57e509ee18Sopenharmony_ci    ret = params.GetString("expression", &expression);
58e509ee18Sopenharmony_ci    if (ret == Result::SUCCESS) {
59e509ee18Sopenharmony_ci        paramsObject->expression_ = std::move(expression);
60e509ee18Sopenharmony_ci    } else {
61e509ee18Sopenharmony_ci        error += "Unknown or wrong type of 'expression';";
62e509ee18Sopenharmony_ci    }
63e509ee18Sopenharmony_ci    std::string objectGroup;
64e509ee18Sopenharmony_ci    ret = params.GetString("objectGroup", &objectGroup);
65e509ee18Sopenharmony_ci    if (ret == Result::SUCCESS) {
66e509ee18Sopenharmony_ci        paramsObject->objectGroup_ = std::move(objectGroup);
67e509ee18Sopenharmony_ci    } else if (ret == Result::TYPE_ERROR) {
68e509ee18Sopenharmony_ci        error += "Wrong type of 'objectGroup';";
69e509ee18Sopenharmony_ci    }
70e509ee18Sopenharmony_ci    bool includeCommandLineAPI = false;
71e509ee18Sopenharmony_ci    ret = params.GetBool("includeCommandLineAPI", &includeCommandLineAPI);
72e509ee18Sopenharmony_ci    if (ret == Result::SUCCESS) {
73e509ee18Sopenharmony_ci        paramsObject->includeCommandLineAPI_ = includeCommandLineAPI;
74e509ee18Sopenharmony_ci    } else if (ret == Result::TYPE_ERROR) {
75e509ee18Sopenharmony_ci        error += "Wrong type of 'includeCommandLineAPI';";
76e509ee18Sopenharmony_ci    }
77e509ee18Sopenharmony_ci    bool silent = false;
78e509ee18Sopenharmony_ci    ret = params.GetBool("silent", &silent);
79e509ee18Sopenharmony_ci    if (ret == Result::SUCCESS) {
80e509ee18Sopenharmony_ci        paramsObject->silent_ = silent;
81e509ee18Sopenharmony_ci    } else if (ret == Result::TYPE_ERROR) {
82e509ee18Sopenharmony_ci        error += "Wrong type of 'silent';";
83e509ee18Sopenharmony_ci    }
84e509ee18Sopenharmony_ci    bool returnByValue = false;
85e509ee18Sopenharmony_ci    ret = params.GetBool("returnByValue", &returnByValue);
86e509ee18Sopenharmony_ci    if (ret == Result::SUCCESS) {
87e509ee18Sopenharmony_ci        paramsObject->returnByValue_ = returnByValue;
88e509ee18Sopenharmony_ci    } else if (ret == Result::TYPE_ERROR) {
89e509ee18Sopenharmony_ci        error += "Wrong type of 'returnByValue';";
90e509ee18Sopenharmony_ci    }
91e509ee18Sopenharmony_ci    bool generatePreview = false;
92e509ee18Sopenharmony_ci    ret = params.GetBool("generatePreview", &generatePreview);
93e509ee18Sopenharmony_ci    if (ret == Result::SUCCESS) {
94e509ee18Sopenharmony_ci        paramsObject->generatePreview_ = generatePreview;
95e509ee18Sopenharmony_ci    } else if (ret == Result::TYPE_ERROR) {
96e509ee18Sopenharmony_ci        error += "Wrong type of 'generatePreview';";
97e509ee18Sopenharmony_ci    }
98e509ee18Sopenharmony_ci    bool throwOnSideEffect = false;
99e509ee18Sopenharmony_ci    ret = params.GetBool("throwOnSideEffect", &throwOnSideEffect);
100e509ee18Sopenharmony_ci    if (ret == Result::SUCCESS) {
101e509ee18Sopenharmony_ci        paramsObject->throwOnSideEffect_ = throwOnSideEffect;
102e509ee18Sopenharmony_ci    } else if (ret == Result::TYPE_ERROR) {
103e509ee18Sopenharmony_ci        error += "Wrong type of 'throwOnSideEffect';";
104e509ee18Sopenharmony_ci    }
105e509ee18Sopenharmony_ci
106e509ee18Sopenharmony_ci    if (!error.empty()) {
107e509ee18Sopenharmony_ci        LOG_DEBUGGER(ERROR) << "EvaluateOnCallFrameParams::Create " << error;
108e509ee18Sopenharmony_ci        return nullptr;
109e509ee18Sopenharmony_ci    }
110e509ee18Sopenharmony_ci    return paramsObject;
111e509ee18Sopenharmony_ci}
112e509ee18Sopenharmony_ci
113e509ee18Sopenharmony_cistd::unique_ptr<ContinueToLocationParams> ContinueToLocationParams::Create(const PtJson &params)
114e509ee18Sopenharmony_ci{
115e509ee18Sopenharmony_ci    auto paramsObject = std::make_unique<ContinueToLocationParams>();
116e509ee18Sopenharmony_ci    std::string error;
117e509ee18Sopenharmony_ci    Result ret;
118e509ee18Sopenharmony_ci
119e509ee18Sopenharmony_ci    std::unique_ptr<PtJson> position;
120e509ee18Sopenharmony_ci    ret = params.GetObject("location", &position);
121e509ee18Sopenharmony_ci    if (ret == Result::SUCCESS) {
122e509ee18Sopenharmony_ci        std::unique_ptr<Location> location = Location::Create(*position);
123e509ee18Sopenharmony_ci        if (location == nullptr) {
124e509ee18Sopenharmony_ci            error += "'location' is invalid;";
125e509ee18Sopenharmony_ci        } else {
126e509ee18Sopenharmony_ci            paramsObject->location_= std::move(location);
127e509ee18Sopenharmony_ci        }
128e509ee18Sopenharmony_ci    } else {
129e509ee18Sopenharmony_ci        error += "Unknown or wrong type of 'location';";
130e509ee18Sopenharmony_ci    }
131e509ee18Sopenharmony_ci
132e509ee18Sopenharmony_ci    std::string targetCallFrames;
133e509ee18Sopenharmony_ci    ret = params.GetString("targetCallFrames", &targetCallFrames);
134e509ee18Sopenharmony_ci    if (ret == Result::SUCCESS) {
135e509ee18Sopenharmony_ci        paramsObject->targetCallFrames_ = std::move(targetCallFrames);
136e509ee18Sopenharmony_ci    } else {
137e509ee18Sopenharmony_ci        error += "Unknown 'targetCallFrames';";
138e509ee18Sopenharmony_ci    }
139e509ee18Sopenharmony_ci
140e509ee18Sopenharmony_ci    if (!error.empty()) {
141e509ee18Sopenharmony_ci        LOG_DEBUGGER(ERROR) << "ContinueToLocationParams::Create " << error;
142e509ee18Sopenharmony_ci        return nullptr;
143e509ee18Sopenharmony_ci    }
144e509ee18Sopenharmony_ci
145e509ee18Sopenharmony_ci    return paramsObject;
146e509ee18Sopenharmony_ci}
147e509ee18Sopenharmony_ci
148e509ee18Sopenharmony_ci
149e509ee18Sopenharmony_cistd::unique_ptr<GetPossibleBreakpointsParams> GetPossibleBreakpointsParams::Create(const PtJson &params)
150e509ee18Sopenharmony_ci{
151e509ee18Sopenharmony_ci    auto paramsObject = std::make_unique<GetPossibleBreakpointsParams>();
152e509ee18Sopenharmony_ci    std::string error;
153e509ee18Sopenharmony_ci    Result ret;
154e509ee18Sopenharmony_ci
155e509ee18Sopenharmony_ci    std::unique_ptr<PtJson> start;
156e509ee18Sopenharmony_ci    ret = params.GetObject("start", &start);
157e509ee18Sopenharmony_ci    if (ret == Result::SUCCESS) {
158e509ee18Sopenharmony_ci        std::unique_ptr<Location> location = Location::Create(*start);
159e509ee18Sopenharmony_ci        if (location == nullptr) {
160e509ee18Sopenharmony_ci            error += "'start' is invalid;";
161e509ee18Sopenharmony_ci        } else {
162e509ee18Sopenharmony_ci            paramsObject->start_ = std::move(location);
163e509ee18Sopenharmony_ci        }
164e509ee18Sopenharmony_ci    } else {
165e509ee18Sopenharmony_ci        error += "Unknown or wrong type of 'start';";
166e509ee18Sopenharmony_ci    }
167e509ee18Sopenharmony_ci    std::unique_ptr<PtJson> end;
168e509ee18Sopenharmony_ci    ret = params.GetObject("end", &end);
169e509ee18Sopenharmony_ci    if (ret == Result::SUCCESS) {
170e509ee18Sopenharmony_ci        std::unique_ptr<Location> location = Location::Create(*end);
171e509ee18Sopenharmony_ci        if (location == nullptr) {
172e509ee18Sopenharmony_ci            error += "'end' is invalid;";
173e509ee18Sopenharmony_ci        } else {
174e509ee18Sopenharmony_ci            paramsObject->end_ = std::move(location);
175e509ee18Sopenharmony_ci        }
176e509ee18Sopenharmony_ci    } else if (ret == Result::TYPE_ERROR) {
177e509ee18Sopenharmony_ci        error += "Wrong type of 'end';";
178e509ee18Sopenharmony_ci    }
179e509ee18Sopenharmony_ci    bool restrictToFunction = false;
180e509ee18Sopenharmony_ci    ret = params.GetBool("restrictToFunction", &restrictToFunction);
181e509ee18Sopenharmony_ci    if (ret == Result::SUCCESS) {
182e509ee18Sopenharmony_ci        paramsObject->restrictToFunction_ = restrictToFunction;
183e509ee18Sopenharmony_ci    } else if (ret == Result::TYPE_ERROR) {
184e509ee18Sopenharmony_ci        error += "Wrong type of 'restrictToFunction';";
185e509ee18Sopenharmony_ci    }
186e509ee18Sopenharmony_ci
187e509ee18Sopenharmony_ci    if (!error.empty()) {
188e509ee18Sopenharmony_ci        LOG_DEBUGGER(ERROR) << "GetPossibleBreakpointsParams::Create " << error;
189e509ee18Sopenharmony_ci        return nullptr;
190e509ee18Sopenharmony_ci    }
191e509ee18Sopenharmony_ci
192e509ee18Sopenharmony_ci    return paramsObject;
193e509ee18Sopenharmony_ci}
194e509ee18Sopenharmony_ci
195e509ee18Sopenharmony_cistd::unique_ptr<GetScriptSourceParams> GetScriptSourceParams::Create(const PtJson &params)
196e509ee18Sopenharmony_ci{
197e509ee18Sopenharmony_ci    auto paramsObject = std::make_unique<GetScriptSourceParams>();
198e509ee18Sopenharmony_ci    std::string error;
199e509ee18Sopenharmony_ci    Result ret;
200e509ee18Sopenharmony_ci
201e509ee18Sopenharmony_ci    std::string scriptId;
202e509ee18Sopenharmony_ci    ret = params.GetString("scriptId", &scriptId);
203e509ee18Sopenharmony_ci    if (ret == Result::SUCCESS) {
204e509ee18Sopenharmony_ci        if (!ToolchainUtils::StrToInt32(scriptId, paramsObject->scriptId_)) {
205e509ee18Sopenharmony_ci            error += "Failed to convert 'scriptId' from string to int;";
206e509ee18Sopenharmony_ci        }
207e509ee18Sopenharmony_ci    } else {
208e509ee18Sopenharmony_ci        error += "Unknown or wrong type of'scriptId';";
209e509ee18Sopenharmony_ci    }
210e509ee18Sopenharmony_ci
211e509ee18Sopenharmony_ci    if (!error.empty()) {
212e509ee18Sopenharmony_ci        LOG_DEBUGGER(ERROR) << "GetScriptSourceParams::Create " << error;
213e509ee18Sopenharmony_ci        return nullptr;
214e509ee18Sopenharmony_ci    }
215e509ee18Sopenharmony_ci
216e509ee18Sopenharmony_ci    return paramsObject;
217e509ee18Sopenharmony_ci}
218e509ee18Sopenharmony_ci
219e509ee18Sopenharmony_cistd::unique_ptr<RemoveBreakpointParams> RemoveBreakpointParams::Create(const PtJson &params)
220e509ee18Sopenharmony_ci{
221e509ee18Sopenharmony_ci    auto paramsObject = std::make_unique<RemoveBreakpointParams>();
222e509ee18Sopenharmony_ci    std::string error;
223e509ee18Sopenharmony_ci    Result ret;
224e509ee18Sopenharmony_ci
225e509ee18Sopenharmony_ci    std::string breakpointId;
226e509ee18Sopenharmony_ci    ret = params.GetString("breakpointId", &breakpointId);
227e509ee18Sopenharmony_ci    if (ret == Result::SUCCESS) {
228e509ee18Sopenharmony_ci        paramsObject->breakpointId_ = std::move(breakpointId);
229e509ee18Sopenharmony_ci    } else {
230e509ee18Sopenharmony_ci        error += "Unknown or wrong type of 'breakpointId';";
231e509ee18Sopenharmony_ci    }
232e509ee18Sopenharmony_ci
233e509ee18Sopenharmony_ci    if (!error.empty()) {
234e509ee18Sopenharmony_ci        LOG_DEBUGGER(ERROR) << "RemoveBreakpointParams::Create " << error;
235e509ee18Sopenharmony_ci        return nullptr;
236e509ee18Sopenharmony_ci    }
237e509ee18Sopenharmony_ci
238e509ee18Sopenharmony_ci    return paramsObject;
239e509ee18Sopenharmony_ci}
240e509ee18Sopenharmony_ci
241e509ee18Sopenharmony_cistd::unique_ptr<RemoveBreakpointsByUrlParams> RemoveBreakpointsByUrlParams::Create(const PtJson &params)
242e509ee18Sopenharmony_ci{
243e509ee18Sopenharmony_ci    auto paramsObject = std::make_unique<RemoveBreakpointsByUrlParams>();
244e509ee18Sopenharmony_ci    std::string error;
245e509ee18Sopenharmony_ci    Result ret;
246e509ee18Sopenharmony_ci
247e509ee18Sopenharmony_ci    std::string url;
248e509ee18Sopenharmony_ci    ret = params.GetString("url", &url);
249e509ee18Sopenharmony_ci    if (ret == Result::SUCCESS) {
250e509ee18Sopenharmony_ci        paramsObject->url_ = std::move(url);
251e509ee18Sopenharmony_ci    } else {
252e509ee18Sopenharmony_ci        error += "Wrong or unknown type of 'url'";
253e509ee18Sopenharmony_ci    }
254e509ee18Sopenharmony_ci
255e509ee18Sopenharmony_ci    if (!error.empty()) {
256e509ee18Sopenharmony_ci        LOG_DEBUGGER(ERROR) << "RemoveBreakpointByUrlParams::Create " << error;
257e509ee18Sopenharmony_ci        return nullptr;
258e509ee18Sopenharmony_ci    }
259e509ee18Sopenharmony_ci
260e509ee18Sopenharmony_ci    return paramsObject;
261e509ee18Sopenharmony_ci}
262e509ee18Sopenharmony_ci
263e509ee18Sopenharmony_cistd::unique_ptr<ResumeParams> ResumeParams::Create(const PtJson &params)
264e509ee18Sopenharmony_ci{
265e509ee18Sopenharmony_ci    auto paramsObject = std::make_unique<ResumeParams>();
266e509ee18Sopenharmony_ci    std::string error;
267e509ee18Sopenharmony_ci    Result ret;
268e509ee18Sopenharmony_ci
269e509ee18Sopenharmony_ci    bool terminateOnResume = false;
270e509ee18Sopenharmony_ci    ret = params.GetBool("terminateOnResume", &terminateOnResume);
271e509ee18Sopenharmony_ci    if (ret == Result::SUCCESS) {
272e509ee18Sopenharmony_ci        paramsObject->terminateOnResume_ = terminateOnResume;
273e509ee18Sopenharmony_ci    } else if (ret == Result::TYPE_ERROR) {
274e509ee18Sopenharmony_ci        error += "Wrong type of 'terminateOnResume';";
275e509ee18Sopenharmony_ci    }
276e509ee18Sopenharmony_ci
277e509ee18Sopenharmony_ci    if (!error.empty()) {
278e509ee18Sopenharmony_ci        LOG_DEBUGGER(ERROR) << "ResumeParams::Create " << error;
279e509ee18Sopenharmony_ci        return nullptr;
280e509ee18Sopenharmony_ci    }
281e509ee18Sopenharmony_ci
282e509ee18Sopenharmony_ci    return paramsObject;
283e509ee18Sopenharmony_ci}
284e509ee18Sopenharmony_ci
285e509ee18Sopenharmony_cistd::unique_ptr<SetAsyncCallStackDepthParams> SetAsyncCallStackDepthParams::Create(const PtJson &params)
286e509ee18Sopenharmony_ci{
287e509ee18Sopenharmony_ci    auto paramsObject = std::make_unique<SetAsyncCallStackDepthParams>();
288e509ee18Sopenharmony_ci    std::string error;
289e509ee18Sopenharmony_ci    Result ret;
290e509ee18Sopenharmony_ci
291e509ee18Sopenharmony_ci    int32_t maxDepth;
292e509ee18Sopenharmony_ci    ret = params.GetInt("maxDepth", &maxDepth);
293e509ee18Sopenharmony_ci    if (ret == Result::SUCCESS) {
294e509ee18Sopenharmony_ci        paramsObject->maxDepth_ = maxDepth;
295e509ee18Sopenharmony_ci    } else {
296e509ee18Sopenharmony_ci        error += "Unknown or wrong type of 'maxDepth';";
297e509ee18Sopenharmony_ci    }
298e509ee18Sopenharmony_ci
299e509ee18Sopenharmony_ci    if (!error.empty()) {
300e509ee18Sopenharmony_ci        LOG_DEBUGGER(ERROR) << "SetAsyncCallStackDepthParams::Create " << error;
301e509ee18Sopenharmony_ci        return nullptr;
302e509ee18Sopenharmony_ci    }
303e509ee18Sopenharmony_ci
304e509ee18Sopenharmony_ci    return paramsObject;
305e509ee18Sopenharmony_ci}
306e509ee18Sopenharmony_ci
307e509ee18Sopenharmony_cistd::unique_ptr<SetBlackboxPatternsParams> SetBlackboxPatternsParams::Create(const PtJson &params)
308e509ee18Sopenharmony_ci{
309e509ee18Sopenharmony_ci    auto paramsObject = std::make_unique<SetBlackboxPatternsParams>();
310e509ee18Sopenharmony_ci    std::string error;
311e509ee18Sopenharmony_ci    Result ret;
312e509ee18Sopenharmony_ci
313e509ee18Sopenharmony_ci    std::unique_ptr<PtJson> patterns;
314e509ee18Sopenharmony_ci    ret = params.GetArray("patterns", &patterns);
315e509ee18Sopenharmony_ci    if (ret == Result::SUCCESS) {
316e509ee18Sopenharmony_ci        int32_t len = patterns->GetSize();
317e509ee18Sopenharmony_ci        for (int32_t i = 0; i < len; ++i) {
318e509ee18Sopenharmony_ci            std::unique_ptr<PtJson> item = patterns->Get(i);
319e509ee18Sopenharmony_ci            if (item->IsString()) {
320e509ee18Sopenharmony_ci                paramsObject->patterns_.emplace_back(item->GetString());
321e509ee18Sopenharmony_ci            } else {
322e509ee18Sopenharmony_ci                error += "'patterns' items should be a String;";
323e509ee18Sopenharmony_ci            }
324e509ee18Sopenharmony_ci        }
325e509ee18Sopenharmony_ci    } else {
326e509ee18Sopenharmony_ci        error += "Unknown or wrong type of 'patterns';";
327e509ee18Sopenharmony_ci    }
328e509ee18Sopenharmony_ci
329e509ee18Sopenharmony_ci    if (!error.empty()) {
330e509ee18Sopenharmony_ci        LOG_DEBUGGER(ERROR) << "SetBlackboxPatternsParams::Create " << error;
331e509ee18Sopenharmony_ci        return nullptr;
332e509ee18Sopenharmony_ci    }
333e509ee18Sopenharmony_ci
334e509ee18Sopenharmony_ci    return paramsObject;
335e509ee18Sopenharmony_ci}
336e509ee18Sopenharmony_ci
337e509ee18Sopenharmony_cistd::unique_ptr<SetBreakpointByUrlParams> SetBreakpointByUrlParams::Create(const PtJson &params)
338e509ee18Sopenharmony_ci{
339e509ee18Sopenharmony_ci    auto paramsObject = std::make_unique<SetBreakpointByUrlParams>();
340e509ee18Sopenharmony_ci    std::string error;
341e509ee18Sopenharmony_ci    Result ret;
342e509ee18Sopenharmony_ci
343e509ee18Sopenharmony_ci    int32_t lineNumber;
344e509ee18Sopenharmony_ci    ret = params.GetInt("lineNumber", &lineNumber);
345e509ee18Sopenharmony_ci    if (ret == Result::SUCCESS) {
346e509ee18Sopenharmony_ci        paramsObject->lineNumber_ = lineNumber;
347e509ee18Sopenharmony_ci    } else {
348e509ee18Sopenharmony_ci        error += "Unknown or wrong type of 'lineNumber';";
349e509ee18Sopenharmony_ci    }
350e509ee18Sopenharmony_ci    std::string url;
351e509ee18Sopenharmony_ci    ret = params.GetString("url", &url);
352e509ee18Sopenharmony_ci    if (ret == Result::SUCCESS) {
353e509ee18Sopenharmony_ci        paramsObject->url_ = std::move(url);
354e509ee18Sopenharmony_ci    } else if (ret == Result::TYPE_ERROR) {
355e509ee18Sopenharmony_ci        error += "Wrong type of 'url';";
356e509ee18Sopenharmony_ci    }
357e509ee18Sopenharmony_ci    std::string urlRegex;
358e509ee18Sopenharmony_ci    ret = params.GetString("urlRegex", &urlRegex);
359e509ee18Sopenharmony_ci    if (ret == Result::SUCCESS) {
360e509ee18Sopenharmony_ci        paramsObject->urlRegex_ = std::move(urlRegex);
361e509ee18Sopenharmony_ci    } else if (ret == Result::TYPE_ERROR) {
362e509ee18Sopenharmony_ci        error += "Wrong type of 'urlRegex';";
363e509ee18Sopenharmony_ci    }
364e509ee18Sopenharmony_ci    std::string scriptHash;
365e509ee18Sopenharmony_ci    ret = params.GetString("scriptHash", &scriptHash);
366e509ee18Sopenharmony_ci    if (ret == Result::SUCCESS) {
367e509ee18Sopenharmony_ci        paramsObject->scriptHash_ = std::move(scriptHash);
368e509ee18Sopenharmony_ci    } else if (ret == Result::TYPE_ERROR) {
369e509ee18Sopenharmony_ci        error += "Wrong type of 'scriptHash';";
370e509ee18Sopenharmony_ci    }
371e509ee18Sopenharmony_ci    int32_t columnNumber;
372e509ee18Sopenharmony_ci    ret = params.GetInt("columnNumber", &columnNumber);
373e509ee18Sopenharmony_ci    if (ret == Result::SUCCESS) {
374e509ee18Sopenharmony_ci        paramsObject->columnNumber_ = columnNumber;
375e509ee18Sopenharmony_ci    } else if (ret == Result::TYPE_ERROR) {
376e509ee18Sopenharmony_ci        error += "Wrong type of 'columnNumber';";
377e509ee18Sopenharmony_ci    }
378e509ee18Sopenharmony_ci    std::string condition;
379e509ee18Sopenharmony_ci    ret = params.GetString("condition", &condition);
380e509ee18Sopenharmony_ci    if (ret == Result::SUCCESS) {
381e509ee18Sopenharmony_ci        paramsObject->condition_ = std::move(condition);
382e509ee18Sopenharmony_ci    } else if (ret == Result::TYPE_ERROR) {
383e509ee18Sopenharmony_ci        error += "Wrong type of 'condition';";
384e509ee18Sopenharmony_ci    }
385e509ee18Sopenharmony_ci    if (!error.empty()) {
386e509ee18Sopenharmony_ci        LOG_DEBUGGER(ERROR) << "SetBreakpointByUrlParams::Create " << error;
387e509ee18Sopenharmony_ci        return nullptr;
388e509ee18Sopenharmony_ci    }
389e509ee18Sopenharmony_ci
390e509ee18Sopenharmony_ci    return paramsObject;
391e509ee18Sopenharmony_ci}
392e509ee18Sopenharmony_ci
393e509ee18Sopenharmony_cistd::unique_ptr<SetBreakpointsActiveParams> SetBreakpointsActiveParams::Create(const PtJson &params)
394e509ee18Sopenharmony_ci{
395e509ee18Sopenharmony_ci    auto paramsObject = std::make_unique<SetBreakpointsActiveParams>();
396e509ee18Sopenharmony_ci    std::string error;
397e509ee18Sopenharmony_ci    Result ret;
398e509ee18Sopenharmony_ci
399e509ee18Sopenharmony_ci    bool breakpointsState;
400e509ee18Sopenharmony_ci    ret = params.GetBool("active", &breakpointsState);
401e509ee18Sopenharmony_ci    if (ret == Result::SUCCESS) {
402e509ee18Sopenharmony_ci        paramsObject->breakpointsState_ = std::move(breakpointsState);
403e509ee18Sopenharmony_ci    } else {
404e509ee18Sopenharmony_ci        error += "Unknown or wrong type of 'active';";
405e509ee18Sopenharmony_ci    }
406e509ee18Sopenharmony_ci    if (!error.empty()) {
407e509ee18Sopenharmony_ci        LOG_DEBUGGER(ERROR) << "SetBreakpointsActiveParams::Create " << error;
408e509ee18Sopenharmony_ci        return nullptr;
409e509ee18Sopenharmony_ci    }
410e509ee18Sopenharmony_ci
411e509ee18Sopenharmony_ci    return paramsObject;
412e509ee18Sopenharmony_ci}
413e509ee18Sopenharmony_ci
414e509ee18Sopenharmony_cistd::unique_ptr<SetSkipAllPausesParams> SetSkipAllPausesParams::Create(const PtJson &params)
415e509ee18Sopenharmony_ci{
416e509ee18Sopenharmony_ci    auto paramsObject = std::make_unique<SetSkipAllPausesParams>();
417e509ee18Sopenharmony_ci    std::string error;
418e509ee18Sopenharmony_ci    Result ret;
419e509ee18Sopenharmony_ci
420e509ee18Sopenharmony_ci    bool skipAllPausesState;
421e509ee18Sopenharmony_ci    ret = params.GetBool("skip", &skipAllPausesState);
422e509ee18Sopenharmony_ci    if (ret == Result::SUCCESS) {
423e509ee18Sopenharmony_ci        paramsObject->skipAllPausesState_ = std::move(skipAllPausesState);
424e509ee18Sopenharmony_ci    } else {
425e509ee18Sopenharmony_ci        error += "Unknown or wrong type of 'skip';";
426e509ee18Sopenharmony_ci    }
427e509ee18Sopenharmony_ci    if (!error.empty()) {
428e509ee18Sopenharmony_ci        LOG_DEBUGGER(ERROR) << "SetSkipAllPausesParams::Create " << error;
429e509ee18Sopenharmony_ci        return nullptr;
430e509ee18Sopenharmony_ci    }
431e509ee18Sopenharmony_ci
432e509ee18Sopenharmony_ci    return paramsObject;
433e509ee18Sopenharmony_ci}
434e509ee18Sopenharmony_ci
435e509ee18Sopenharmony_cistd::unique_ptr<GetPossibleAndSetBreakpointParams> GetPossibleAndSetBreakpointParams::Create(const PtJson &params)
436e509ee18Sopenharmony_ci{
437e509ee18Sopenharmony_ci    auto paramsObject = std::make_unique<GetPossibleAndSetBreakpointParams>();
438e509ee18Sopenharmony_ci    std::string error;
439e509ee18Sopenharmony_ci    Result ret;
440e509ee18Sopenharmony_ci
441e509ee18Sopenharmony_ci    std::unique_ptr<PtJson> breakpoints;
442e509ee18Sopenharmony_ci    ret = params.GetArray("locations", &breakpoints);
443e509ee18Sopenharmony_ci    if (ret == Result::SUCCESS) {
444e509ee18Sopenharmony_ci        int32_t length = breakpoints->GetSize();
445e509ee18Sopenharmony_ci        std::vector<std::unique_ptr<BreakpointInfo>> breakpointList;
446e509ee18Sopenharmony_ci        for (int32_t i = 0; i < length; i++) {
447e509ee18Sopenharmony_ci            std::unique_ptr<BreakpointInfo> info = BreakpointInfo::Create(*breakpoints->Get(i));
448e509ee18Sopenharmony_ci            if (info == nullptr) {
449e509ee18Sopenharmony_ci                error += "'breakpoints' items BreakpointInfo is invaild;";
450e509ee18Sopenharmony_ci                break;
451e509ee18Sopenharmony_ci            } else {
452e509ee18Sopenharmony_ci                breakpointList.emplace_back(std::move(info));
453e509ee18Sopenharmony_ci            }
454e509ee18Sopenharmony_ci        }
455e509ee18Sopenharmony_ci        if (!breakpointList.empty()) {
456e509ee18Sopenharmony_ci            paramsObject->breakpointsList_ = std::move(breakpointList);
457e509ee18Sopenharmony_ci        }
458e509ee18Sopenharmony_ci    } else if (ret == Result::TYPE_ERROR) {
459e509ee18Sopenharmony_ci        error += "Wrong type of 'breakpoints';";
460e509ee18Sopenharmony_ci    }
461e509ee18Sopenharmony_ci
462e509ee18Sopenharmony_ci    if (!error.empty()) {
463e509ee18Sopenharmony_ci        LOG_DEBUGGER(ERROR) << "GetPossibleAndSetBreakpointParams::Create " << error;
464e509ee18Sopenharmony_ci        return nullptr;
465e509ee18Sopenharmony_ci    }
466e509ee18Sopenharmony_ci
467e509ee18Sopenharmony_ci    return paramsObject;
468e509ee18Sopenharmony_ci}
469e509ee18Sopenharmony_ci
470e509ee18Sopenharmony_cistd::unique_ptr<SetPauseOnExceptionsParams> SetPauseOnExceptionsParams::Create(const PtJson &params)
471e509ee18Sopenharmony_ci{
472e509ee18Sopenharmony_ci    auto paramsObject = std::make_unique<SetPauseOnExceptionsParams>();
473e509ee18Sopenharmony_ci    std::string error;
474e509ee18Sopenharmony_ci    Result ret;
475e509ee18Sopenharmony_ci
476e509ee18Sopenharmony_ci    std::string state;
477e509ee18Sopenharmony_ci    ret = params.GetString("state", &state);
478e509ee18Sopenharmony_ci    if (ret == Result::SUCCESS) {
479e509ee18Sopenharmony_ci        paramsObject->StoreState(state);
480e509ee18Sopenharmony_ci    } else {
481e509ee18Sopenharmony_ci        error += "Unknown or wrong type of'state';";
482e509ee18Sopenharmony_ci    }
483e509ee18Sopenharmony_ci
484e509ee18Sopenharmony_ci    if (!error.empty()) {
485e509ee18Sopenharmony_ci        LOG_DEBUGGER(ERROR) << "SetPauseOnExceptionsParams::Create " << error;
486e509ee18Sopenharmony_ci        return nullptr;
487e509ee18Sopenharmony_ci    }
488e509ee18Sopenharmony_ci
489e509ee18Sopenharmony_ci    return paramsObject;
490e509ee18Sopenharmony_ci}
491e509ee18Sopenharmony_ci
492e509ee18Sopenharmony_cistd::unique_ptr<StepIntoParams> StepIntoParams::Create(const PtJson &params)
493e509ee18Sopenharmony_ci{
494e509ee18Sopenharmony_ci    auto paramsObject = std::make_unique<StepIntoParams>();
495e509ee18Sopenharmony_ci    std::string error;
496e509ee18Sopenharmony_ci    Result ret;
497e509ee18Sopenharmony_ci
498e509ee18Sopenharmony_ci    bool breakOnAsyncCall = false;
499e509ee18Sopenharmony_ci    ret = params.GetBool("breakOnAsyncCall", &breakOnAsyncCall);
500e509ee18Sopenharmony_ci    if (ret == Result::SUCCESS) {
501e509ee18Sopenharmony_ci        paramsObject->breakOnAsyncCall_ = breakOnAsyncCall;
502e509ee18Sopenharmony_ci    } else if (ret == Result::TYPE_ERROR) {
503e509ee18Sopenharmony_ci        error += "Wrong type of 'breakOnAsyncCall';";
504e509ee18Sopenharmony_ci    }
505e509ee18Sopenharmony_ci    std::unique_ptr<PtJson> skipList;
506e509ee18Sopenharmony_ci    ret = params.GetArray("skipList", &skipList);
507e509ee18Sopenharmony_ci    if (ret == Result::SUCCESS) {
508e509ee18Sopenharmony_ci        int32_t len = skipList->GetSize();
509e509ee18Sopenharmony_ci        std::list<std::unique_ptr<LocationRange>> listLocation;
510e509ee18Sopenharmony_ci        for (int32_t i = 0; i < len; ++i) {
511e509ee18Sopenharmony_ci            std::unique_ptr<LocationRange> obj = LocationRange::Create(*skipList->Get(i));
512e509ee18Sopenharmony_ci            if (obj == nullptr) {
513e509ee18Sopenharmony_ci                error += "'skipList' items LocationRange is invalid;";
514e509ee18Sopenharmony_ci                break;
515e509ee18Sopenharmony_ci            } else {
516e509ee18Sopenharmony_ci                listLocation.emplace_back(std::move(obj));
517e509ee18Sopenharmony_ci            }
518e509ee18Sopenharmony_ci        }
519e509ee18Sopenharmony_ci        if (listLocation.size()) {
520e509ee18Sopenharmony_ci            paramsObject->skipList_ = std::move(listLocation);
521e509ee18Sopenharmony_ci        }
522e509ee18Sopenharmony_ci    } else if (ret == Result::TYPE_ERROR) {
523e509ee18Sopenharmony_ci        error += "Wrong type of 'skipList';";
524e509ee18Sopenharmony_ci    }
525e509ee18Sopenharmony_ci
526e509ee18Sopenharmony_ci    if (!error.empty()) {
527e509ee18Sopenharmony_ci        LOG_DEBUGGER(ERROR) << "StepIntoParams::Create " << error;
528e509ee18Sopenharmony_ci        return nullptr;
529e509ee18Sopenharmony_ci    }
530e509ee18Sopenharmony_ci
531e509ee18Sopenharmony_ci    return paramsObject;
532e509ee18Sopenharmony_ci}
533e509ee18Sopenharmony_ci
534e509ee18Sopenharmony_cistd::unique_ptr<SmartStepIntoParams> SmartStepIntoParams::Create(const PtJson &params)
535e509ee18Sopenharmony_ci{
536e509ee18Sopenharmony_ci    auto paramsObject = std::make_unique<SmartStepIntoParams>();
537e509ee18Sopenharmony_ci    auto sbpObject = std::make_unique<SetBreakpointByUrlParams>();
538e509ee18Sopenharmony_ci    PtJson ptJson(params.GetJson());
539e509ee18Sopenharmony_ci    AddRequireParams(ptJson);
540e509ee18Sopenharmony_ci    if (!(sbpObject = SetBreakpointByUrlParams::Create(ptJson))) {
541e509ee18Sopenharmony_ci        return nullptr;
542e509ee18Sopenharmony_ci    }
543e509ee18Sopenharmony_ci    paramsObject->sbpParams_ = std::move(sbpObject);
544e509ee18Sopenharmony_ci    return paramsObject;
545e509ee18Sopenharmony_ci}
546e509ee18Sopenharmony_ci
547e509ee18Sopenharmony_civoid SmartStepIntoParams::AddRequireParams(PtJson &params)
548e509ee18Sopenharmony_ci{
549e509ee18Sopenharmony_ci    if (!params.Contains("urlRegex")) {
550e509ee18Sopenharmony_ci        params.Add("urlRegex", "");
551e509ee18Sopenharmony_ci    }
552e509ee18Sopenharmony_ci    if (!params.Contains("scriptHash")) {
553e509ee18Sopenharmony_ci        params.Add("scriptHash", "");
554e509ee18Sopenharmony_ci    }
555e509ee18Sopenharmony_ci    if (!params.Contains("columnNumber")) {
556e509ee18Sopenharmony_ci        params.Add("columnNumber", 0);
557e509ee18Sopenharmony_ci    }
558e509ee18Sopenharmony_ci    if (!params.Contains("condition")) {
559e509ee18Sopenharmony_ci        params.Add("condition", "");
560e509ee18Sopenharmony_ci    }
561e509ee18Sopenharmony_ci}
562e509ee18Sopenharmony_ci
563e509ee18Sopenharmony_cistd::unique_ptr<StepOverParams> StepOverParams::Create(const PtJson &params)
564e509ee18Sopenharmony_ci{
565e509ee18Sopenharmony_ci    auto paramsObject = std::make_unique<StepOverParams>();
566e509ee18Sopenharmony_ci    std::string error;
567e509ee18Sopenharmony_ci    Result ret;
568e509ee18Sopenharmony_ci
569e509ee18Sopenharmony_ci    std::unique_ptr<PtJson> skipList;
570e509ee18Sopenharmony_ci    ret = params.GetArray("skipList", &skipList);
571e509ee18Sopenharmony_ci    if (ret == Result::SUCCESS) {
572e509ee18Sopenharmony_ci        int32_t len = skipList->GetSize();
573e509ee18Sopenharmony_ci        std::list<std::unique_ptr<LocationRange>> listLocation;
574e509ee18Sopenharmony_ci        for (int32_t i = 0; i < len; ++i) {
575e509ee18Sopenharmony_ci            std::unique_ptr<LocationRange> obj = LocationRange::Create(*skipList->Get(i));
576e509ee18Sopenharmony_ci            if (obj == nullptr) {
577e509ee18Sopenharmony_ci                error += "'skipList' items LocationRange is invalid;";
578e509ee18Sopenharmony_ci                break;
579e509ee18Sopenharmony_ci            } else {
580e509ee18Sopenharmony_ci                listLocation.emplace_back(std::move(obj));
581e509ee18Sopenharmony_ci            }
582e509ee18Sopenharmony_ci        }
583e509ee18Sopenharmony_ci        if (listLocation.size()) {
584e509ee18Sopenharmony_ci            paramsObject->skipList_ = std::move(listLocation);
585e509ee18Sopenharmony_ci        }
586e509ee18Sopenharmony_ci    } else if (ret == Result::TYPE_ERROR) {
587e509ee18Sopenharmony_ci        error += "Wrong type of 'skipList';";
588e509ee18Sopenharmony_ci    }
589e509ee18Sopenharmony_ci
590e509ee18Sopenharmony_ci    if (!error.empty()) {
591e509ee18Sopenharmony_ci        LOG_DEBUGGER(ERROR) << "StepOverParams::Create " << error;
592e509ee18Sopenharmony_ci        return nullptr;
593e509ee18Sopenharmony_ci    }
594e509ee18Sopenharmony_ci
595e509ee18Sopenharmony_ci    return paramsObject;
596e509ee18Sopenharmony_ci}
597e509ee18Sopenharmony_ci
598e509ee18Sopenharmony_cistd::unique_ptr<DropFrameParams> DropFrameParams::Create(const PtJson &params)
599e509ee18Sopenharmony_ci{
600e509ee18Sopenharmony_ci    auto paramsObject = std::make_unique<DropFrameParams>();
601e509ee18Sopenharmony_ci    std::string error;
602e509ee18Sopenharmony_ci    Result ret;
603e509ee18Sopenharmony_ci
604e509ee18Sopenharmony_ci    uint32_t droppedDepth = 0;
605e509ee18Sopenharmony_ci    ret = params.GetUInt("droppedDepth", &droppedDepth);
606e509ee18Sopenharmony_ci    if (ret == Result::SUCCESS) {
607e509ee18Sopenharmony_ci        paramsObject->droppedDepth_ = droppedDepth;
608e509ee18Sopenharmony_ci    } else if (ret == Result::TYPE_ERROR) {
609e509ee18Sopenharmony_ci        error += "Wrong type of 'droppedDepth';";
610e509ee18Sopenharmony_ci    }
611e509ee18Sopenharmony_ci
612e509ee18Sopenharmony_ci    if (!error.empty()) {
613e509ee18Sopenharmony_ci        LOG_DEBUGGER(ERROR) << "DropFrameParams::Create " << error;
614e509ee18Sopenharmony_ci        return nullptr;
615e509ee18Sopenharmony_ci    }
616e509ee18Sopenharmony_ci
617e509ee18Sopenharmony_ci    return paramsObject;
618e509ee18Sopenharmony_ci}
619e509ee18Sopenharmony_ci
620e509ee18Sopenharmony_cistd::unique_ptr<SetNativeRangeParams> SetNativeRangeParams::Create(const PtJson &params)
621e509ee18Sopenharmony_ci{
622e509ee18Sopenharmony_ci    auto paramsObject = std::make_unique<SetNativeRangeParams>();
623e509ee18Sopenharmony_ci    std::string error;
624e509ee18Sopenharmony_ci    Result ret;
625e509ee18Sopenharmony_ci
626e509ee18Sopenharmony_ci    std::unique_ptr<PtJson> nativeRange;
627e509ee18Sopenharmony_ci    ret = params.GetArray("nativeRange", &nativeRange);
628e509ee18Sopenharmony_ci    if (ret == Result::SUCCESS) {
629e509ee18Sopenharmony_ci        int32_t len = nativeRange->GetSize();
630e509ee18Sopenharmony_ci        std::vector<NativeRange> vectorNativeRange;
631e509ee18Sopenharmony_ci        for (int32_t i = 0; i < len; ++i) {
632e509ee18Sopenharmony_ci            std::unique_ptr<NativeRange> obj = NativeRange::Create(*nativeRange->Get(i));
633e509ee18Sopenharmony_ci            if (obj == nullptr) {
634e509ee18Sopenharmony_ci                error += "'nativeRange' is invalid;";
635e509ee18Sopenharmony_ci                break;
636e509ee18Sopenharmony_ci            } else {
637e509ee18Sopenharmony_ci                vectorNativeRange.emplace_back(std::move(*obj));
638e509ee18Sopenharmony_ci            }
639e509ee18Sopenharmony_ci        }
640e509ee18Sopenharmony_ci        if (vectorNativeRange.size()) {
641e509ee18Sopenharmony_ci            paramsObject->nativeRange_ = std::move(vectorNativeRange);
642e509ee18Sopenharmony_ci        }
643e509ee18Sopenharmony_ci    } else if (ret == Result::TYPE_ERROR) {
644e509ee18Sopenharmony_ci        error += "Unknown 'nativeRange';";
645e509ee18Sopenharmony_ci    }
646e509ee18Sopenharmony_ci
647e509ee18Sopenharmony_ci    if (!error.empty()) {
648e509ee18Sopenharmony_ci        LOG_DEBUGGER(ERROR) << "SetNativeRangeParams::Create " << error;
649e509ee18Sopenharmony_ci        return nullptr;
650e509ee18Sopenharmony_ci    }
651e509ee18Sopenharmony_ci
652e509ee18Sopenharmony_ci    return paramsObject;
653e509ee18Sopenharmony_ci}
654e509ee18Sopenharmony_ci
655e509ee18Sopenharmony_cistd::unique_ptr<SetMixedDebugParams> SetMixedDebugParams::Create(const PtJson &params)
656e509ee18Sopenharmony_ci{
657e509ee18Sopenharmony_ci    auto paramsObject = std::make_unique<SetMixedDebugParams>();
658e509ee18Sopenharmony_ci    std::string error;
659e509ee18Sopenharmony_ci    Result ret;
660e509ee18Sopenharmony_ci
661e509ee18Sopenharmony_ci    bool enabled = false;
662e509ee18Sopenharmony_ci    ret = params.GetBool("enabled", &enabled);
663e509ee18Sopenharmony_ci    if (ret == Result::SUCCESS) {
664e509ee18Sopenharmony_ci        paramsObject->enabled_ = enabled;
665e509ee18Sopenharmony_ci    } else if (ret == Result::TYPE_ERROR) {
666e509ee18Sopenharmony_ci        error += "Wrong type of 'enabled';";
667e509ee18Sopenharmony_ci    }
668e509ee18Sopenharmony_ci
669e509ee18Sopenharmony_ci    bool mixedStackEnabled = false;
670e509ee18Sopenharmony_ci    ret = params.GetBool("mixedStackEnabled", &mixedStackEnabled);
671e509ee18Sopenharmony_ci    if (ret == Result::SUCCESS) {
672e509ee18Sopenharmony_ci        paramsObject->mixedStackEnabled_ = mixedStackEnabled;
673e509ee18Sopenharmony_ci    } else if (ret == Result::TYPE_ERROR) {
674e509ee18Sopenharmony_ci        error += "Wrong type of 'enabled';";
675e509ee18Sopenharmony_ci    }
676e509ee18Sopenharmony_ci
677e509ee18Sopenharmony_ci    if (!error.empty()) {
678e509ee18Sopenharmony_ci        LOG_DEBUGGER(ERROR) << "SetMixedDebugParams::Create " << error;
679e509ee18Sopenharmony_ci        return nullptr;
680e509ee18Sopenharmony_ci    }
681e509ee18Sopenharmony_ci
682e509ee18Sopenharmony_ci    return paramsObject;
683e509ee18Sopenharmony_ci}
684e509ee18Sopenharmony_ci
685e509ee18Sopenharmony_cistd::unique_ptr<ResetSingleStepperParams> ResetSingleStepperParams::Create(const PtJson &params)
686e509ee18Sopenharmony_ci{
687e509ee18Sopenharmony_ci    auto paramsObject = std::make_unique<ResetSingleStepperParams>();
688e509ee18Sopenharmony_ci    std::string error;
689e509ee18Sopenharmony_ci    Result ret;
690e509ee18Sopenharmony_ci
691e509ee18Sopenharmony_ci    bool resetSingleStepper = false;
692e509ee18Sopenharmony_ci    ret = params.GetBool("resetSingleStepper", &resetSingleStepper);
693e509ee18Sopenharmony_ci    if (ret == Result::SUCCESS) {
694e509ee18Sopenharmony_ci        paramsObject->resetSingleStepper_ = resetSingleStepper;
695e509ee18Sopenharmony_ci    } else if (ret == Result::TYPE_ERROR) {
696e509ee18Sopenharmony_ci        error += "Wrong type of 'resetSingleStepper';";
697e509ee18Sopenharmony_ci    }
698e509ee18Sopenharmony_ci
699e509ee18Sopenharmony_ci    if (!error.empty()) {
700e509ee18Sopenharmony_ci        LOG_DEBUGGER(ERROR) << "ResetSingleStepperParams::Create " << error;
701e509ee18Sopenharmony_ci        return nullptr;
702e509ee18Sopenharmony_ci    }
703e509ee18Sopenharmony_ci
704e509ee18Sopenharmony_ci    return paramsObject;
705e509ee18Sopenharmony_ci}
706e509ee18Sopenharmony_ci
707e509ee18Sopenharmony_cistd::unique_ptr<ReplyNativeCallingParams> ReplyNativeCallingParams::Create(const PtJson &params)
708e509ee18Sopenharmony_ci{
709e509ee18Sopenharmony_ci    auto paramsObject = std::make_unique<ReplyNativeCallingParams>();
710e509ee18Sopenharmony_ci    std::string error;
711e509ee18Sopenharmony_ci    Result ret;
712e509ee18Sopenharmony_ci
713e509ee18Sopenharmony_ci    bool userCode = false;
714e509ee18Sopenharmony_ci    ret = params.GetBool("userCode", &userCode);
715e509ee18Sopenharmony_ci    if (ret == Result::SUCCESS) {
716e509ee18Sopenharmony_ci        paramsObject->userCode_ = userCode;
717e509ee18Sopenharmony_ci    } else if (ret == Result::TYPE_ERROR) {
718e509ee18Sopenharmony_ci        error += "Wrong type of 'userCode';";
719e509ee18Sopenharmony_ci    }
720e509ee18Sopenharmony_ci
721e509ee18Sopenharmony_ci    if (!error.empty()) {
722e509ee18Sopenharmony_ci        LOG_DEBUGGER(ERROR) << "ReplyNativeCallingParams::Create " << error;
723e509ee18Sopenharmony_ci        return nullptr;
724e509ee18Sopenharmony_ci    }
725e509ee18Sopenharmony_ci
726e509ee18Sopenharmony_ci    return paramsObject;
727e509ee18Sopenharmony_ci}
728e509ee18Sopenharmony_ci
729e509ee18Sopenharmony_cistd::unique_ptr<GetPropertiesParams> GetPropertiesParams::Create(const PtJson &params)
730e509ee18Sopenharmony_ci{
731e509ee18Sopenharmony_ci    auto paramsObject = std::make_unique<GetPropertiesParams>();
732e509ee18Sopenharmony_ci    std::string error;
733e509ee18Sopenharmony_ci    Result ret;
734e509ee18Sopenharmony_ci
735e509ee18Sopenharmony_ci    std::string objectId;
736e509ee18Sopenharmony_ci    ret = params.GetString("objectId", &objectId);
737e509ee18Sopenharmony_ci    if (ret == Result::SUCCESS) {
738e509ee18Sopenharmony_ci        if (!ToolchainUtils::StrToInt32(objectId, paramsObject->objectId_)) {
739e509ee18Sopenharmony_ci            error += "Failed to convert 'objectId' from string to int;";
740e509ee18Sopenharmony_ci        }
741e509ee18Sopenharmony_ci    } else {
742e509ee18Sopenharmony_ci        error += "Unknown or wrong type of 'objectId';";
743e509ee18Sopenharmony_ci    }
744e509ee18Sopenharmony_ci    bool ownProperties = false;
745e509ee18Sopenharmony_ci    ret = params.GetBool("ownProperties", &ownProperties);
746e509ee18Sopenharmony_ci    if (ret == Result::SUCCESS) {
747e509ee18Sopenharmony_ci        paramsObject->ownProperties_ = ownProperties;
748e509ee18Sopenharmony_ci    } else if (ret == Result::TYPE_ERROR) {
749e509ee18Sopenharmony_ci        error += "Wrong type of 'ownProperties';";
750e509ee18Sopenharmony_ci    }
751e509ee18Sopenharmony_ci    bool accessorPropertiesOnly = false;
752e509ee18Sopenharmony_ci    ret = params.GetBool("accessorPropertiesOnly", &accessorPropertiesOnly);
753e509ee18Sopenharmony_ci    if (ret == Result::SUCCESS) {
754e509ee18Sopenharmony_ci        paramsObject->accessorPropertiesOnly_ = accessorPropertiesOnly;
755e509ee18Sopenharmony_ci    } else if (ret == Result::TYPE_ERROR) {
756e509ee18Sopenharmony_ci        error += "Wrong type of 'accessorPropertiesOnly';";
757e509ee18Sopenharmony_ci    }
758e509ee18Sopenharmony_ci    bool generatePreview = false;
759e509ee18Sopenharmony_ci    ret = params.GetBool("generatePreview", &generatePreview);
760e509ee18Sopenharmony_ci    if (ret == Result::SUCCESS) {
761e509ee18Sopenharmony_ci        paramsObject->generatePreview_ = generatePreview;
762e509ee18Sopenharmony_ci    } else if (ret == Result::TYPE_ERROR) {
763e509ee18Sopenharmony_ci        error += "Wrong type of 'generatePreview';";
764e509ee18Sopenharmony_ci    }
765e509ee18Sopenharmony_ci    if (!error.empty()) {
766e509ee18Sopenharmony_ci        LOG_DEBUGGER(ERROR) << "GetPropertiesParams::Create " << error;
767e509ee18Sopenharmony_ci        return nullptr;
768e509ee18Sopenharmony_ci    }
769e509ee18Sopenharmony_ci
770e509ee18Sopenharmony_ci    return paramsObject;
771e509ee18Sopenharmony_ci}
772e509ee18Sopenharmony_ci
773e509ee18Sopenharmony_cistd::unique_ptr<CallFunctionOnParams> CallFunctionOnParams::Create(const PtJson &params)
774e509ee18Sopenharmony_ci{
775e509ee18Sopenharmony_ci    auto paramsObject = std::make_unique<CallFunctionOnParams>();
776e509ee18Sopenharmony_ci    std::string error;
777e509ee18Sopenharmony_ci    Result ret;
778e509ee18Sopenharmony_ci
779e509ee18Sopenharmony_ci    // paramsObject->callFrameId_
780e509ee18Sopenharmony_ci    std::string callFrameId;
781e509ee18Sopenharmony_ci    ret = params.GetString("callFrameId", &callFrameId);
782e509ee18Sopenharmony_ci    if (ret == Result::SUCCESS) {
783e509ee18Sopenharmony_ci        if (!ToolchainUtils::StrToInt32(callFrameId, paramsObject->callFrameId_)) {
784e509ee18Sopenharmony_ci            error += "Failed to convert 'callFrameId' from string to int;";
785e509ee18Sopenharmony_ci        }
786e509ee18Sopenharmony_ci    } else {
787e509ee18Sopenharmony_ci        error += "Unknown or wrong type of 'callFrameId';";
788e509ee18Sopenharmony_ci    }
789e509ee18Sopenharmony_ci    // paramsObject->functionDeclaration_
790e509ee18Sopenharmony_ci    std::string functionDeclaration;
791e509ee18Sopenharmony_ci    ret = params.GetString("functionDeclaration", &functionDeclaration);
792e509ee18Sopenharmony_ci    if (ret == Result::SUCCESS) {
793e509ee18Sopenharmony_ci        paramsObject->functionDeclaration_ = std::move(functionDeclaration);
794e509ee18Sopenharmony_ci    } else {
795e509ee18Sopenharmony_ci        error += "Unknown or wrong type of 'functionDeclaration';";
796e509ee18Sopenharmony_ci    }
797e509ee18Sopenharmony_ci    // paramsObject->objectId_
798e509ee18Sopenharmony_ci    std::string objectId;
799e509ee18Sopenharmony_ci    ret = params.GetString("objectId", &objectId);
800e509ee18Sopenharmony_ci    if (ret == Result::SUCCESS) {
801e509ee18Sopenharmony_ci        if (!ToolchainUtils::StrToInt32(objectId, paramsObject->objectId_)) {
802e509ee18Sopenharmony_ci            error += "Failed to convert 'objectId' from string to int;";
803e509ee18Sopenharmony_ci        }
804e509ee18Sopenharmony_ci    } else if (ret == Result::TYPE_ERROR) {
805e509ee18Sopenharmony_ci        error += "Wrong type of 'objectId';";
806e509ee18Sopenharmony_ci    }
807e509ee18Sopenharmony_ci    // paramsObject->arguments_
808e509ee18Sopenharmony_ci    std::unique_ptr<PtJson> arguments;
809e509ee18Sopenharmony_ci    ret = params.GetArray("arguments", &arguments);
810e509ee18Sopenharmony_ci    if (ret == Result::SUCCESS) {
811e509ee18Sopenharmony_ci        int32_t len = arguments->GetSize();
812e509ee18Sopenharmony_ci        std::vector<std::unique_ptr<CallArgument>> callArgument;
813e509ee18Sopenharmony_ci        for (int32_t i = 0; i < len; ++i) {
814e509ee18Sopenharmony_ci            std::unique_ptr<CallArgument> obj = CallArgument::Create(*arguments->Get(i));
815e509ee18Sopenharmony_ci            if (obj == nullptr) {
816e509ee18Sopenharmony_ci                error += "'arguments' items CallArgument is invaild;";
817e509ee18Sopenharmony_ci                break;
818e509ee18Sopenharmony_ci            } else {
819e509ee18Sopenharmony_ci                callArgument.emplace_back(std::move(obj));
820e509ee18Sopenharmony_ci            }
821e509ee18Sopenharmony_ci        }
822e509ee18Sopenharmony_ci        if (callArgument.size()) {
823e509ee18Sopenharmony_ci            paramsObject->arguments_ = std::move(callArgument);
824e509ee18Sopenharmony_ci        }
825e509ee18Sopenharmony_ci    } else if (ret == Result::TYPE_ERROR) {
826e509ee18Sopenharmony_ci        error += "Wrong type of 'arguments';";
827e509ee18Sopenharmony_ci    }
828e509ee18Sopenharmony_ci    // paramsObject->silent_
829e509ee18Sopenharmony_ci    bool silent = false;
830e509ee18Sopenharmony_ci    ret = params.GetBool("silent", &silent);
831e509ee18Sopenharmony_ci    if (ret == Result::SUCCESS) {
832e509ee18Sopenharmony_ci        paramsObject->silent_ = silent;
833e509ee18Sopenharmony_ci    } else if (ret == Result::TYPE_ERROR) {
834e509ee18Sopenharmony_ci        error += "Wrong type of 'silent';";
835e509ee18Sopenharmony_ci    }
836e509ee18Sopenharmony_ci    // paramsObject->returnByValue_
837e509ee18Sopenharmony_ci    bool returnByValue = false;
838e509ee18Sopenharmony_ci    ret = params.GetBool("returnByValue", &returnByValue);
839e509ee18Sopenharmony_ci    if (ret == Result::SUCCESS) {
840e509ee18Sopenharmony_ci        paramsObject->returnByValue_ = returnByValue;
841e509ee18Sopenharmony_ci    } else if (ret == Result::TYPE_ERROR) {
842e509ee18Sopenharmony_ci        error += "Wrong type of 'returnByValue';";
843e509ee18Sopenharmony_ci    }
844e509ee18Sopenharmony_ci    // paramsObject->generatePreview_
845e509ee18Sopenharmony_ci    bool generatePreview = false;
846e509ee18Sopenharmony_ci    ret = params.GetBool("generatePreview", &generatePreview);
847e509ee18Sopenharmony_ci    if (ret == Result::SUCCESS) {
848e509ee18Sopenharmony_ci        paramsObject->generatePreview_ = generatePreview;
849e509ee18Sopenharmony_ci    } else if (ret == Result::TYPE_ERROR) {
850e509ee18Sopenharmony_ci        error += "Wrong type of 'generatePreview';";
851e509ee18Sopenharmony_ci    }
852e509ee18Sopenharmony_ci    // paramsObject->userGesture_
853e509ee18Sopenharmony_ci    bool userGesture = false;
854e509ee18Sopenharmony_ci    ret = params.GetBool("userGesture", &userGesture);
855e509ee18Sopenharmony_ci    if (ret == Result::SUCCESS) {
856e509ee18Sopenharmony_ci        paramsObject->userGesture_ = userGesture;
857e509ee18Sopenharmony_ci    } else if (ret == Result::TYPE_ERROR) {
858e509ee18Sopenharmony_ci        error += "Wrong type of 'userGesture';";
859e509ee18Sopenharmony_ci    }
860e509ee18Sopenharmony_ci    // paramsObject->awaitPromise_
861e509ee18Sopenharmony_ci    bool awaitPromise = false;
862e509ee18Sopenharmony_ci    ret = params.GetBool("awaitPromise", &awaitPromise);
863e509ee18Sopenharmony_ci    if (ret == Result::SUCCESS) {
864e509ee18Sopenharmony_ci        paramsObject->awaitPromise_ = awaitPromise;
865e509ee18Sopenharmony_ci    } else if (ret == Result::TYPE_ERROR) {
866e509ee18Sopenharmony_ci        error += "Wrong type of 'awaitPromise';";
867e509ee18Sopenharmony_ci    }
868e509ee18Sopenharmony_ci    // paramsObject->executionContextId_
869e509ee18Sopenharmony_ci    int32_t executionContextId;
870e509ee18Sopenharmony_ci    ret = params.GetInt("executionContextId", &executionContextId);
871e509ee18Sopenharmony_ci    if (ret == Result::SUCCESS) {
872e509ee18Sopenharmony_ci        paramsObject->executionContextId_ = executionContextId;
873e509ee18Sopenharmony_ci    } else if (ret == Result::TYPE_ERROR) {
874e509ee18Sopenharmony_ci        error += "Wrong type of 'executionContextId';";
875e509ee18Sopenharmony_ci    }
876e509ee18Sopenharmony_ci    // paramsObject->objectGroup_
877e509ee18Sopenharmony_ci    std::string objectGroup;
878e509ee18Sopenharmony_ci    ret = params.GetString("objectGroup", &objectGroup);
879e509ee18Sopenharmony_ci    if (ret == Result::SUCCESS) {
880e509ee18Sopenharmony_ci        paramsObject->objectGroup_ = std::move(objectGroup);
881e509ee18Sopenharmony_ci    } else if (ret == Result::TYPE_ERROR) {
882e509ee18Sopenharmony_ci        error += "Wrong type of 'objectGroup';";
883e509ee18Sopenharmony_ci    }
884e509ee18Sopenharmony_ci    // paramsObject->throwOnSideEffect_
885e509ee18Sopenharmony_ci    bool throwOnSideEffect = false;
886e509ee18Sopenharmony_ci    ret = params.GetBool("throwOnSideEffect", &throwOnSideEffect);
887e509ee18Sopenharmony_ci    if (ret == Result::SUCCESS) {
888e509ee18Sopenharmony_ci        paramsObject->throwOnSideEffect_ = throwOnSideEffect;
889e509ee18Sopenharmony_ci    } else if (ret == Result::TYPE_ERROR) {
890e509ee18Sopenharmony_ci        error += "Wrong type of 'throwOnSideEffect';";
891e509ee18Sopenharmony_ci    }
892e509ee18Sopenharmony_ci
893e509ee18Sopenharmony_ci    // Check whether the error is empty.
894e509ee18Sopenharmony_ci    if (!error.empty()) {
895e509ee18Sopenharmony_ci        LOG_DEBUGGER(ERROR) << "CallFunctionOnParams::Create " << error;
896e509ee18Sopenharmony_ci        return nullptr;
897e509ee18Sopenharmony_ci    }
898e509ee18Sopenharmony_ci
899e509ee18Sopenharmony_ci    return paramsObject;
900e509ee18Sopenharmony_ci}
901e509ee18Sopenharmony_ci
902e509ee18Sopenharmony_cistd::unique_ptr<StartSamplingParams> StartSamplingParams::Create(const PtJson &params)
903e509ee18Sopenharmony_ci{
904e509ee18Sopenharmony_ci    auto paramsObject = std::make_unique<StartSamplingParams>();
905e509ee18Sopenharmony_ci    std::string error;
906e509ee18Sopenharmony_ci    Result ret;
907e509ee18Sopenharmony_ci
908e509ee18Sopenharmony_ci    double samplingInterval;
909e509ee18Sopenharmony_ci    ret = params.GetDouble("samplingInterval", &samplingInterval);
910e509ee18Sopenharmony_ci    if (ret == Result::SUCCESS) {
911e509ee18Sopenharmony_ci        if (samplingInterval <= 0) {
912e509ee18Sopenharmony_ci            error += "Invalid SamplingInterval";
913e509ee18Sopenharmony_ci        } else {
914e509ee18Sopenharmony_ci            paramsObject->samplingInterval_ = samplingInterval;
915e509ee18Sopenharmony_ci        }
916e509ee18Sopenharmony_ci    } else if (ret == Result::TYPE_ERROR) {
917e509ee18Sopenharmony_ci        error += "Wrong type of 'samplingInterval';";
918e509ee18Sopenharmony_ci    }
919e509ee18Sopenharmony_ci
920e509ee18Sopenharmony_ci    if (!error.empty()) {
921e509ee18Sopenharmony_ci        LOG_DEBUGGER(ERROR) << "StartSamplingParams::Create " << error;
922e509ee18Sopenharmony_ci        return nullptr;
923e509ee18Sopenharmony_ci    }
924e509ee18Sopenharmony_ci    return paramsObject;
925e509ee18Sopenharmony_ci}
926e509ee18Sopenharmony_ci
927e509ee18Sopenharmony_cistd::unique_ptr<StartTrackingHeapObjectsParams> StartTrackingHeapObjectsParams::Create(const PtJson &params)
928e509ee18Sopenharmony_ci{
929e509ee18Sopenharmony_ci    auto paramsObject = std::make_unique<StartTrackingHeapObjectsParams>();
930e509ee18Sopenharmony_ci    std::string error;
931e509ee18Sopenharmony_ci    Result ret;
932e509ee18Sopenharmony_ci
933e509ee18Sopenharmony_ci    bool trackAllocations = false;
934e509ee18Sopenharmony_ci    ret = params.GetBool("trackAllocations", &trackAllocations);
935e509ee18Sopenharmony_ci    if (ret == Result::SUCCESS) {
936e509ee18Sopenharmony_ci        paramsObject->trackAllocations_ = trackAllocations;
937e509ee18Sopenharmony_ci    } else if (ret == Result::TYPE_ERROR) {
938e509ee18Sopenharmony_ci        error += "Wrong type of 'trackAllocations';";
939e509ee18Sopenharmony_ci    }
940e509ee18Sopenharmony_ci
941e509ee18Sopenharmony_ci    if (!error.empty()) {
942e509ee18Sopenharmony_ci        LOG_DEBUGGER(ERROR) << "StartTrackingHeapObjectsParams::Create " << error;
943e509ee18Sopenharmony_ci        return nullptr;
944e509ee18Sopenharmony_ci    }
945e509ee18Sopenharmony_ci    return paramsObject;
946e509ee18Sopenharmony_ci}
947e509ee18Sopenharmony_ci
948e509ee18Sopenharmony_cistd::unique_ptr<StopTrackingHeapObjectsParams> StopTrackingHeapObjectsParams::Create(const PtJson &params)
949e509ee18Sopenharmony_ci{
950e509ee18Sopenharmony_ci    auto paramsObject = std::make_unique<StopTrackingHeapObjectsParams>();
951e509ee18Sopenharmony_ci    std::string error;
952e509ee18Sopenharmony_ci    Result ret;
953e509ee18Sopenharmony_ci
954e509ee18Sopenharmony_ci    bool reportProgress = false;
955e509ee18Sopenharmony_ci    ret = params.GetBool("reportProgress", &reportProgress);
956e509ee18Sopenharmony_ci    if (ret == Result::SUCCESS) {
957e509ee18Sopenharmony_ci        paramsObject->reportProgress_ = reportProgress;
958e509ee18Sopenharmony_ci    } else if (ret == Result::TYPE_ERROR) {
959e509ee18Sopenharmony_ci        error += "Wrong type of 'reportProgress';";
960e509ee18Sopenharmony_ci    }
961e509ee18Sopenharmony_ci
962e509ee18Sopenharmony_ci    bool treatGlobalObjectsAsRoots = false;
963e509ee18Sopenharmony_ci    ret = params.GetBool("treatGlobalObjectsAsRoots", &treatGlobalObjectsAsRoots);
964e509ee18Sopenharmony_ci    if (ret == Result::SUCCESS) {
965e509ee18Sopenharmony_ci        paramsObject->treatGlobalObjectsAsRoots_ = treatGlobalObjectsAsRoots;
966e509ee18Sopenharmony_ci    } else if (ret == Result::TYPE_ERROR) {
967e509ee18Sopenharmony_ci        error += "Wrong type of 'treatGlobalObjectsAsRoots';";
968e509ee18Sopenharmony_ci    }
969e509ee18Sopenharmony_ci
970e509ee18Sopenharmony_ci    bool captureNumericValue = false;
971e509ee18Sopenharmony_ci    ret = params.GetBool("captureNumericValue", &captureNumericValue);
972e509ee18Sopenharmony_ci    if (ret == Result::SUCCESS) {
973e509ee18Sopenharmony_ci        paramsObject->captureNumericValue_ = captureNumericValue;
974e509ee18Sopenharmony_ci    } else if (ret == Result::TYPE_ERROR) {
975e509ee18Sopenharmony_ci        error += "Wrong type of 'captureNumericValue';";
976e509ee18Sopenharmony_ci    }
977e509ee18Sopenharmony_ci
978e509ee18Sopenharmony_ci    if (!error.empty()) {
979e509ee18Sopenharmony_ci        LOG_DEBUGGER(ERROR) << "StopTrackingHeapObjectsParams::Create " << error;
980e509ee18Sopenharmony_ci        return nullptr;
981e509ee18Sopenharmony_ci    }
982e509ee18Sopenharmony_ci    return paramsObject;
983e509ee18Sopenharmony_ci}
984e509ee18Sopenharmony_ci
985e509ee18Sopenharmony_cistd::unique_ptr<AddInspectedHeapObjectParams> AddInspectedHeapObjectParams::Create(const PtJson &params)
986e509ee18Sopenharmony_ci{
987e509ee18Sopenharmony_ci    auto paramsObject = std::make_unique<AddInspectedHeapObjectParams>();
988e509ee18Sopenharmony_ci    std::string error;
989e509ee18Sopenharmony_ci    Result ret;
990e509ee18Sopenharmony_ci
991e509ee18Sopenharmony_ci    std::string heapObjectId;
992e509ee18Sopenharmony_ci    ret = params.GetString("heapObjectId", &heapObjectId);
993e509ee18Sopenharmony_ci    if (ret == Result::SUCCESS) {
994e509ee18Sopenharmony_ci        if (!ToolchainUtils::StrToInt32(heapObjectId, paramsObject->heapObjectId_)) {
995e509ee18Sopenharmony_ci            error += "Failed to convert 'heapObjectId' from string to int;";
996e509ee18Sopenharmony_ci        }
997e509ee18Sopenharmony_ci    } else {
998e509ee18Sopenharmony_ci        error += "Unknown or wrong type of 'heapObjectId';";
999e509ee18Sopenharmony_ci    }
1000e509ee18Sopenharmony_ci
1001e509ee18Sopenharmony_ci    if (!error.empty()) {
1002e509ee18Sopenharmony_ci        LOG_DEBUGGER(ERROR) << "AddInspectedHeapObjectParams::Create " << error;
1003e509ee18Sopenharmony_ci        return nullptr;
1004e509ee18Sopenharmony_ci    }
1005e509ee18Sopenharmony_ci    return paramsObject;
1006e509ee18Sopenharmony_ci}
1007e509ee18Sopenharmony_ci
1008e509ee18Sopenharmony_cistd::unique_ptr<GetHeapObjectIdParams> GetHeapObjectIdParams::Create(const PtJson &params)
1009e509ee18Sopenharmony_ci{
1010e509ee18Sopenharmony_ci    auto paramsObject = std::make_unique<GetHeapObjectIdParams>();
1011e509ee18Sopenharmony_ci    std::string error;
1012e509ee18Sopenharmony_ci    Result ret;
1013e509ee18Sopenharmony_ci
1014e509ee18Sopenharmony_ci    std::string objectId;
1015e509ee18Sopenharmony_ci    ret = params.GetString("objectId", &objectId);
1016e509ee18Sopenharmony_ci    if (ret == Result::SUCCESS) {
1017e509ee18Sopenharmony_ci        if (!ToolchainUtils::StrToInt32(objectId, paramsObject->objectId_)) {
1018e509ee18Sopenharmony_ci            error += "Failed to convert 'objectId' from string to int;";
1019e509ee18Sopenharmony_ci        }
1020e509ee18Sopenharmony_ci    } else if (ret == Result::TYPE_ERROR) {
1021e509ee18Sopenharmony_ci        error += "Wrong type of 'objectId';";
1022e509ee18Sopenharmony_ci    }
1023e509ee18Sopenharmony_ci
1024e509ee18Sopenharmony_ci    if (!error.empty()) {
1025e509ee18Sopenharmony_ci        LOG_DEBUGGER(ERROR) << "GetHeapObjectIdParams::Create " << error;
1026e509ee18Sopenharmony_ci        return nullptr;
1027e509ee18Sopenharmony_ci    }
1028e509ee18Sopenharmony_ci    return paramsObject;
1029e509ee18Sopenharmony_ci}
1030e509ee18Sopenharmony_ci
1031e509ee18Sopenharmony_cistd::unique_ptr<GetObjectByHeapObjectIdParams> GetObjectByHeapObjectIdParams::Create(const PtJson &params)
1032e509ee18Sopenharmony_ci{
1033e509ee18Sopenharmony_ci    auto paramsObject = std::make_unique<GetObjectByHeapObjectIdParams>();
1034e509ee18Sopenharmony_ci    std::string error;
1035e509ee18Sopenharmony_ci    Result ret;
1036e509ee18Sopenharmony_ci
1037e509ee18Sopenharmony_ci    std::string objectId;
1038e509ee18Sopenharmony_ci    ret = params.GetString("objectId", &objectId);
1039e509ee18Sopenharmony_ci    if (ret == Result::SUCCESS) {
1040e509ee18Sopenharmony_ci        if (!ToolchainUtils::StrToInt32(objectId, paramsObject->objectId_)) {
1041e509ee18Sopenharmony_ci            error += "Failed to convert 'objectId' from string to int;";
1042e509ee18Sopenharmony_ci        }
1043e509ee18Sopenharmony_ci    } else if (ret == Result::TYPE_ERROR) {
1044e509ee18Sopenharmony_ci        error += "Wrong type of 'objectId';";
1045e509ee18Sopenharmony_ci    }
1046e509ee18Sopenharmony_ci
1047e509ee18Sopenharmony_ci    std::string objectGroup;
1048e509ee18Sopenharmony_ci    ret = params.GetString("objectGroup", &objectGroup);
1049e509ee18Sopenharmony_ci    if (ret == Result::SUCCESS) {
1050e509ee18Sopenharmony_ci        paramsObject->objectGroup_ = std::move(objectGroup);
1051e509ee18Sopenharmony_ci    } else if (ret == Result::TYPE_ERROR) {
1052e509ee18Sopenharmony_ci        error += "Wrong type of 'objectGroup';";
1053e509ee18Sopenharmony_ci    }
1054e509ee18Sopenharmony_ci
1055e509ee18Sopenharmony_ci    if (!error.empty()) {
1056e509ee18Sopenharmony_ci        LOG_DEBUGGER(ERROR) << "GetObjectByHeapObjectIdParams::Create " << error;
1057e509ee18Sopenharmony_ci        return nullptr;
1058e509ee18Sopenharmony_ci    }
1059e509ee18Sopenharmony_ci    return paramsObject;
1060e509ee18Sopenharmony_ci}
1061e509ee18Sopenharmony_ci
1062e509ee18Sopenharmony_cistd::unique_ptr<StartPreciseCoverageParams> StartPreciseCoverageParams::Create(const PtJson &params)
1063e509ee18Sopenharmony_ci{
1064e509ee18Sopenharmony_ci    auto paramsObject = std::make_unique<StartPreciseCoverageParams>();
1065e509ee18Sopenharmony_ci    std::string error;
1066e509ee18Sopenharmony_ci    Result ret;
1067e509ee18Sopenharmony_ci
1068e509ee18Sopenharmony_ci    bool callCount = false;
1069e509ee18Sopenharmony_ci    ret = params.GetBool("callCount", &callCount);
1070e509ee18Sopenharmony_ci    if (ret == Result::SUCCESS) {
1071e509ee18Sopenharmony_ci        paramsObject->callCount_ = callCount;
1072e509ee18Sopenharmony_ci    } else if (ret == Result::TYPE_ERROR) {
1073e509ee18Sopenharmony_ci        error += "Wrong type of 'callCount';";
1074e509ee18Sopenharmony_ci    }
1075e509ee18Sopenharmony_ci
1076e509ee18Sopenharmony_ci    bool detailed = false;
1077e509ee18Sopenharmony_ci    ret = params.GetBool("detailed", &detailed);
1078e509ee18Sopenharmony_ci    if (ret == Result::SUCCESS) {
1079e509ee18Sopenharmony_ci        paramsObject->detailed_ = detailed;
1080e509ee18Sopenharmony_ci    } else if (ret == Result::TYPE_ERROR) {
1081e509ee18Sopenharmony_ci        error += "Wrong type of 'detailed';";
1082e509ee18Sopenharmony_ci    }
1083e509ee18Sopenharmony_ci
1084e509ee18Sopenharmony_ci    bool allowTriggeredUpdates = false;
1085e509ee18Sopenharmony_ci    ret = params.GetBool("allowTriggeredUpdates", &allowTriggeredUpdates);
1086e509ee18Sopenharmony_ci    if (ret == Result::SUCCESS) {
1087e509ee18Sopenharmony_ci        paramsObject->allowTriggeredUpdates_ = allowTriggeredUpdates;
1088e509ee18Sopenharmony_ci    } else if (ret == Result::TYPE_ERROR) {
1089e509ee18Sopenharmony_ci        error += "Wrong type of 'allowTriggeredUpdates';";
1090e509ee18Sopenharmony_ci    }
1091e509ee18Sopenharmony_ci
1092e509ee18Sopenharmony_ci    if (!error.empty()) {
1093e509ee18Sopenharmony_ci        LOG_DEBUGGER(ERROR) << "StartPreciseCoverageParams::Create " << error;
1094e509ee18Sopenharmony_ci        return nullptr;
1095e509ee18Sopenharmony_ci    }
1096e509ee18Sopenharmony_ci    return paramsObject;
1097e509ee18Sopenharmony_ci}
1098e509ee18Sopenharmony_ci
1099e509ee18Sopenharmony_cistd::unique_ptr<SetSamplingIntervalParams> SetSamplingIntervalParams::Create(const PtJson &params)
1100e509ee18Sopenharmony_ci{
1101e509ee18Sopenharmony_ci    auto paramsObject = std::make_unique<SetSamplingIntervalParams>();
1102e509ee18Sopenharmony_ci    std::string error;
1103e509ee18Sopenharmony_ci    Result ret;
1104e509ee18Sopenharmony_ci
1105e509ee18Sopenharmony_ci    int32_t interval = 0;
1106e509ee18Sopenharmony_ci    ret = params.GetInt("interval", &interval);
1107e509ee18Sopenharmony_ci    if (ret == Result::SUCCESS) {
1108e509ee18Sopenharmony_ci        paramsObject->interval_ = interval;
1109e509ee18Sopenharmony_ci    } else {
1110e509ee18Sopenharmony_ci        error += "Unknown or wrong type of 'interval';";
1111e509ee18Sopenharmony_ci    }
1112e509ee18Sopenharmony_ci
1113e509ee18Sopenharmony_ci    if (!error.empty()) {
1114e509ee18Sopenharmony_ci        LOG_DEBUGGER(ERROR) << "SetSamplingIntervalParams::Create " << error;
1115e509ee18Sopenharmony_ci        return nullptr;
1116e509ee18Sopenharmony_ci    }
1117e509ee18Sopenharmony_ci    return paramsObject;
1118e509ee18Sopenharmony_ci}
1119e509ee18Sopenharmony_ci
1120e509ee18Sopenharmony_cistd::unique_ptr<RecordClockSyncMarkerParams> RecordClockSyncMarkerParams::Create(const PtJson &params)
1121e509ee18Sopenharmony_ci{
1122e509ee18Sopenharmony_ci    std::string error;
1123e509ee18Sopenharmony_ci    auto recordClockSyncMarkerParams = std::make_unique<RecordClockSyncMarkerParams>();
1124e509ee18Sopenharmony_ci    Result ret;
1125e509ee18Sopenharmony_ci
1126e509ee18Sopenharmony_ci    std::string syncId;
1127e509ee18Sopenharmony_ci    ret = params.GetString("syncId", &syncId);
1128e509ee18Sopenharmony_ci    if (ret == Result::SUCCESS) {
1129e509ee18Sopenharmony_ci        recordClockSyncMarkerParams->syncId_ = syncId;
1130e509ee18Sopenharmony_ci    } else {
1131e509ee18Sopenharmony_ci        error += "Unknown or wrong type of 'syncId';";
1132e509ee18Sopenharmony_ci    }
1133e509ee18Sopenharmony_ci
1134e509ee18Sopenharmony_ci    if (!error.empty()) {
1135e509ee18Sopenharmony_ci        LOG_DEBUGGER(ERROR) << "RecordClockSyncMarkerParams::Create " << error;
1136e509ee18Sopenharmony_ci        return nullptr;
1137e509ee18Sopenharmony_ci    }
1138e509ee18Sopenharmony_ci
1139e509ee18Sopenharmony_ci    return recordClockSyncMarkerParams;
1140e509ee18Sopenharmony_ci}
1141e509ee18Sopenharmony_ci
1142e509ee18Sopenharmony_cistd::unique_ptr<RequestMemoryDumpParams> RequestMemoryDumpParams::Create(const PtJson &params)
1143e509ee18Sopenharmony_ci{
1144e509ee18Sopenharmony_ci    std::string error;
1145e509ee18Sopenharmony_ci    auto requestMemoryDumpParams = std::make_unique<RequestMemoryDumpParams>();
1146e509ee18Sopenharmony_ci    Result ret;
1147e509ee18Sopenharmony_ci
1148e509ee18Sopenharmony_ci    bool deterministic = false;
1149e509ee18Sopenharmony_ci    ret = params.GetBool("deterministic", &deterministic);
1150e509ee18Sopenharmony_ci    if (ret == Result::SUCCESS) {
1151e509ee18Sopenharmony_ci        requestMemoryDumpParams->deterministic_ = deterministic;
1152e509ee18Sopenharmony_ci    } else if (ret == Result::TYPE_ERROR) {
1153e509ee18Sopenharmony_ci        error += "Wrong type of 'deterministic';";
1154e509ee18Sopenharmony_ci    }
1155e509ee18Sopenharmony_ci
1156e509ee18Sopenharmony_ci    std::string levelOfDetail;
1157e509ee18Sopenharmony_ci    ret = params.GetString("levelOfDetail", &levelOfDetail);
1158e509ee18Sopenharmony_ci    if (ret == Result::SUCCESS) {
1159e509ee18Sopenharmony_ci        if (MemoryDumpLevelOfDetailValues::Valid(levelOfDetail)) {
1160e509ee18Sopenharmony_ci            requestMemoryDumpParams->levelOfDetail_ = std::move(levelOfDetail);
1161e509ee18Sopenharmony_ci        } else {
1162e509ee18Sopenharmony_ci            error += "'levelOfDetail' is invalid;";
1163e509ee18Sopenharmony_ci        }
1164e509ee18Sopenharmony_ci    } else if (ret == Result::TYPE_ERROR) {
1165e509ee18Sopenharmony_ci        error += "Wrong type of 'levelOfDetail';";
1166e509ee18Sopenharmony_ci    }
1167e509ee18Sopenharmony_ci
1168e509ee18Sopenharmony_ci    if (!error.empty()) {
1169e509ee18Sopenharmony_ci        LOG_DEBUGGER(ERROR) << "RequestMemoryDumpParams::Create " << error;
1170e509ee18Sopenharmony_ci        return nullptr;
1171e509ee18Sopenharmony_ci    }
1172e509ee18Sopenharmony_ci
1173e509ee18Sopenharmony_ci    return requestMemoryDumpParams;
1174e509ee18Sopenharmony_ci}
1175e509ee18Sopenharmony_ci
1176e509ee18Sopenharmony_cistd::unique_ptr<StartParams> StartParams::Create(const PtJson &params)
1177e509ee18Sopenharmony_ci{
1178e509ee18Sopenharmony_ci    std::string error;
1179e509ee18Sopenharmony_ci    auto startParams = std::make_unique<StartParams>();
1180e509ee18Sopenharmony_ci    Result ret;
1181e509ee18Sopenharmony_ci
1182e509ee18Sopenharmony_ci    std::string categories;
1183e509ee18Sopenharmony_ci    ret = params.GetString("categories", &categories);
1184e509ee18Sopenharmony_ci    if (ret == Result::SUCCESS) {
1185e509ee18Sopenharmony_ci        startParams->categories_ = std::move(categories);
1186e509ee18Sopenharmony_ci    } else if (ret == Result::TYPE_ERROR) {
1187e509ee18Sopenharmony_ci        error += "Wrong type of 'categories';";
1188e509ee18Sopenharmony_ci    }
1189e509ee18Sopenharmony_ci
1190e509ee18Sopenharmony_ci    std::string options;
1191e509ee18Sopenharmony_ci    ret = params.GetString("options", &options);
1192e509ee18Sopenharmony_ci    if (ret == Result::SUCCESS) {
1193e509ee18Sopenharmony_ci        startParams->options_ = std::move(options);
1194e509ee18Sopenharmony_ci    } else if (ret == Result::TYPE_ERROR) {
1195e509ee18Sopenharmony_ci        error += "Wrong type of 'options';";
1196e509ee18Sopenharmony_ci    }
1197e509ee18Sopenharmony_ci
1198e509ee18Sopenharmony_ci    int32_t bufferUsageReportingInterval = 0;
1199e509ee18Sopenharmony_ci    ret = params.GetInt("bufferUsageReportingInterval", &bufferUsageReportingInterval);
1200e509ee18Sopenharmony_ci    if (ret == Result::SUCCESS) {
1201e509ee18Sopenharmony_ci        startParams->bufferUsageReportingInterval_ = bufferUsageReportingInterval;
1202e509ee18Sopenharmony_ci    } else if (ret == Result::TYPE_ERROR) {
1203e509ee18Sopenharmony_ci        error += "Wrong type of 'bufferUsageReportingInterval';";
1204e509ee18Sopenharmony_ci    }
1205e509ee18Sopenharmony_ci
1206e509ee18Sopenharmony_ci    std::string transferMode;
1207e509ee18Sopenharmony_ci    ret = params.GetString("transferMode", &transferMode);
1208e509ee18Sopenharmony_ci    if (ret == Result::SUCCESS) {
1209e509ee18Sopenharmony_ci        if (StartParams::TransferModeValues::Valid(transferMode)) {
1210e509ee18Sopenharmony_ci            startParams->transferMode_ = std::move(transferMode);
1211e509ee18Sopenharmony_ci        } else {
1212e509ee18Sopenharmony_ci            error += "'transferMode' is invalid;";
1213e509ee18Sopenharmony_ci        }
1214e509ee18Sopenharmony_ci    } else if (ret == Result::TYPE_ERROR) {
1215e509ee18Sopenharmony_ci        error += "Wrong type of 'transferMode';";
1216e509ee18Sopenharmony_ci    }
1217e509ee18Sopenharmony_ci
1218e509ee18Sopenharmony_ci    std::string streamFormat;
1219e509ee18Sopenharmony_ci    ret = params.GetString("streamFormat", &streamFormat);
1220e509ee18Sopenharmony_ci    if (ret == Result::SUCCESS) {
1221e509ee18Sopenharmony_ci        if (StreamFormatValues::Valid(streamFormat)) {
1222e509ee18Sopenharmony_ci            startParams->streamFormat_ = std::move(streamFormat);
1223e509ee18Sopenharmony_ci        } else {
1224e509ee18Sopenharmony_ci            error += "'streamFormat' is invalid;";
1225e509ee18Sopenharmony_ci        }
1226e509ee18Sopenharmony_ci    } else if (ret == Result::TYPE_ERROR) {
1227e509ee18Sopenharmony_ci        error += "Wrong type of 'streamFormat';";
1228e509ee18Sopenharmony_ci    }
1229e509ee18Sopenharmony_ci
1230e509ee18Sopenharmony_ci    std::string streamCompression;
1231e509ee18Sopenharmony_ci    ret = params.GetString("streamCompression", &streamCompression);
1232e509ee18Sopenharmony_ci    if (ret == Result::SUCCESS) {
1233e509ee18Sopenharmony_ci        if (StreamCompressionValues::Valid(streamCompression)) {
1234e509ee18Sopenharmony_ci            startParams->streamCompression_ = std::move(streamCompression);
1235e509ee18Sopenharmony_ci        } else {
1236e509ee18Sopenharmony_ci            error += "'streamCompression' is invalid;";
1237e509ee18Sopenharmony_ci        }
1238e509ee18Sopenharmony_ci    } else if (ret == Result::TYPE_ERROR) {
1239e509ee18Sopenharmony_ci        error += "Wrong type of 'streamCompression';";
1240e509ee18Sopenharmony_ci    }
1241e509ee18Sopenharmony_ci
1242e509ee18Sopenharmony_ci    std::unique_ptr<PtJson> traceConfig;
1243e509ee18Sopenharmony_ci    ret = params.GetObject("traceConfig", &traceConfig);
1244e509ee18Sopenharmony_ci    if (ret == Result::SUCCESS) {
1245e509ee18Sopenharmony_ci        std::unique_ptr<TraceConfig> pTraceConfig = TraceConfig::Create(*traceConfig);
1246e509ee18Sopenharmony_ci        if (pTraceConfig == nullptr) {
1247e509ee18Sopenharmony_ci            error += "'traceConfig' format is invalid;";
1248e509ee18Sopenharmony_ci        } else {
1249e509ee18Sopenharmony_ci            startParams->traceConfig_ = std::move(pTraceConfig);
1250e509ee18Sopenharmony_ci        }
1251e509ee18Sopenharmony_ci    } else if (ret == Result::TYPE_ERROR) {
1252e509ee18Sopenharmony_ci        error += "Wrong type of 'traceConfig';";
1253e509ee18Sopenharmony_ci    }
1254e509ee18Sopenharmony_ci
1255e509ee18Sopenharmony_ci    std::string perfettoConfig;
1256e509ee18Sopenharmony_ci    ret = params.GetString("perfettoConfig", &perfettoConfig);
1257e509ee18Sopenharmony_ci    if (ret == Result::SUCCESS) {
1258e509ee18Sopenharmony_ci        startParams->perfettoConfig_ = std::move(perfettoConfig);
1259e509ee18Sopenharmony_ci    } else if (ret == Result::TYPE_ERROR) {
1260e509ee18Sopenharmony_ci        error += "Wrong type of 'perfettoConfig';";
1261e509ee18Sopenharmony_ci    }
1262e509ee18Sopenharmony_ci
1263e509ee18Sopenharmony_ci    std::string tracingBackend;
1264e509ee18Sopenharmony_ci    ret = params.GetString("tracingBackend", &tracingBackend);
1265e509ee18Sopenharmony_ci    if (ret == Result::SUCCESS) {
1266e509ee18Sopenharmony_ci        if (TracingBackendValues::Valid(tracingBackend)) {
1267e509ee18Sopenharmony_ci            startParams->tracingBackend_ = std::move(tracingBackend);
1268e509ee18Sopenharmony_ci        } else {
1269e509ee18Sopenharmony_ci            error += "'tracingBackend' is invalid;";
1270e509ee18Sopenharmony_ci        }
1271e509ee18Sopenharmony_ci    } else if (ret == Result::TYPE_ERROR) {
1272e509ee18Sopenharmony_ci        error += "Wrong type of 'tracingBackend';";
1273e509ee18Sopenharmony_ci    }
1274e509ee18Sopenharmony_ci
1275e509ee18Sopenharmony_ci    if (!error.empty()) {
1276e509ee18Sopenharmony_ci        LOG_DEBUGGER(ERROR) << "StartParams::Create " << error;
1277e509ee18Sopenharmony_ci        return nullptr;
1278e509ee18Sopenharmony_ci    }
1279e509ee18Sopenharmony_ci
1280e509ee18Sopenharmony_ci    return startParams;
1281e509ee18Sopenharmony_ci}
1282e509ee18Sopenharmony_ci
1283e509ee18Sopenharmony_cistd::unique_ptr<SeriliazationTimeoutCheckEnableParams> SeriliazationTimeoutCheckEnableParams::Create
1284e509ee18Sopenharmony_ci    (const PtJson &params)
1285e509ee18Sopenharmony_ci{
1286e509ee18Sopenharmony_ci    auto paramsObject = std::make_unique<SeriliazationTimeoutCheckEnableParams>();
1287e509ee18Sopenharmony_ci    std::string error;
1288e509ee18Sopenharmony_ci    Result ret;
1289e509ee18Sopenharmony_ci
1290e509ee18Sopenharmony_ci    int32_t threshold = 0;
1291e509ee18Sopenharmony_ci    ret = params.GetInt("threshold", &threshold);
1292e509ee18Sopenharmony_ci    if (ret == Result::SUCCESS) {
1293e509ee18Sopenharmony_ci        paramsObject->threshold_ = threshold;
1294e509ee18Sopenharmony_ci    } else {
1295e509ee18Sopenharmony_ci        error += "Unknown or wrong type of 'threshold';";
1296e509ee18Sopenharmony_ci    }
1297e509ee18Sopenharmony_ci
1298e509ee18Sopenharmony_ci    if (!error.empty()) {
1299e509ee18Sopenharmony_ci        LOG_DEBUGGER(ERROR) << "SeriliazationTimeoutCheckEnableParams::Create " << error;
1300e509ee18Sopenharmony_ci        return nullptr;
1301e509ee18Sopenharmony_ci    }
1302e509ee18Sopenharmony_ci    return paramsObject;
1303e509ee18Sopenharmony_ci}
1304e509ee18Sopenharmony_ci}  // namespace panda::ecmascript::tooling
1305