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 "ecmascript/tooling/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(ERROR, DEBUGGER) << "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;
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;
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;
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;
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;
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(ERROR, DEBUGGER) << "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("start", &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;
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(ERROR, DEBUGGER) << "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(ERROR, DEBUGGER) << "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(ERROR, DEBUGGER) << "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;
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(ERROR, DEBUGGER) << "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(ERROR, DEBUGGER) << "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(ERROR, DEBUGGER) << "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(ERROR, DEBUGGER) << "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(ERROR, DEBUGGER) << "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;
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 for (int32_t i = 0; i < len; ++i) {
371 std::unique_ptr<LocationRange> obj = LocationRange::Create(*skipList->Get(i));
372 if (obj == nullptr) {
373 error += "'skipList' items LocationRange is invalid;";
374 } else {
375 paramsObject->skipList_->emplace_back(std::move(obj));
376 }
377 }
378 } else if (ret == Result::TYPE_ERROR) { // optional value
379 error += "Unknown 'skipList';";
380 }
381
382 if (!error.empty()) {
383 LOG(ERROR, DEBUGGER) << "StepIntoParams::Create " << error;
384 return nullptr;
385 }
386
387 return paramsObject;
388 }
389
Create(const PtJson & params)390 std::unique_ptr<StepOverParams> StepOverParams::Create(const PtJson ¶ms)
391 {
392 auto paramsObject = std::make_unique<StepOverParams>();
393 std::string error;
394 Result ret;
395
396 std::unique_ptr<PtJson> skipList;
397 ret = params.GetArray("skipList", &skipList);
398 if (ret == Result::SUCCESS) {
399 int32_t len = skipList->GetSize();
400 for (int32_t i = 0; i < len; ++i) {
401 std::unique_ptr<LocationRange> obj = LocationRange::Create(*skipList->Get(i));
402 if (obj == nullptr) {
403 error += "'skipList' items LocationRange is invalid;";
404 } else {
405 paramsObject->skipList_->emplace_back(std::move(obj));
406 }
407 }
408 } else if (ret == Result::TYPE_ERROR) { // optional value
409 error += "Unknown 'skipList';";
410 }
411
412 if (!error.empty()) {
413 LOG(ERROR, DEBUGGER) << "StepOverParams::Create " << error;
414 return nullptr;
415 }
416
417 return paramsObject;
418 }
419
Create(const PtJson & params)420 std::unique_ptr<GetPropertiesParams> GetPropertiesParams::Create(const PtJson ¶ms)
421 {
422 auto paramsObject = std::make_unique<GetPropertiesParams>();
423 std::string error;
424 Result ret;
425
426 std::string objectId;
427 ret = params.GetString("objectId", &objectId);
428 if (ret == Result::SUCCESS) {
429 paramsObject->objectId_ = std::stoi(objectId);
430 } else {
431 error += "Unknown 'objectId';";
432 }
433 bool ownProperties;
434 ret = params.GetBool("ownProperties", &ownProperties);
435 if (ret == Result::SUCCESS) {
436 paramsObject->ownProperties_ = ownProperties;
437 } else if (ret == Result::TYPE_ERROR) { // optional value
438 error += "Unknown 'ownProperties';";
439 }
440 bool accessorPropertiesOnly;
441 ret = params.GetBool("accessorPropertiesOnly", &accessorPropertiesOnly);
442 if (ret == Result::SUCCESS) {
443 paramsObject->accessorPropertiesOnly_ = accessorPropertiesOnly;
444 } else if (ret == Result::TYPE_ERROR) { // optional value
445 error += "Unknown 'accessorPropertiesOnly';";
446 }
447 bool generatePreview;
448 ret = params.GetBool("generatePreview", &generatePreview);
449 if (ret == Result::SUCCESS) {
450 paramsObject->generatePreview_ = generatePreview;
451 } else if (ret == Result::TYPE_ERROR) { // optional value
452 error += "Unknown 'generatePreview';";
453 }
454 if (!error.empty()) {
455 LOG(ERROR, DEBUGGER) << "GetPropertiesParams::Create " << error;
456 return nullptr;
457 }
458
459 return paramsObject;
460 }
461
Create(const PtJson & params)462 std::unique_ptr<CallFunctionOnParams> CallFunctionOnParams::Create(const PtJson ¶ms)
463 {
464 auto paramsObject = std::make_unique<CallFunctionOnParams>();
465 std::string error;
466 Result ret;
467
468 // paramsObject->functionDeclaration_
469 std::string functionDeclaration;
470 ret = params.GetString("functionDeclaration", &functionDeclaration);
471 if (ret == Result::SUCCESS) {
472 paramsObject->functionDeclaration_ = std::move(functionDeclaration);
473 } else {
474 error += "Unknown 'functionDeclaration';";
475 }
476 // paramsObject->objectId_
477 std::string objectId;
478 ret = params.GetString("objectId", &objectId);
479 if (ret == Result::SUCCESS) {
480 paramsObject->objectId_ = std::stoi(objectId);
481 } else if (ret == Result::TYPE_ERROR) { // optional value
482 error += "Unknown 'objectId';";
483 }
484 // paramsObject->arguments_
485 std::unique_ptr<PtJson> arguments;
486 ret = params.GetArray("arguments", &arguments);
487 if (ret == Result::SUCCESS) {
488 int32_t len = arguments->GetSize();
489 for (int32_t i = 0; i < len; ++i) {
490 std::unique_ptr<CallArgument> obj = CallArgument::Create(*arguments->Get(i));
491 if (obj == nullptr) {
492 error += "'arguments' items CallArgument is invaild;";
493 } else {
494 paramsObject->arguments_->emplace_back(std::move(obj));
495 }
496 }
497 } else if (ret == Result::TYPE_ERROR) { // optional value
498 error += "Unknown 'arguments';";
499 }
500 // paramsObject->silent_
501 bool silent;
502 ret = params.GetBool("silent", &silent);
503 if (ret == Result::SUCCESS) {
504 paramsObject->silent_ = silent;
505 } else if (ret == Result::TYPE_ERROR) { // optional value
506 error += "Unknown 'silent';";
507 }
508 // paramsObject->returnByValue_
509 bool returnByValue;
510 ret = params.GetBool("returnByValue", &returnByValue);
511 if (ret == Result::SUCCESS) {
512 paramsObject->returnByValue_ = returnByValue;
513 } else if (ret == Result::TYPE_ERROR) { // optional value
514 error += "Unknown 'returnByValue';";
515 }
516 // paramsObject->generatePreview_
517 bool generatePreview;
518 ret = params.GetBool("generatePreview", &generatePreview);
519 if (ret == Result::SUCCESS) {
520 paramsObject->generatePreview_ = generatePreview;
521 } else if (ret == Result::TYPE_ERROR) { // optional value
522 error += "Unknown 'generatePreview';";
523 }
524 // paramsObject->userGesture_
525 bool userGesture;
526 ret = params.GetBool("userGesture", &userGesture);
527 if (ret == Result::SUCCESS) {
528 paramsObject->userGesture_ = userGesture;
529 } else if (ret == Result::TYPE_ERROR) { // optional value
530 error += "Unknown 'userGesture';";
531 }
532 // paramsObject->awaitPromise_
533 bool awaitPromise;
534 ret = params.GetBool("awaitPromise", &awaitPromise);
535 if (ret == Result::SUCCESS) {
536 paramsObject->awaitPromise_ = awaitPromise;
537 } else if (ret == Result::TYPE_ERROR) { // optional value
538 error += "Unknown 'awaitPromise';";
539 }
540 // paramsObject->executionContextId_
541 int32_t executionContextId;
542 ret = params.GetInt("executionContextId", &executionContextId);
543 if (ret == Result::SUCCESS) {
544 paramsObject->executionContextId_ = executionContextId;
545 } else if (ret == Result::TYPE_ERROR) { // optional value
546 error += "Unknown 'executionContextId';";
547 }
548 // paramsObject->objectGroup_
549 std::string objectGroup;
550 ret = params.GetString("objectGroup", &objectGroup);
551 if (ret == Result::SUCCESS) {
552 paramsObject->objectGroup_ = std::move(objectGroup);
553 } else if (ret == Result::TYPE_ERROR) { // optional value
554 error += "Unknown 'objectGroup';";
555 }
556 // paramsObject->throwOnSideEffect_
557 bool throwOnSideEffect;
558 ret = params.GetBool("throwOnSideEffect", &throwOnSideEffect);
559 if (ret == Result::SUCCESS) {
560 paramsObject->throwOnSideEffect_ = throwOnSideEffect;
561 } else if (ret == Result::TYPE_ERROR) { // optional value
562 error += "Unknown 'throwOnSideEffect';";
563 }
564
565 // Check whether the error is empty.
566 if (!error.empty()) {
567 LOG(ERROR, DEBUGGER) << "CallFunctionOnParams::Create " << error;
568 return nullptr;
569 }
570
571 return paramsObject;
572 }
573
574 #ifdef SUPPORT_PROFILER_CDP
Create(const PtJson & params)575 std::unique_ptr<StartSamplingParams> StartSamplingParams::Create(const PtJson ¶ms)
576 {
577 auto paramsObject = std::make_unique<StartSamplingParams>();
578 std::string error;
579 Result ret;
580
581 int32_t samplingInterval;
582 ret = params.GetInt("samplingInterval", &samplingInterval);
583 if (ret == Result::SUCCESS) {
584 paramsObject->samplingInterval_ = samplingInterval;
585 } else if (ret == Result::TYPE_ERROR) { // optional value
586 error += "Unknown 'samplingInterval';";
587 }
588
589 if (!error.empty()) {
590 LOG(ERROR, DEBUGGER) << "StartSamplingParams::Create " << error;
591 return nullptr;
592 }
593 return paramsObject;
594 }
595
Create(const PtJson & params)596 std::unique_ptr<StartTrackingHeapObjectsParams> StartTrackingHeapObjectsParams::Create(const PtJson ¶ms)
597 {
598 auto paramsObject = std::make_unique<StartTrackingHeapObjectsParams>();
599 std::string error;
600 Result ret;
601
602 bool trackAllocations;
603 ret = params.GetBool("trackAllocations", &trackAllocations);
604 if (ret == Result::SUCCESS) {
605 paramsObject->trackAllocations_ = trackAllocations;
606 } else if (ret == Result::TYPE_ERROR) { // optional value
607 error += "Unknown 'trackAllocations';";
608 }
609
610 if (!error.empty()) {
611 LOG(ERROR, DEBUGGER) << "StartTrackingHeapObjectsParams::Create " << error;
612 return nullptr;
613 }
614 return paramsObject;
615 }
616
Create(const PtJson & params)617 std::unique_ptr<StopTrackingHeapObjectsParams> StopTrackingHeapObjectsParams::Create(const PtJson ¶ms)
618 {
619 auto paramsObject = std::make_unique<StopTrackingHeapObjectsParams>();
620 std::string error;
621 Result ret;
622
623 bool reportProgress;
624 ret = params.GetBool("reportProgress", &reportProgress);
625 if (ret == Result::SUCCESS) {
626 paramsObject->reportProgress_ = reportProgress;
627 } else if (ret == Result::TYPE_ERROR) { // optional value
628 error += "Unknown 'reportProgress';";
629 }
630
631 bool treatGlobalObjectsAsRoots;
632 ret = params.GetBool("treatGlobalObjectsAsRoots", &treatGlobalObjectsAsRoots);
633 if (ret == Result::SUCCESS) {
634 paramsObject->treatGlobalObjectsAsRoots_ = treatGlobalObjectsAsRoots;
635 } else if (ret == Result::TYPE_ERROR) { // optional value
636 error += "Unknown 'treatGlobalObjectsAsRoots';";
637 }
638
639 bool captureNumericValue;
640 ret = params.GetBool("captureNumericValue", &captureNumericValue);
641 if (ret == Result::SUCCESS) {
642 paramsObject->captureNumericValue_ = captureNumericValue;
643 } else if (ret == Result::TYPE_ERROR) { // optional value
644 error += "Unknown 'captureNumericValue';";
645 }
646
647 if (!error.empty()) {
648 LOG(ERROR, DEBUGGER) << "StopTrackingHeapObjectsParams::Create " << error;
649 return nullptr;
650 }
651 return paramsObject;
652 }
653
Create(const PtJson & params)654 std::unique_ptr<AddInspectedHeapObjectParams> AddInspectedHeapObjectParams::Create(const PtJson ¶ms)
655 {
656 auto paramsObject = std::make_unique<AddInspectedHeapObjectParams>();
657 std::string error;
658 Result ret;
659
660 std::string heapObjectId;
661 ret = params.GetString("heapObjectId", &heapObjectId);
662 if (ret == Result::SUCCESS) {
663 paramsObject->heapObjectId_ = std::stoi(heapObjectId);
664 } else {
665 error += "Unknown 'heapObjectId';";
666 }
667
668 if (!error.empty()) {
669 LOG(ERROR, DEBUGGER) << "AddInspectedHeapObjectParams::Create " << error;
670 return nullptr;
671 }
672 return paramsObject;
673 }
674
Create(const PtJson & params)675 std::unique_ptr<GetHeapObjectIdParams> GetHeapObjectIdParams::Create(const PtJson ¶ms)
676 {
677 auto paramsObject = std::make_unique<GetHeapObjectIdParams>();
678 std::string error;
679 Result ret;
680
681 std::string objectId;
682 ret = params.GetString("objectId", &objectId);
683 if (ret == Result::SUCCESS) {
684 paramsObject->objectId_ = std::stoi(objectId);
685 } else if (ret == Result::TYPE_ERROR) { // optional value
686 error += "Unknown 'objectId';";
687 }
688
689 if (!error.empty()) {
690 LOG(ERROR, DEBUGGER) << "GetHeapObjectIdParams::Create " << error;
691 return nullptr;
692 }
693 return paramsObject;
694 }
695
Create(const PtJson & params)696 std::unique_ptr<GetObjectByHeapObjectIdParams> GetObjectByHeapObjectIdParams::Create(const PtJson ¶ms)
697 {
698 auto paramsObject = std::make_unique<GetObjectByHeapObjectIdParams>();
699 std::string error;
700 Result ret;
701
702 std::string objectId;
703 ret = params.GetString("objectId", &objectId);
704 if (ret == Result::SUCCESS) {
705 paramsObject->objectId_ = std::stoi(objectId);
706 } else if (ret == Result::TYPE_ERROR) { // optional value
707 error += "Unknown 'objectId';";
708 }
709
710 std::string objectGroup;
711 ret = params.GetString("objectGroup", &objectGroup);
712 if (ret == Result::SUCCESS) {
713 paramsObject->objectGroup_ = std::move(objectGroup);
714 } else if (ret == Result::TYPE_ERROR) { // optional value
715 error += "Unknown 'objectGroup';";
716 }
717
718 if (!error.empty()) {
719 LOG(ERROR, DEBUGGER) << "GetObjectByHeapObjectIdParams::Create " << error;
720 return nullptr;
721 }
722 return paramsObject;
723 }
724
Create(const PtJson & params)725 std::unique_ptr<StartPreciseCoverageParams> StartPreciseCoverageParams::Create(const PtJson ¶ms)
726 {
727 auto paramsObject = std::make_unique<StartPreciseCoverageParams>();
728 std::string error;
729 Result ret;
730
731 bool callCount;
732 ret = params.GetBool("callCount", &callCount);
733 if (ret == Result::SUCCESS) {
734 paramsObject->callCount_ = callCount;
735 } else if (ret == Result::TYPE_ERROR) { // optional value
736 error += "Unknown 'callCount';";
737 }
738
739 bool detailed;
740 ret = params.GetBool("detailed", &detailed);
741 if (ret == Result::SUCCESS) {
742 paramsObject->detailed_ = detailed;
743 } else if (ret == Result::TYPE_ERROR) { // optional value
744 error += "Unknown 'detailed';";
745 }
746
747 bool allowTriggeredUpdates;
748 ret = params.GetBool("allowTriggeredUpdates", &allowTriggeredUpdates);
749 if (ret == Result::SUCCESS) {
750 paramsObject->allowTriggeredUpdates_ = allowTriggeredUpdates;
751 } else if (ret == Result::TYPE_ERROR) { // optional value
752 error += "Unknown 'allowTriggeredUpdates';";
753 }
754
755 if (!error.empty()) {
756 LOG(ERROR, DEBUGGER) << "StartPreciseCoverageParams::Create " << error;
757 return nullptr;
758 }
759 return paramsObject;
760 }
761
Create(const PtJson & params)762 std::unique_ptr<SetSamplingIntervalParams> SetSamplingIntervalParams::Create(const PtJson ¶ms)
763 {
764 auto paramsObject = std::make_unique<SetSamplingIntervalParams>();
765 std::string error;
766 Result ret;
767
768 int32_t interval;
769 ret = params.GetInt("interval", &interval);
770 if (ret == Result::SUCCESS) {
771 paramsObject->interval_ = interval;
772 } else {
773 error += "Unknown 'interval';";
774 }
775
776 if (!error.empty()) {
777 LOG(ERROR, DEBUGGER) << "SetSamplingIntervalParams::Create " << error;
778 return nullptr;
779 }
780 return paramsObject;
781 }
782 #endif
783 } // namespace panda::ecmascript::tooling
784