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 "base/pt_params.h"
17
18 namespace panda::ecmascript::tooling {
Create(const PtJson & params)19 std::unique_ptr<EnableParams> EnableParams::Create(const PtJson ¶ms)
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) { // optional value
30 error += "Unknown 'maxScriptsCacheSize';";
31 }
32
33 if (!error.empty()) {
34 LOG_DEBUGGER(ERROR) << "EnableParams::Create " << error;
35 return nullptr;
36 }
37
38 return paramsObject;
39 }
40
Create(const PtJson & params)41 std::unique_ptr<EvaluateOnCallFrameParams> EvaluateOnCallFrameParams::Create(const PtJson ¶ms)
42 {
43 auto paramsObject = std::make_unique<EvaluateOnCallFrameParams>();
44 std::string error;
45 Result ret;
46
47 std::string callFrameId;
48 ret = params.GetString("callFrameId", &callFrameId);
49 if (ret == Result::SUCCESS) {
50 paramsObject->callFrameId_ = std::stoi(callFrameId);
51 } else {
52 error += "Unknown 'callFrameId';";
53 }
54 std::string expression;
55 ret = params.GetString("expression", &expression);
56 if (ret == Result::SUCCESS) {
57 paramsObject->expression_ = std::move(expression);
58 } else {
59 error += "Unknown 'expression';";
60 }
61 std::string objectGroup;
62 ret = params.GetString("objectGroup", &objectGroup);
63 if (ret == Result::SUCCESS) {
64 paramsObject->objectGroup_ = std::move(objectGroup);
65 } else if (ret == Result::TYPE_ERROR) { // optional value
66 error += "Unknown 'objectGroup';";
67 }
68 bool includeCommandLineAPI = false;
69 ret = params.GetBool("includeCommandLineAPI", &includeCommandLineAPI);
70 if (ret == Result::SUCCESS) {
71 paramsObject->includeCommandLineAPI_ = includeCommandLineAPI;
72 } else if (ret == Result::TYPE_ERROR) { // optional value
73 error += "Unknown 'includeCommandLineAPI';";
74 }
75 bool silent = false;
76 ret = params.GetBool("silent", &silent);
77 if (ret == Result::SUCCESS) {
78 paramsObject->silent_ = silent;
79 } else if (ret == Result::TYPE_ERROR) { // optional value
80 error += "Unknown 'silent';";
81 }
82 bool returnByValue = false;
83 ret = params.GetBool("returnByValue", &returnByValue);
84 if (ret == Result::SUCCESS) {
85 paramsObject->returnByValue_ = returnByValue;
86 } else if (ret == Result::TYPE_ERROR) { // optional value
87 error += "Unknown 'returnByValue';";
88 }
89 bool generatePreview = false;
90 ret = params.GetBool("generatePreview", &generatePreview);
91 if (ret == Result::SUCCESS) {
92 paramsObject->generatePreview_ = generatePreview;
93 } else if (ret == Result::TYPE_ERROR) { // optional value
94 error += "Unknown 'generatePreview';";
95 }
96 bool throwOnSideEffect = false;
97 ret = params.GetBool("throwOnSideEffect", &throwOnSideEffect);
98 if (ret == Result::SUCCESS) {
99 paramsObject->throwOnSideEffect_ = throwOnSideEffect;
100 } else if (ret == Result::TYPE_ERROR) { // optional value
101 error += "Unknown 'throwOnSideEffect';";
102 }
103
104 if (!error.empty()) {
105 LOG_DEBUGGER(ERROR) << "EvaluateOnCallFrameParams::Create " << error;
106 return nullptr;
107 }
108 return paramsObject;
109 }
110
Create(const PtJson & params)111 std::unique_ptr<GetPossibleBreakpointsParams> GetPossibleBreakpointsParams::Create(const PtJson ¶ms)
112 {
113 auto paramsObject = std::make_unique<GetPossibleBreakpointsParams>();
114 std::string error;
115 Result ret;
116
117 std::unique_ptr<PtJson> start;
118 ret = params.GetObject("start", &start);
119 if (ret == Result::SUCCESS) {
120 std::unique_ptr<Location> location = Location::Create(*start);
121 if (location == nullptr) {
122 error += "Unknown 'start';";
123 } else {
124 paramsObject->start_ = std::move(location);
125 }
126 } else {
127 error += "Unknown 'start';";
128 }
129 std::unique_ptr<PtJson> end;
130 ret = params.GetObject("end", &end);
131 if (ret == Result::SUCCESS) {
132 std::unique_ptr<Location> location = Location::Create(*end);
133 if (location == nullptr) {
134 error += "Unknown 'end';";
135 } else {
136 paramsObject->end_ = std::move(location);
137 }
138 } else if (ret == Result::TYPE_ERROR) { // optional value
139 error += "Unknown 'end';";
140 }
141 bool restrictToFunction = false;
142 ret = params.GetBool("restrictToFunction", &restrictToFunction);
143 if (ret == Result::SUCCESS) {
144 paramsObject->restrictToFunction_ = restrictToFunction;
145 } else if (ret == Result::TYPE_ERROR) { // optional value
146 error += "Unknown 'restrictToFunction';";
147 }
148
149 if (!error.empty()) {
150 LOG_DEBUGGER(ERROR) << "GetPossibleBreakpointsParams::Create " << error;
151 return nullptr;
152 }
153
154 return paramsObject;
155 }
156
Create(const PtJson & params)157 std::unique_ptr<GetScriptSourceParams> GetScriptSourceParams::Create(const PtJson ¶ms)
158 {
159 auto paramsObject = std::make_unique<GetScriptSourceParams>();
160 std::string error;
161 Result ret;
162
163 std::string scriptId;
164 ret = params.GetString("scriptId", &scriptId);
165 if (ret == Result::SUCCESS) {
166 paramsObject->scriptId_ = std::stoi(scriptId);
167 } else {
168 error += "Unknown 'scriptId';";
169 }
170
171 if (!error.empty()) {
172 LOG_DEBUGGER(ERROR) << "GetScriptSourceParams::Create " << error;
173 return nullptr;
174 }
175
176 return paramsObject;
177 }
178
Create(const PtJson & params)179 std::unique_ptr<RemoveBreakpointParams> RemoveBreakpointParams::Create(const PtJson ¶ms)
180 {
181 auto paramsObject = std::make_unique<RemoveBreakpointParams>();
182 std::string error;
183 Result ret;
184
185 std::string breakpointId;
186 ret = params.GetString("breakpointId", &breakpointId);
187 if (ret == Result::SUCCESS) {
188 paramsObject->breakpointId_ = std::move(breakpointId);
189 } else {
190 error += "Unknown 'breakpointId';";
191 }
192
193 if (!error.empty()) {
194 LOG_DEBUGGER(ERROR) << "RemoveBreakpointParams::Create " << error;
195 return nullptr;
196 }
197
198 return paramsObject;
199 }
200
Create(const PtJson & params)201 std::unique_ptr<ResumeParams> ResumeParams::Create(const PtJson ¶ms)
202 {
203 auto paramsObject = std::make_unique<ResumeParams>();
204 std::string error;
205 Result ret;
206
207 bool terminateOnResume = false;
208 ret = params.GetBool("terminateOnResume", &terminateOnResume);
209 if (ret == Result::SUCCESS) {
210 paramsObject->terminateOnResume_ = terminateOnResume;
211 } else if (ret == Result::TYPE_ERROR) { // optional value
212 error += "Unknown 'terminateOnResume';";
213 }
214
215 if (!error.empty()) {
216 LOG_DEBUGGER(ERROR) << "ResumeParams::Create " << error;
217 return nullptr;
218 }
219
220 return paramsObject;
221 }
222
Create(const PtJson & params)223 std::unique_ptr<SetAsyncCallStackDepthParams> SetAsyncCallStackDepthParams::Create(const PtJson ¶ms)
224 {
225 auto paramsObject = std::make_unique<SetAsyncCallStackDepthParams>();
226 std::string error;
227 Result ret;
228
229 int32_t maxDepth;
230 ret = params.GetInt("maxDepth", &maxDepth);
231 if (ret == Result::SUCCESS) {
232 paramsObject->maxDepth_ = maxDepth;
233 } else {
234 error += "Unknown 'maxDepth';";
235 }
236
237 if (!error.empty()) {
238 LOG_DEBUGGER(ERROR) << "SetAsyncCallStackDepthParams::Create " << error;
239 return nullptr;
240 }
241
242 return paramsObject;
243 }
244
Create(const PtJson & params)245 std::unique_ptr<SetBlackboxPatternsParams> SetBlackboxPatternsParams::Create(const PtJson ¶ms)
246 {
247 auto paramsObject = std::make_unique<SetBlackboxPatternsParams>();
248 std::string error;
249 Result ret;
250
251 std::unique_ptr<PtJson> patterns;
252 ret = params.GetArray("patterns", &patterns);
253 if (ret == Result::SUCCESS) {
254 int32_t len = patterns->GetSize();
255 for (int32_t i = 0; i < len; ++i) {
256 std::unique_ptr<PtJson> item = patterns->Get(i);
257 if (item->IsString()) {
258 paramsObject->patterns_.emplace_back(item->GetString());
259 } else {
260 error += "'patterns' items should be a String;";
261 }
262 }
263 } else {
264 error += "Unknown 'patterns';";
265 }
266
267 if (!error.empty()) {
268 LOG_DEBUGGER(ERROR) << "SetBlackboxPatternsParams::Create " << error;
269 return nullptr;
270 }
271
272 return paramsObject;
273 }
274
Create(const PtJson & params)275 std::unique_ptr<SetBreakpointByUrlParams> SetBreakpointByUrlParams::Create(const PtJson ¶ms)
276 {
277 auto paramsObject = std::make_unique<SetBreakpointByUrlParams>();
278 std::string error;
279 Result ret;
280
281 int32_t lineNumber;
282 ret = params.GetInt("lineNumber", &lineNumber);
283 if (ret == Result::SUCCESS) {
284 paramsObject->lineNumber_ = lineNumber;
285 } else {
286 error += "Unknown 'lineNumber';";
287 }
288 std::string url;
289 ret = params.GetString("url", &url);
290 if (ret == Result::SUCCESS) {
291 paramsObject->url_ = std::move(url);
292 } else if (ret == Result::TYPE_ERROR) { // optional value
293 error += "Unknown 'url';";
294 }
295 std::string urlRegex;
296 ret = params.GetString("urlRegex", &urlRegex);
297 if (ret == Result::SUCCESS) {
298 paramsObject->urlRegex_ = std::move(urlRegex);
299 } else if (ret == Result::TYPE_ERROR) { // optional value
300 error += "Unknown 'urlRegex';";
301 }
302 std::string scriptHash;
303 ret = params.GetString("scriptHash", &scriptHash);
304 if (ret == Result::SUCCESS) {
305 paramsObject->scriptHash_ = std::move(scriptHash);
306 } else if (ret == Result::TYPE_ERROR) { // optional value
307 error += "Unknown 'scriptHash';";
308 }
309 int32_t columnNumber;
310 ret = params.GetInt("columnNumber", &columnNumber);
311 if (ret == Result::SUCCESS) {
312 paramsObject->columnNumber_ = columnNumber;
313 } else if (ret == Result::TYPE_ERROR) { // optional value
314 error += "Unknown 'columnNumber';";
315 }
316 std::string condition;
317 ret = params.GetString("condition", &condition);
318 if (ret == Result::SUCCESS) {
319 paramsObject->condition_ = std::move(condition);
320 } else if (ret == Result::TYPE_ERROR) { // optional value
321 error += "Unknown 'condition';";
322 }
323 if (!error.empty()) {
324 LOG_DEBUGGER(ERROR) << "SetBreakpointByUrlParams::Create " << error;
325 return nullptr;
326 }
327
328 return paramsObject;
329 }
330
Create(const PtJson & params)331 std::unique_ptr<SetPauseOnExceptionsParams> SetPauseOnExceptionsParams::Create(const PtJson ¶ms)
332 {
333 auto paramsObject = std::make_unique<SetPauseOnExceptionsParams>();
334 std::string error;
335 Result ret;
336
337 std::string state;
338 ret = params.GetString("state", &state);
339 if (ret == Result::SUCCESS) {
340 paramsObject->StoreState(state);
341 } else {
342 error += "Unknown 'state';";
343 }
344
345 if (!error.empty()) {
346 LOG_DEBUGGER(ERROR) << "SetPauseOnExceptionsParams::Create " << error;
347 return nullptr;
348 }
349
350 return paramsObject;
351 }
352
Create(const PtJson & params)353 std::unique_ptr<StepIntoParams> StepIntoParams::Create(const PtJson ¶ms)
354 {
355 auto paramsObject = std::make_unique<StepIntoParams>();
356 std::string error;
357 Result ret;
358
359 bool breakOnAsyncCall = false;
360 ret = params.GetBool("breakOnAsyncCall", &breakOnAsyncCall);
361 if (ret == Result::SUCCESS) {
362 paramsObject->breakOnAsyncCall_ = breakOnAsyncCall;
363 } else if (ret == Result::TYPE_ERROR) { // optional value
364 error += "Unknown 'breakOnAsyncCall';";
365 }
366 std::unique_ptr<PtJson> skipList;
367 ret = params.GetArray("skipList", &skipList);
368 if (ret == Result::SUCCESS) {
369 int32_t len = skipList->GetSize();
370 std::list<std::unique_ptr<LocationRange>> listLocation;
371 for (int32_t i = 0; i < len; ++i) {
372 std::unique_ptr<LocationRange> obj = LocationRange::Create(*skipList->Get(i));
373 if (obj == nullptr) {
374 error += "'skipList' items LocationRange is invalid;";
375 break;
376 } else {
377 listLocation.emplace_back(std::move(obj));
378 }
379 }
380 if (listLocation.size()) {
381 paramsObject->skipList_ = std::move(listLocation);
382 }
383 } else if (ret == Result::TYPE_ERROR) { // optional value
384 error += "Unknown 'skipList';";
385 }
386
387 if (!error.empty()) {
388 LOG_DEBUGGER(ERROR) << "StepIntoParams::Create " << error;
389 return nullptr;
390 }
391
392 return paramsObject;
393 }
394
Create(const PtJson & params)395 std::unique_ptr<StepOverParams> StepOverParams::Create(const PtJson ¶ms)
396 {
397 auto paramsObject = std::make_unique<StepOverParams>();
398 std::string error;
399 Result ret;
400
401 std::unique_ptr<PtJson> skipList;
402 ret = params.GetArray("skipList", &skipList);
403 if (ret == Result::SUCCESS) {
404 int32_t len = skipList->GetSize();
405 std::list<std::unique_ptr<LocationRange>> listLocation;
406 for (int32_t i = 0; i < len; ++i) {
407 std::unique_ptr<LocationRange> obj = LocationRange::Create(*skipList->Get(i));
408 if (obj == nullptr) {
409 error += "'skipList' items LocationRange is invalid;";
410 break;
411 } else {
412 listLocation.emplace_back(std::move(obj));
413 }
414 }
415 if (listLocation.size()) {
416 paramsObject->skipList_ = std::move(listLocation);
417 }
418 } else if (ret == Result::TYPE_ERROR) { // optional value
419 error += "Unknown 'skipList';";
420 }
421
422 if (!error.empty()) {
423 LOG_DEBUGGER(ERROR) << "StepOverParams::Create " << error;
424 return nullptr;
425 }
426
427 return paramsObject;
428 }
429
Create(const PtJson & params)430 std::unique_ptr<SetMixedDebugParams> SetMixedDebugParams::Create(const PtJson ¶ms)
431 {
432 auto paramsObject = std::make_unique<SetMixedDebugParams>();
433 std::string error;
434 Result ret;
435
436 bool enabled = false;
437 ret = params.GetBool("enabled", &enabled);
438 if (ret == Result::SUCCESS) {
439 paramsObject->enabled_ = enabled;
440 } else if (ret == Result::TYPE_ERROR) { // optional value
441 error += "Unknown 'enabled';";
442 }
443
444 if (!error.empty()) {
445 LOG_DEBUGGER(ERROR) << "SetMixedDebugParams::Create " << error;
446 return nullptr;
447 }
448
449 return paramsObject;
450 }
451
Create(const PtJson & params)452 std::unique_ptr<ReplyNativeCallingParams> ReplyNativeCallingParams::Create(const PtJson ¶ms)
453 {
454 auto paramsObject = std::make_unique<ReplyNativeCallingParams>();
455 std::string error;
456 Result ret;
457
458 bool userCode = false;
459 ret = params.GetBool("userCode", &userCode);
460 if (ret == Result::SUCCESS) {
461 paramsObject->userCode_ = userCode;
462 } else if (ret == Result::TYPE_ERROR) { // optional value
463 error += "Unknown 'userCode';";
464 }
465
466 if (!error.empty()) {
467 LOG_DEBUGGER(ERROR) << "ReplyNativeCallingParams::Create " << error;
468 return nullptr;
469 }
470
471 return paramsObject;
472 }
473
Create(const PtJson & params)474 std::unique_ptr<GetPropertiesParams> GetPropertiesParams::Create(const PtJson ¶ms)
475 {
476 auto paramsObject = std::make_unique<GetPropertiesParams>();
477 std::string error;
478 Result ret;
479
480 std::string objectId;
481 ret = params.GetString("objectId", &objectId);
482 if (ret == Result::SUCCESS) {
483 paramsObject->objectId_ = std::stoi(objectId);
484 } else {
485 error += "Unknown 'objectId';";
486 }
487 bool ownProperties = false;
488 ret = params.GetBool("ownProperties", &ownProperties);
489 if (ret == Result::SUCCESS) {
490 paramsObject->ownProperties_ = ownProperties;
491 } else if (ret == Result::TYPE_ERROR) { // optional value
492 error += "Unknown 'ownProperties';";
493 }
494 bool accessorPropertiesOnly = false;
495 ret = params.GetBool("accessorPropertiesOnly", &accessorPropertiesOnly);
496 if (ret == Result::SUCCESS) {
497 paramsObject->accessorPropertiesOnly_ = accessorPropertiesOnly;
498 } else if (ret == Result::TYPE_ERROR) { // optional value
499 error += "Unknown 'accessorPropertiesOnly';";
500 }
501 bool generatePreview = false;
502 ret = params.GetBool("generatePreview", &generatePreview);
503 if (ret == Result::SUCCESS) {
504 paramsObject->generatePreview_ = generatePreview;
505 } else if (ret == Result::TYPE_ERROR) { // optional value
506 error += "Unknown 'generatePreview';";
507 }
508 if (!error.empty()) {
509 LOG_DEBUGGER(ERROR) << "GetPropertiesParams::Create " << error;
510 return nullptr;
511 }
512
513 return paramsObject;
514 }
515
Create(const PtJson & params)516 std::unique_ptr<CallFunctionOnParams> CallFunctionOnParams::Create(const PtJson ¶ms)
517 {
518 auto paramsObject = std::make_unique<CallFunctionOnParams>();
519 std::string error;
520 Result ret;
521
522 // paramsObject->functionDeclaration_
523 std::string functionDeclaration;
524 ret = params.GetString("functionDeclaration", &functionDeclaration);
525 if (ret == Result::SUCCESS) {
526 paramsObject->functionDeclaration_ = std::move(functionDeclaration);
527 } else {
528 error += "Unknown 'functionDeclaration';";
529 }
530 // paramsObject->objectId_
531 std::string objectId;
532 ret = params.GetString("objectId", &objectId);
533 if (ret == Result::SUCCESS) {
534 paramsObject->objectId_ = std::stoi(objectId);
535 } else if (ret == Result::TYPE_ERROR) { // optional value
536 error += "Unknown 'objectId';";
537 }
538 // paramsObject->arguments_
539 std::unique_ptr<PtJson> arguments;
540 ret = params.GetArray("arguments", &arguments);
541 if (ret == Result::SUCCESS) {
542 int32_t len = arguments->GetSize();
543 std::vector<std::unique_ptr<CallArgument>> callArgument;
544 for (int32_t i = 0; i < len; ++i) {
545 std::unique_ptr<CallArgument> obj = CallArgument::Create(*arguments->Get(i));
546 if (obj == nullptr) {
547 error += "'arguments' items CallArgument is invaild;";
548 break;
549 } else {
550 callArgument.emplace_back(std::move(obj));
551 }
552 }
553 if (callArgument.size()) {
554 paramsObject->arguments_ = std::move(callArgument);
555 }
556 } else if (ret == Result::TYPE_ERROR) { // optional value
557 error += "Unknown 'arguments';";
558 }
559 // paramsObject->silent_
560 bool silent = false;
561 ret = params.GetBool("silent", &silent);
562 if (ret == Result::SUCCESS) {
563 paramsObject->silent_ = silent;
564 } else if (ret == Result::TYPE_ERROR) { // optional value
565 error += "Unknown 'silent';";
566 }
567 // paramsObject->returnByValue_
568 bool returnByValue = false;
569 ret = params.GetBool("returnByValue", &returnByValue);
570 if (ret == Result::SUCCESS) {
571 paramsObject->returnByValue_ = returnByValue;
572 } else if (ret == Result::TYPE_ERROR) { // optional value
573 error += "Unknown 'returnByValue';";
574 }
575 // paramsObject->generatePreview_
576 bool generatePreview = false;
577 ret = params.GetBool("generatePreview", &generatePreview);
578 if (ret == Result::SUCCESS) {
579 paramsObject->generatePreview_ = generatePreview;
580 } else if (ret == Result::TYPE_ERROR) { // optional value
581 error += "Unknown 'generatePreview';";
582 }
583 // paramsObject->userGesture_
584 bool userGesture = false;
585 ret = params.GetBool("userGesture", &userGesture);
586 if (ret == Result::SUCCESS) {
587 paramsObject->userGesture_ = userGesture;
588 } else if (ret == Result::TYPE_ERROR) { // optional value
589 error += "Unknown 'userGesture';";
590 }
591 // paramsObject->awaitPromise_
592 bool awaitPromise = false;
593 ret = params.GetBool("awaitPromise", &awaitPromise);
594 if (ret == Result::SUCCESS) {
595 paramsObject->awaitPromise_ = awaitPromise;
596 } else if (ret == Result::TYPE_ERROR) { // optional value
597 error += "Unknown 'awaitPromise';";
598 }
599 // paramsObject->executionContextId_
600 int32_t executionContextId;
601 ret = params.GetInt("executionContextId", &executionContextId);
602 if (ret == Result::SUCCESS) {
603 paramsObject->executionContextId_ = executionContextId;
604 } else if (ret == Result::TYPE_ERROR) { // optional value
605 error += "Unknown 'executionContextId';";
606 }
607 // paramsObject->objectGroup_
608 std::string objectGroup;
609 ret = params.GetString("objectGroup", &objectGroup);
610 if (ret == Result::SUCCESS) {
611 paramsObject->objectGroup_ = std::move(objectGroup);
612 } else if (ret == Result::TYPE_ERROR) { // optional value
613 error += "Unknown 'objectGroup';";
614 }
615 // paramsObject->throwOnSideEffect_
616 bool throwOnSideEffect = false;
617 ret = params.GetBool("throwOnSideEffect", &throwOnSideEffect);
618 if (ret == Result::SUCCESS) {
619 paramsObject->throwOnSideEffect_ = throwOnSideEffect;
620 } else if (ret == Result::TYPE_ERROR) { // optional value
621 error += "Unknown 'throwOnSideEffect';";
622 }
623
624 // Check whether the error is empty.
625 if (!error.empty()) {
626 LOG_DEBUGGER(ERROR) << "CallFunctionOnParams::Create " << error;
627 return nullptr;
628 }
629
630 return paramsObject;
631 }
632
Create(const PtJson & params)633 std::unique_ptr<StartSamplingParams> StartSamplingParams::Create(const PtJson ¶ms)
634 {
635 auto paramsObject = std::make_unique<StartSamplingParams>();
636 std::string error;
637 Result ret;
638
639 int32_t samplingInterval;
640 ret = params.GetInt("samplingInterval", &samplingInterval);
641 if (ret == Result::SUCCESS) {
642 paramsObject->samplingInterval_ = samplingInterval;
643 } else if (ret == Result::TYPE_ERROR) { // optional value
644 error += "Unknown 'samplingInterval';";
645 }
646
647 if (!error.empty()) {
648 LOG_DEBUGGER(ERROR) << "StartSamplingParams::Create " << error;
649 return nullptr;
650 }
651 return paramsObject;
652 }
653
Create(const PtJson & params)654 std::unique_ptr<StartTrackingHeapObjectsParams> StartTrackingHeapObjectsParams::Create(const PtJson ¶ms)
655 {
656 auto paramsObject = std::make_unique<StartTrackingHeapObjectsParams>();
657 std::string error;
658 Result ret;
659
660 bool trackAllocations = false;
661 ret = params.GetBool("trackAllocations", &trackAllocations);
662 if (ret == Result::SUCCESS) {
663 paramsObject->trackAllocations_ = trackAllocations;
664 } else if (ret == Result::TYPE_ERROR) { // optional value
665 error += "Unknown 'trackAllocations';";
666 }
667
668 if (!error.empty()) {
669 LOG_DEBUGGER(ERROR) << "StartTrackingHeapObjectsParams::Create " << error;
670 return nullptr;
671 }
672 return paramsObject;
673 }
674
Create(const PtJson & params)675 std::unique_ptr<StopTrackingHeapObjectsParams> StopTrackingHeapObjectsParams::Create(const PtJson ¶ms)
676 {
677 auto paramsObject = std::make_unique<StopTrackingHeapObjectsParams>();
678 std::string error;
679 Result ret;
680
681 bool reportProgress = false;
682 ret = params.GetBool("reportProgress", &reportProgress);
683 if (ret == Result::SUCCESS) {
684 paramsObject->reportProgress_ = reportProgress;
685 } else if (ret == Result::TYPE_ERROR) { // optional value
686 error += "Unknown 'reportProgress';";
687 }
688
689 bool treatGlobalObjectsAsRoots = false;
690 ret = params.GetBool("treatGlobalObjectsAsRoots", &treatGlobalObjectsAsRoots);
691 if (ret == Result::SUCCESS) {
692 paramsObject->treatGlobalObjectsAsRoots_ = treatGlobalObjectsAsRoots;
693 } else if (ret == Result::TYPE_ERROR) { // optional value
694 error += "Unknown 'treatGlobalObjectsAsRoots';";
695 }
696
697 bool captureNumericValue = false;
698 ret = params.GetBool("captureNumericValue", &captureNumericValue);
699 if (ret == Result::SUCCESS) {
700 paramsObject->captureNumericValue_ = captureNumericValue;
701 } else if (ret == Result::TYPE_ERROR) { // optional value
702 error += "Unknown 'captureNumericValue';";
703 }
704
705 if (!error.empty()) {
706 LOG_DEBUGGER(ERROR) << "StopTrackingHeapObjectsParams::Create " << error;
707 return nullptr;
708 }
709 return paramsObject;
710 }
711
Create(const PtJson & params)712 std::unique_ptr<AddInspectedHeapObjectParams> AddInspectedHeapObjectParams::Create(const PtJson ¶ms)
713 {
714 auto paramsObject = std::make_unique<AddInspectedHeapObjectParams>();
715 std::string error;
716 Result ret;
717
718 std::string heapObjectId;
719 ret = params.GetString("heapObjectId", &heapObjectId);
720 if (ret == Result::SUCCESS) {
721 paramsObject->heapObjectId_ = std::stoi(heapObjectId);
722 } else {
723 error += "Unknown 'heapObjectId';";
724 }
725
726 if (!error.empty()) {
727 LOG_DEBUGGER(ERROR) << "AddInspectedHeapObjectParams::Create " << error;
728 return nullptr;
729 }
730 return paramsObject;
731 }
732
Create(const PtJson & params)733 std::unique_ptr<GetHeapObjectIdParams> GetHeapObjectIdParams::Create(const PtJson ¶ms)
734 {
735 auto paramsObject = std::make_unique<GetHeapObjectIdParams>();
736 std::string error;
737 Result ret;
738
739 std::string objectId;
740 ret = params.GetString("objectId", &objectId);
741 if (ret == Result::SUCCESS) {
742 paramsObject->objectId_ = std::stoi(objectId);
743 } else if (ret == Result::TYPE_ERROR) { // optional value
744 error += "Unknown 'objectId';";
745 }
746
747 if (!error.empty()) {
748 LOG_DEBUGGER(ERROR) << "GetHeapObjectIdParams::Create " << error;
749 return nullptr;
750 }
751 return paramsObject;
752 }
753
Create(const PtJson & params)754 std::unique_ptr<GetObjectByHeapObjectIdParams> GetObjectByHeapObjectIdParams::Create(const PtJson ¶ms)
755 {
756 auto paramsObject = std::make_unique<GetObjectByHeapObjectIdParams>();
757 std::string error;
758 Result ret;
759
760 std::string objectId;
761 ret = params.GetString("objectId", &objectId);
762 if (ret == Result::SUCCESS) {
763 paramsObject->objectId_ = std::stoi(objectId);
764 } else if (ret == Result::TYPE_ERROR) { // optional value
765 error += "Unknown 'objectId';";
766 }
767
768 std::string objectGroup;
769 ret = params.GetString("objectGroup", &objectGroup);
770 if (ret == Result::SUCCESS) {
771 paramsObject->objectGroup_ = std::move(objectGroup);
772 } else if (ret == Result::TYPE_ERROR) { // optional value
773 error += "Unknown 'objectGroup';";
774 }
775
776 if (!error.empty()) {
777 LOG_DEBUGGER(ERROR) << "GetObjectByHeapObjectIdParams::Create " << error;
778 return nullptr;
779 }
780 return paramsObject;
781 }
782
Create(const PtJson & params)783 std::unique_ptr<StartPreciseCoverageParams> StartPreciseCoverageParams::Create(const PtJson ¶ms)
784 {
785 auto paramsObject = std::make_unique<StartPreciseCoverageParams>();
786 std::string error;
787 Result ret;
788
789 bool callCount = false;
790 ret = params.GetBool("callCount", &callCount);
791 if (ret == Result::SUCCESS) {
792 paramsObject->callCount_ = callCount;
793 } else if (ret == Result::TYPE_ERROR) { // optional value
794 error += "Unknown 'callCount';";
795 }
796
797 bool detailed = false;
798 ret = params.GetBool("detailed", &detailed);
799 if (ret == Result::SUCCESS) {
800 paramsObject->detailed_ = detailed;
801 } else if (ret == Result::TYPE_ERROR) { // optional value
802 error += "Unknown 'detailed';";
803 }
804
805 bool allowTriggeredUpdates = false;
806 ret = params.GetBool("allowTriggeredUpdates", &allowTriggeredUpdates);
807 if (ret == Result::SUCCESS) {
808 paramsObject->allowTriggeredUpdates_ = allowTriggeredUpdates;
809 } else if (ret == Result::TYPE_ERROR) { // optional value
810 error += "Unknown 'allowTriggeredUpdates';";
811 }
812
813 if (!error.empty()) {
814 LOG_DEBUGGER(ERROR) << "StartPreciseCoverageParams::Create " << error;
815 return nullptr;
816 }
817 return paramsObject;
818 }
819
Create(const PtJson & params)820 std::unique_ptr<SetSamplingIntervalParams> SetSamplingIntervalParams::Create(const PtJson ¶ms)
821 {
822 auto paramsObject = std::make_unique<SetSamplingIntervalParams>();
823 std::string error;
824 Result ret;
825
826 int32_t interval = 0;
827 ret = params.GetInt("interval", &interval);
828 if (ret == Result::SUCCESS) {
829 paramsObject->interval_ = interval;
830 } else {
831 error += "Unknown 'interval';";
832 }
833
834 if (!error.empty()) {
835 LOG_DEBUGGER(ERROR) << "SetSamplingIntervalParams::Create " << error;
836 return nullptr;
837 }
838 return paramsObject;
839 }
840
Create(const PtJson & params)841 std::unique_ptr<RecordClockSyncMarkerParams> RecordClockSyncMarkerParams::Create(const PtJson ¶ms)
842 {
843 std::string error;
844 auto recordClockSyncMarkerParams = std::make_unique<RecordClockSyncMarkerParams>();
845 Result ret;
846
847 std::string syncId;
848 ret = params.GetString("syncId", &syncId);
849 if (ret == Result::SUCCESS) {
850 recordClockSyncMarkerParams->syncId_ = syncId;
851 } else {
852 error += "Unknown 'syncId';";
853 }
854
855 if (!error.empty()) {
856 LOG_DEBUGGER(ERROR) << "RecordClockSyncMarkerParams::Create " << error;
857 return nullptr;
858 }
859
860 return recordClockSyncMarkerParams;
861 }
862
Create(const PtJson & params)863 std::unique_ptr<RequestMemoryDumpParams> RequestMemoryDumpParams::Create(const PtJson ¶ms)
864 {
865 std::string error;
866 auto requestMemoryDumpParams = std::make_unique<RequestMemoryDumpParams>();
867 Result ret;
868
869 bool deterministic = false;
870 ret = params.GetBool("deterministic", &deterministic);
871 if (ret == Result::SUCCESS) {
872 requestMemoryDumpParams->deterministic_ = deterministic;
873 } else if (ret == Result::TYPE_ERROR) {
874 error += "Unknown 'deterministic';";
875 }
876
877 std::string levelOfDetail;
878 ret = params.GetString("levelOfDetail", &levelOfDetail);
879 if (ret == Result::SUCCESS) {
880 if (MemoryDumpLevelOfDetailValues::Valid(levelOfDetail)) {
881 requestMemoryDumpParams->levelOfDetail_ = std::move(levelOfDetail);
882 } else {
883 error += "'levelOfDetail' is invalid;";
884 }
885 } else if (ret == Result::TYPE_ERROR) {
886 error += "Unknown 'levelOfDetail';";
887 }
888
889 if (!error.empty()) {
890 LOG_DEBUGGER(ERROR) << "RequestMemoryDumpParams::Create " << error;
891 return nullptr;
892 }
893
894 return requestMemoryDumpParams;
895 }
896
Create(const PtJson & params)897 std::unique_ptr<StartParams> StartParams::Create(const PtJson ¶ms)
898 {
899 std::string error;
900 auto startParams = std::make_unique<StartParams>();
901 Result ret;
902
903 std::string categories;
904 ret = params.GetString("categories", &categories);
905 if (ret == Result::SUCCESS) {
906 startParams->categories_ = std::move(categories);
907 } else if (ret == Result::TYPE_ERROR) {
908 error += "Unknown 'categories';";
909 }
910
911 std::string options;
912 ret = params.GetString("options", &options);
913 if (ret == Result::SUCCESS) {
914 startParams->options_ = std::move(options);
915 } else if (ret == Result::TYPE_ERROR) {
916 error += "Unknown 'options';";
917 }
918
919 int32_t bufferUsageReportingInterval = 0;
920 ret = params.GetInt("bufferUsageReportingInterval", &bufferUsageReportingInterval);
921 if (ret == Result::SUCCESS) {
922 startParams->bufferUsageReportingInterval_ = bufferUsageReportingInterval;
923 } else if (ret == Result::TYPE_ERROR) {
924 error += "Unknown 'bufferUsageReportingInterval';";
925 }
926
927 std::string transferMode;
928 ret = params.GetString("transferMode", &transferMode);
929 if (ret == Result::SUCCESS) {
930 if (StartParams::TransferModeValues::Valid(transferMode)) {
931 startParams->transferMode_ = std::move(transferMode);
932 } else {
933 error += "'transferMode' is invalid;";
934 }
935 } else if (ret == Result::TYPE_ERROR) {
936 error += "Unknown 'transferMode';";
937 }
938
939 std::string streamFormat;
940 ret = params.GetString("streamFormat", &streamFormat);
941 if (ret == Result::SUCCESS) {
942 if (StreamFormatValues::Valid(streamFormat)) {
943 startParams->streamFormat_ = std::move(streamFormat);
944 } else {
945 error += "'streamFormat' is invalid;";
946 }
947 } else if (ret == Result::TYPE_ERROR) {
948 error += "Unknown 'streamFormat';";
949 }
950
951 std::string streamCompression;
952 ret = params.GetString("streamCompression", &streamCompression);
953 if (ret == Result::SUCCESS) {
954 if (StreamCompressionValues::Valid(streamCompression)) {
955 startParams->streamCompression_ = std::move(streamCompression);
956 } else {
957 error += "'streamCompression' is invalid;";
958 }
959 } else if (ret == Result::TYPE_ERROR) {
960 error += "Unknown 'streamCompression';";
961 }
962
963 std::unique_ptr<PtJson> traceConfig;
964 ret = params.GetObject("traceConfig", &traceConfig);
965 if (ret == Result::SUCCESS) {
966 std::unique_ptr<TraceConfig> pTraceConfig = TraceConfig::Create(*traceConfig);
967 if (pTraceConfig == nullptr) {
968 error += "'traceConfig' format invalid;";
969 } else {
970 startParams->traceConfig_ = std::move(pTraceConfig);
971 }
972 } else if (ret == Result::TYPE_ERROR) {
973 error += "Unknown 'traceConfig';";
974 }
975
976 std::string perfettoConfig;
977 ret = params.GetString("perfettoConfig", &perfettoConfig);
978 if (ret == Result::SUCCESS) {
979 startParams->perfettoConfig_ = std::move(perfettoConfig);
980 } else if (ret == Result::TYPE_ERROR) {
981 error += "Unknown 'perfettoConfig';";
982 }
983
984 std::string tracingBackend;
985 ret = params.GetString("tracingBackend", &tracingBackend);
986 if (ret == Result::SUCCESS) {
987 if (TracingBackendValues::Valid(tracingBackend)) {
988 startParams->tracingBackend_ = std::move(tracingBackend);
989 } else {
990 error += "'tracingBackend' is invalid;";
991 }
992 } else if (ret == Result::TYPE_ERROR) {
993 error += "Unknown 'tracingBackend';";
994 }
995
996 if (!error.empty()) {
997 LOG_DEBUGGER(ERROR) << "StartParams::Create " << error;
998 return nullptr;
999 }
1000
1001 return startParams;
1002 }
1003 } // namespace panda::ecmascript::tooling
1004