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