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 #ifndef ECMASCRIPT_TOOLING_BASE_PT_PARAMS_H 17 #define ECMASCRIPT_TOOLING_BASE_PT_PARAMS_H 18 19 #include "tooling/base/pt_types.h" 20 21 namespace panda::ecmascript::tooling { 22 class PtBaseParams : public PtBaseTypes { 23 public: 24 PtBaseParams() = default; 25 ~PtBaseParams() override = default; ToJson()26 std::unique_ptr<PtJson> ToJson() const override 27 { 28 UNREACHABLE(); 29 } 30 31 private: 32 NO_COPY_SEMANTIC(PtBaseParams); 33 NO_MOVE_SEMANTIC(PtBaseParams); 34 }; 35 36 class ContinueToLocationParams : public PtBaseParams { 37 public: 38 ContinueToLocationParams() = default; 39 ~ContinueToLocationParams() override = default; 40 41 static std::unique_ptr<ContinueToLocationParams> Create(const PtJson ¶ms); GetLocation()42 Location *GetLocation() const 43 { 44 return location_.get(); 45 } 46 GetTargetCallFrames()47 const std::string &GetTargetCallFrames() const 48 { 49 return targetCallFrames_; 50 } 51 52 private: 53 NO_COPY_SEMANTIC(ContinueToLocationParams); 54 NO_MOVE_SEMANTIC(ContinueToLocationParams); 55 56 std::unique_ptr<Location> location_ {nullptr}; 57 std::string targetCallFrames_ {}; 58 }; 59 60 class EnableParams : public PtBaseParams { 61 public: 62 EnableParams() = default; 63 ~EnableParams() override = default; 64 65 static std::unique_ptr<EnableParams> Create(const PtJson ¶ms); 66 GetMaxScriptsCacheSize()67 double GetMaxScriptsCacheSize() const 68 { 69 return maxScriptsCacheSize_.value_or(0); 70 } 71 HasMaxScriptsCacheSize()72 bool HasMaxScriptsCacheSize() const 73 { 74 return maxScriptsCacheSize_.has_value(); 75 } 76 77 private: 78 NO_COPY_SEMANTIC(EnableParams); 79 NO_MOVE_SEMANTIC(EnableParams); 80 81 std::optional<double> maxScriptsCacheSize_ {}; 82 }; 83 84 class EvaluateOnCallFrameParams : public PtBaseParams { 85 public: 86 EvaluateOnCallFrameParams() = default; 87 ~EvaluateOnCallFrameParams() override = default; 88 89 static std::unique_ptr<EvaluateOnCallFrameParams> Create(const PtJson ¶ms); 90 GetCallFrameId()91 CallFrameId GetCallFrameId() const 92 { 93 return callFrameId_; 94 } 95 GetExpression()96 const std::string &GetExpression() const 97 { 98 return expression_; 99 } 100 101 private: 102 NO_COPY_SEMANTIC(EvaluateOnCallFrameParams); 103 NO_MOVE_SEMANTIC(EvaluateOnCallFrameParams); 104 105 CallFrameId callFrameId_ {}; 106 std::string expression_ {}; 107 std::optional<std::string> objectGroup_ {}; 108 std::optional<bool> includeCommandLineAPI_ {}; 109 std::optional<bool> silent_ {}; 110 std::optional<bool> returnByValue_ {}; 111 std::optional<bool> generatePreview_ {}; 112 std::optional<bool> throwOnSideEffect_ {}; 113 }; 114 115 class GetPossibleBreakpointsParams : public PtBaseParams { 116 public: 117 GetPossibleBreakpointsParams() = default; 118 ~GetPossibleBreakpointsParams() override = default; 119 120 static std::unique_ptr<GetPossibleBreakpointsParams> Create(const PtJson ¶ms); 121 GetStart()122 Location *GetStart() const 123 { 124 return start_.get(); 125 } 126 GetEnd()127 Location *GetEnd() const 128 { 129 if (end_) { 130 return end_->get(); 131 } 132 return nullptr; 133 } 134 HasEnd()135 bool HasEnd() const 136 { 137 return end_.has_value(); 138 } 139 GetRestrictToFunction()140 bool GetRestrictToFunction() const 141 { 142 return restrictToFunction_.value_or(false); 143 } 144 HasRestrictToFunction()145 bool HasRestrictToFunction() const 146 { 147 return restrictToFunction_.has_value(); 148 } 149 150 private: 151 NO_COPY_SEMANTIC(GetPossibleBreakpointsParams); 152 NO_MOVE_SEMANTIC(GetPossibleBreakpointsParams); 153 154 std::unique_ptr<Location> start_ {nullptr}; 155 std::optional<std::unique_ptr<Location>> end_ {}; 156 std::optional<bool> restrictToFunction_ {}; 157 }; 158 159 class GetScriptSourceParams : public PtBaseParams { 160 public: 161 GetScriptSourceParams() = default; 162 ~GetScriptSourceParams() override = default; 163 164 static std::unique_ptr<GetScriptSourceParams> Create(const PtJson ¶ms); 165 GetScriptId()166 ScriptId GetScriptId() const 167 { 168 return scriptId_; 169 } 170 171 private: 172 NO_COPY_SEMANTIC(GetScriptSourceParams); 173 NO_MOVE_SEMANTIC(GetScriptSourceParams); 174 175 ScriptId scriptId_ {0}; 176 }; 177 178 class RemoveBreakpointParams : public PtBaseParams { 179 public: 180 RemoveBreakpointParams() = default; 181 ~RemoveBreakpointParams() override = default; 182 183 static std::unique_ptr<RemoveBreakpointParams> Create(const PtJson ¶ms); 184 GetBreakpointId()185 BreakpointId GetBreakpointId() const 186 { 187 return breakpointId_; 188 } 189 190 private: 191 NO_COPY_SEMANTIC(RemoveBreakpointParams); 192 NO_MOVE_SEMANTIC(RemoveBreakpointParams); 193 194 BreakpointId breakpointId_ {}; 195 }; 196 197 class RemoveBreakpointsByUrlParams : public PtBaseParams { 198 public: 199 RemoveBreakpointsByUrlParams() = default; 200 ~RemoveBreakpointsByUrlParams() override = default; 201 202 static std::unique_ptr<RemoveBreakpointsByUrlParams> Create(const PtJson ¶ms); 203 GetUrl()204 const std::string &GetUrl() const 205 { 206 ASSERT(HasUrl()); 207 return url_.value(); 208 } 209 HasUrl()210 bool HasUrl() const 211 { 212 return url_.has_value(); 213 } 214 private: 215 NO_COPY_SEMANTIC(RemoveBreakpointsByUrlParams); 216 NO_MOVE_SEMANTIC(RemoveBreakpointsByUrlParams); 217 218 std::optional<std::string> url_ {}; 219 }; 220 221 class ResumeParams : public PtBaseParams { 222 public: 223 ResumeParams() = default; 224 ~ResumeParams() override = default; 225 226 static std::unique_ptr<ResumeParams> Create(const PtJson ¶ms); 227 GetTerminateOnResume()228 bool GetTerminateOnResume() const 229 { 230 return terminateOnResume_.value_or(false); 231 } 232 HasTerminateOnResume()233 bool HasTerminateOnResume() const 234 { 235 return terminateOnResume_.has_value(); 236 } 237 238 private: 239 NO_COPY_SEMANTIC(ResumeParams); 240 NO_MOVE_SEMANTIC(ResumeParams); 241 242 std::optional<bool> terminateOnResume_ {}; 243 }; 244 245 class SetAsyncCallStackDepthParams : public PtBaseParams { 246 public: 247 SetAsyncCallStackDepthParams() = default; 248 ~SetAsyncCallStackDepthParams() override = default; 249 250 static std::unique_ptr<SetAsyncCallStackDepthParams> Create(const PtJson ¶ms); 251 GetMaxDepth()252 int32_t GetMaxDepth() const 253 { 254 return maxDepth_; 255 } 256 257 private: 258 NO_COPY_SEMANTIC(SetAsyncCallStackDepthParams); 259 NO_MOVE_SEMANTIC(SetAsyncCallStackDepthParams); 260 261 int32_t maxDepth_ {0}; 262 }; 263 264 class SetBlackboxPatternsParams : public PtBaseParams { 265 public: 266 SetBlackboxPatternsParams() = default; 267 ~SetBlackboxPatternsParams() override = default; 268 static std::unique_ptr<SetBlackboxPatternsParams> Create(const PtJson ¶ms); 269 GetPatterns()270 std::list<std::string> GetPatterns() const 271 { 272 return patterns_; 273 } 274 275 private: 276 NO_COPY_SEMANTIC(SetBlackboxPatternsParams); 277 NO_MOVE_SEMANTIC(SetBlackboxPatternsParams); 278 279 std::list<std::string> patterns_ {}; 280 }; 281 282 class SetBreakpointByUrlParams : public PtBaseParams { 283 public: 284 SetBreakpointByUrlParams() = default; 285 ~SetBreakpointByUrlParams() override = default; 286 287 static std::unique_ptr<SetBreakpointByUrlParams> Create(const PtJson ¶ms); 288 GetLine()289 int32_t GetLine() const 290 { 291 return lineNumber_; 292 } 293 GetUrl()294 const std::string &GetUrl() const 295 { 296 ASSERT(HasUrl()); 297 return url_.value(); 298 } 299 HasUrl()300 bool HasUrl() const 301 { 302 return url_.has_value(); 303 } 304 GetUrlRegex()305 const std::string &GetUrlRegex() const 306 { 307 ASSERT(HasUrlRegex()); 308 return urlRegex_.value(); 309 } 310 HasUrlRegex()311 bool HasUrlRegex() const 312 { 313 return urlRegex_.has_value(); 314 } 315 GetScriptHash()316 const std::string &GetScriptHash() const 317 { 318 ASSERT(HasScriptHash()); 319 return scriptHash_.value(); 320 } 321 HasScriptHash()322 bool HasScriptHash() const 323 { 324 return scriptHash_.has_value(); 325 } 326 GetColumn()327 int32_t GetColumn() const 328 { 329 return columnNumber_.value_or(0); 330 } 331 HasColumn()332 bool HasColumn() const 333 { 334 return columnNumber_.has_value(); 335 } 336 GetCondition()337 const std::string &GetCondition() const 338 { 339 ASSERT(HasCondition()); 340 return condition_.value(); 341 } 342 HasCondition()343 bool HasCondition() const 344 { 345 return condition_.has_value(); 346 } 347 348 private: 349 NO_COPY_SEMANTIC(SetBreakpointByUrlParams); 350 NO_MOVE_SEMANTIC(SetBreakpointByUrlParams); 351 352 int32_t lineNumber_ {0}; 353 std::optional<std::string> url_ {}; 354 std::optional<std::string> urlRegex_ {}; 355 std::optional<std::string> scriptHash_ {}; 356 std::optional<int32_t> columnNumber_ {0}; 357 std::optional<std::string> condition_ {}; 358 }; 359 360 361 class SetBreakpointsActiveParams : public PtBaseParams { 362 public: 363 SetBreakpointsActiveParams() = default; 364 ~SetBreakpointsActiveParams() override = default; 365 366 static std::unique_ptr<SetBreakpointsActiveParams> Create(const PtJson ¶ms); 367 GetBreakpointsState()368 bool GetBreakpointsState() const 369 { 370 return breakpointsState_.value_or(false); 371 } 372 private: 373 NO_COPY_SEMANTIC(SetBreakpointsActiveParams); 374 NO_MOVE_SEMANTIC(SetBreakpointsActiveParams); 375 376 std::optional<bool> breakpointsState_ {}; 377 }; 378 379 class SetSkipAllPausesParams : public PtBaseParams { 380 public: 381 SetSkipAllPausesParams() = default; 382 ~SetSkipAllPausesParams() override = default; 383 384 static std::unique_ptr<SetSkipAllPausesParams> Create(const PtJson ¶ms); 385 GetSkipAllPausesState()386 bool GetSkipAllPausesState() const 387 { 388 return skipAllPausesState_.value_or(false); 389 } 390 private: 391 NO_COPY_SEMANTIC(SetSkipAllPausesParams); 392 NO_MOVE_SEMANTIC(SetSkipAllPausesParams); 393 394 std::optional<bool> skipAllPausesState_ {}; 395 }; 396 397 class GetPossibleAndSetBreakpointParams : public PtBaseParams { 398 public: 399 GetPossibleAndSetBreakpointParams() = default; 400 ~GetPossibleAndSetBreakpointParams() = default; 401 static std::unique_ptr<GetPossibleAndSetBreakpointParams> Create(const PtJson ¶ms); 402 GetBreakpointsList()403 const std::vector<std::unique_ptr<BreakpointInfo>> *GetBreakpointsList() const 404 { 405 if (!breakpointsList_) { 406 return nullptr; 407 } 408 return &(breakpointsList_.value()); 409 } 410 HasBreakpointsList()411 bool HasBreakpointsList() const 412 { 413 return breakpointsList_.has_value(); 414 } 415 416 private: 417 NO_COPY_SEMANTIC(GetPossibleAndSetBreakpointParams); 418 NO_MOVE_SEMANTIC(GetPossibleAndSetBreakpointParams); 419 420 std::optional<std::vector<std::unique_ptr<BreakpointInfo>>> breakpointsList_ {}; 421 }; 422 423 enum class PauseOnExceptionsState : uint8_t { NONE, UNCAUGHT, ALL }; 424 425 class SetPauseOnExceptionsParams : public PtBaseParams { 426 public: 427 SetPauseOnExceptionsParams() = default; 428 ~SetPauseOnExceptionsParams() override = default; 429 static std::unique_ptr<SetPauseOnExceptionsParams> Create(const PtJson ¶ms); 430 GetState()431 PauseOnExceptionsState GetState() const 432 { 433 return state_; 434 } 435 StoreState(const std::string & state)436 bool StoreState(const std::string &state) 437 { 438 if (state == "none") { 439 state_ = PauseOnExceptionsState::NONE; 440 return true; 441 } 442 if (state == "uncaught") { 443 state_ = PauseOnExceptionsState::UNCAUGHT; 444 return true; 445 } 446 if (state == "all") { 447 state_ = PauseOnExceptionsState::ALL; 448 return true; 449 } 450 return false; 451 } 452 453 private: 454 NO_COPY_SEMANTIC(SetPauseOnExceptionsParams); 455 NO_MOVE_SEMANTIC(SetPauseOnExceptionsParams); 456 457 PauseOnExceptionsState state_ {PauseOnExceptionsState::ALL}; 458 }; 459 460 class StepIntoParams : public PtBaseParams { 461 public: 462 StepIntoParams() = default; 463 ~StepIntoParams() override = default; 464 465 static std::unique_ptr<StepIntoParams> Create(const PtJson ¶ms); 466 GetBreakOnAsyncCall()467 bool GetBreakOnAsyncCall() const 468 { 469 return breakOnAsyncCall_.value_or(false); 470 } 471 HasBreakOnAsyncCall()472 bool HasBreakOnAsyncCall() const 473 { 474 return breakOnAsyncCall_.has_value(); 475 } 476 GetSkipList()477 const std::list<std::unique_ptr<LocationRange>> *GetSkipList() const 478 { 479 if (!skipList_) { 480 return nullptr; 481 } 482 return &(skipList_.value()); 483 } 484 HasSkipList()485 bool HasSkipList() const 486 { 487 return skipList_.has_value(); 488 } 489 490 private: 491 NO_COPY_SEMANTIC(StepIntoParams); 492 NO_MOVE_SEMANTIC(StepIntoParams); 493 494 std::optional<bool> breakOnAsyncCall_ {}; 495 std::optional<std::list<std::unique_ptr<LocationRange>>> skipList_ {}; 496 }; 497 498 class SmartStepIntoParams : public PtBaseParams { 499 public: 500 SmartStepIntoParams() = default; 501 ~SmartStepIntoParams() override = default; 502 503 static std::unique_ptr<SmartStepIntoParams> Create(const PtJson ¶ms); 504 GetSetBreakpointByUrlParams()505 SetBreakpointByUrlParams *GetSetBreakpointByUrlParams() const 506 { 507 return sbpParams_.get(); 508 } 509 510 private: 511 NO_COPY_SEMANTIC(SmartStepIntoParams); 512 NO_MOVE_SEMANTIC(SmartStepIntoParams); 513 514 static void AddRequireParams(PtJson ¶ms); 515 516 std::unique_ptr<SetBreakpointByUrlParams> sbpParams_ {nullptr}; 517 }; 518 519 class StepOverParams : public PtBaseParams { 520 public: 521 StepOverParams() = default; 522 ~StepOverParams() override = default; 523 524 static std::unique_ptr<StepOverParams> Create(const PtJson ¶ms); 525 GetSkipList()526 const std::list<std::unique_ptr<LocationRange>> *GetSkipList() const 527 { 528 if (!skipList_) { 529 return nullptr; 530 } 531 return &(skipList_.value()); 532 } 533 HasSkipList()534 bool HasSkipList() const 535 { 536 return skipList_.has_value(); 537 } 538 539 private: 540 NO_COPY_SEMANTIC(StepOverParams); 541 NO_MOVE_SEMANTIC(StepOverParams); 542 543 std::optional<std::list<std::unique_ptr<LocationRange>>> skipList_ {}; 544 }; 545 546 class DropFrameParams : public PtBaseParams { 547 public: 548 DropFrameParams() = default; 549 ~DropFrameParams() override = default; 550 static std::unique_ptr<DropFrameParams> Create(const PtJson ¶ms); 551 GetDroppedDepth()552 uint32_t GetDroppedDepth() const 553 { 554 return droppedDepth_.value(); 555 } 556 HasDroppedDepth()557 bool HasDroppedDepth() const 558 { 559 return droppedDepth_.has_value(); 560 } 561 562 private: 563 NO_COPY_SEMANTIC(DropFrameParams); 564 NO_MOVE_SEMANTIC(DropFrameParams); 565 566 std::optional<uint32_t> droppedDepth_ {}; 567 }; 568 569 class SetNativeRangeParams { 570 public: 571 SetNativeRangeParams() = default; 572 ~SetNativeRangeParams() = default; 573 static std::unique_ptr<SetNativeRangeParams> Create(const PtJson ¶ms); 574 GetNativeRange()575 std::vector<NativeRange> GetNativeRange() const 576 { 577 return nativeRange_; 578 } 579 private: 580 581 std::vector<NativeRange> nativeRange_ {}; 582 }; 583 584 class ResetSingleStepperParams : public PtBaseParams { 585 public: 586 ResetSingleStepperParams() = default; 587 ~ResetSingleStepperParams() = default; 588 static std::unique_ptr<ResetSingleStepperParams> Create(const PtJson ¶ms); 589 GetResetSingleStepper()590 bool GetResetSingleStepper() const 591 { 592 return resetSingleStepper_; 593 } 594 private: 595 NO_COPY_SEMANTIC(ResetSingleStepperParams); 596 NO_MOVE_SEMANTIC(ResetSingleStepperParams); 597 598 bool resetSingleStepper_ {false}; 599 }; 600 601 class SetMixedDebugParams : public PtBaseParams { 602 public: 603 SetMixedDebugParams() = default; 604 ~SetMixedDebugParams() override = default; 605 static std::unique_ptr<SetMixedDebugParams> Create(const PtJson ¶ms); 606 GetEnabled()607 bool GetEnabled() const 608 { 609 return enabled_; 610 } 611 GetMixedStackEnabled()612 bool GetMixedStackEnabled() const 613 { 614 return mixedStackEnabled_; 615 } 616 617 private: 618 NO_COPY_SEMANTIC(SetMixedDebugParams); 619 NO_MOVE_SEMANTIC(SetMixedDebugParams); 620 621 bool enabled_ {false}; 622 bool mixedStackEnabled_ {false}; 623 }; 624 625 class ReplyNativeCallingParams : public PtBaseParams { 626 public: 627 ReplyNativeCallingParams() = default; 628 ~ReplyNativeCallingParams() override = default; 629 static std::unique_ptr<ReplyNativeCallingParams> Create(const PtJson ¶ms); 630 GetUserCode()631 bool GetUserCode() const 632 { 633 return userCode_; 634 } 635 636 private: 637 NO_COPY_SEMANTIC(ReplyNativeCallingParams); 638 NO_MOVE_SEMANTIC(ReplyNativeCallingParams); 639 640 bool userCode_ {false}; 641 }; 642 643 class GetPropertiesParams : public PtBaseParams { 644 public: 645 GetPropertiesParams() = default; 646 ~GetPropertiesParams() override = default; 647 648 static std::unique_ptr<GetPropertiesParams> Create(const PtJson ¶ms); 649 GetObjectId()650 RemoteObjectId GetObjectId() const 651 { 652 return objectId_; 653 } 654 SetObjectId(RemoteObjectId id)655 GetPropertiesParams &SetObjectId(RemoteObjectId id) 656 { 657 objectId_ = id; 658 return *this; 659 } 660 GetOwnProperties()661 bool GetOwnProperties() const 662 { 663 return ownProperties_.value_or(false); 664 } 665 SetOwnProperties(bool ownProperties)666 GetPropertiesParams &SetOwnProperties(bool ownProperties) 667 { 668 ownProperties_ = ownProperties; 669 return *this; 670 } 671 HasOwnProperties()672 bool HasOwnProperties() const 673 { 674 return ownProperties_.has_value(); 675 } 676 GetAccessPropertiesOnly()677 bool GetAccessPropertiesOnly() const 678 { 679 return accessorPropertiesOnly_.value_or(false); 680 } 681 SetAccessPropertiesOnly(bool accessorPropertiesOnly)682 GetPropertiesParams &SetAccessPropertiesOnly(bool accessorPropertiesOnly) 683 { 684 accessorPropertiesOnly_ = accessorPropertiesOnly; 685 return *this; 686 } 687 HasAccessPropertiesOnly()688 bool HasAccessPropertiesOnly() const 689 { 690 return accessorPropertiesOnly_.has_value(); 691 } 692 GetGeneratePreview()693 bool GetGeneratePreview() const 694 { 695 return generatePreview_.value_or(false); 696 } 697 HasGeneratePreview()698 bool HasGeneratePreview() const 699 { 700 return generatePreview_.has_value(); 701 } 702 703 private: 704 NO_COPY_SEMANTIC(GetPropertiesParams); 705 NO_MOVE_SEMANTIC(GetPropertiesParams); 706 707 RemoteObjectId objectId_ {}; 708 std::optional<bool> ownProperties_ {}; 709 std::optional<bool> accessorPropertiesOnly_ {}; 710 std::optional<bool> generatePreview_ {}; 711 }; 712 713 class CallFunctionOnParams : public PtBaseParams { 714 public: 715 CallFunctionOnParams() = default; 716 ~CallFunctionOnParams() override = default; 717 718 static std::unique_ptr<CallFunctionOnParams> Create(const PtJson ¶ms); 719 GetCallFrameId()720 CallFrameId GetCallFrameId() const 721 { 722 return callFrameId_; 723 } 724 GetFunctionDeclaration()725 const std::string &GetFunctionDeclaration() const 726 { 727 return functionDeclaration_; 728 } 729 GetObjectId()730 RemoteObjectId GetObjectId() const 731 { 732 return objectId_.value_or(-1); 733 } 734 SetObjectId(RemoteObjectId objectId)735 CallFunctionOnParams &SetObjectId(RemoteObjectId objectId) 736 { 737 objectId_ = objectId; 738 return *this; 739 } 740 HasObjectId()741 bool HasObjectId() const 742 { 743 return objectId_.has_value(); 744 } 745 GetArguments()746 const std::vector<std::unique_ptr<CallArgument>> *GetArguments() const 747 { 748 if (!arguments_) { 749 return nullptr; 750 } 751 return &(arguments_.value()); 752 } 753 HasArguments()754 bool HasArguments() const 755 { 756 return arguments_.has_value(); 757 } 758 GetSilent()759 bool GetSilent() const 760 { 761 return silent_.value_or(false); 762 } 763 HasSilent()764 bool HasSilent() const 765 { 766 return silent_.has_value(); 767 } 768 GetReturnByValue()769 bool GetReturnByValue() const 770 { 771 return returnByValue_.value_or(false); 772 } 773 HasReturnByValue()774 bool HasReturnByValue() const 775 { 776 return returnByValue_.has_value(); 777 } 778 GetGeneratePreview()779 bool GetGeneratePreview() const 780 { 781 return generatePreview_.value_or(false); 782 } 783 HasGeneratePreview()784 bool HasGeneratePreview() const 785 { 786 return generatePreview_.has_value(); 787 } 788 GetUserGesture()789 bool GetUserGesture() const 790 { 791 return userGesture_.value_or(false); 792 } 793 HasUserGesture()794 bool HasUserGesture() const 795 { 796 return userGesture_.has_value(); 797 } 798 GetAwaitPromise()799 bool GetAwaitPromise() const 800 { 801 return awaitPromise_.value_or(false); 802 } 803 HasAwaitPromise()804 bool HasAwaitPromise() const 805 { 806 return awaitPromise_.has_value(); 807 } 808 GetExecutionContextId()809 ExecutionContextId GetExecutionContextId() const 810 { 811 return executionContextId_.value_or(-1); 812 } 813 SetExecutionContextId(ExecutionContextId executionContextId)814 CallFunctionOnParams &SetExecutionContextId(ExecutionContextId executionContextId) 815 { 816 executionContextId_ = executionContextId; 817 return *this; 818 } 819 HasExecutionContextId()820 bool HasExecutionContextId() const 821 { 822 return executionContextId_.has_value(); 823 } 824 GetObjectGroup()825 const std::string &GetObjectGroup() const 826 { 827 ASSERT(HasObjectGroup()); 828 return objectGroup_.value(); 829 } 830 HasObjectGroup()831 bool HasObjectGroup() const 832 { 833 return objectGroup_.has_value(); 834 } 835 GetThrowOnSideEffect()836 bool GetThrowOnSideEffect() const 837 { 838 return throwOnSideEffect_.value_or(false); 839 } 840 HasThrowOnSideEffect()841 bool HasThrowOnSideEffect() const 842 { 843 return throwOnSideEffect_.has_value(); 844 } 845 846 private: 847 NO_COPY_SEMANTIC(CallFunctionOnParams); 848 NO_MOVE_SEMANTIC(CallFunctionOnParams); 849 850 CallFrameId callFrameId_ {}; 851 std::string functionDeclaration_ {}; 852 std::optional<RemoteObjectId> objectId_ {}; 853 std::optional<std::vector<std::unique_ptr<CallArgument>>> arguments_ {}; 854 std::optional<bool> silent_ {}; 855 std::optional<bool> returnByValue_ {}; 856 std::optional<bool> generatePreview_ {}; 857 std::optional<bool> userGesture_ {}; 858 std::optional<bool> awaitPromise_ {}; 859 std::optional<ExecutionContextId> executionContextId_ {}; 860 std::optional<std::string> objectGroup_ {}; 861 std::optional<bool> throwOnSideEffect_ {}; 862 }; 863 864 class StartSamplingParams : public PtBaseParams { 865 public: 866 StartSamplingParams() = default; 867 ~StartSamplingParams() override = default; 868 869 static std::unique_ptr<StartSamplingParams> Create(const PtJson ¶ms); 870 GetSamplingInterval()871 double GetSamplingInterval() const 872 { 873 return samplingInterval_.value_or(32768); // 32768: default interval 874 } 875 876 private: 877 NO_COPY_SEMANTIC(StartSamplingParams); 878 NO_MOVE_SEMANTIC(StartSamplingParams); 879 880 std::optional<double> samplingInterval_ {32768}; 881 }; 882 883 class StartTrackingHeapObjectsParams : public PtBaseParams { 884 public: 885 StartTrackingHeapObjectsParams() = default; 886 ~StartTrackingHeapObjectsParams() override = default; 887 888 static std::unique_ptr<StartTrackingHeapObjectsParams> Create(const PtJson ¶ms); 889 GetTrackAllocations()890 bool GetTrackAllocations() const 891 { 892 return trackAllocations_.value_or(false); 893 } 894 HasTrackAllocations()895 bool HasTrackAllocations() const 896 { 897 return trackAllocations_.has_value(); 898 } 899 900 private: 901 NO_COPY_SEMANTIC(StartTrackingHeapObjectsParams); 902 NO_MOVE_SEMANTIC(StartTrackingHeapObjectsParams); 903 904 std::optional<bool> trackAllocations_; 905 }; 906 907 class StopTrackingHeapObjectsParams : public PtBaseParams { 908 public: 909 StopTrackingHeapObjectsParams() = default; 910 ~StopTrackingHeapObjectsParams() override = default; 911 912 static std::unique_ptr<StopTrackingHeapObjectsParams> Create(const PtJson ¶ms); 913 GetReportProgress()914 bool GetReportProgress() const 915 { 916 return reportProgress_.value_or(false); 917 } 918 HasReportProgress()919 bool HasReportProgress() const 920 { 921 return reportProgress_.has_value(); 922 } 923 GetTreatGlobalObjectsAsRoots()924 bool GetTreatGlobalObjectsAsRoots() const 925 { 926 return treatGlobalObjectsAsRoots_.value_or(false); 927 } 928 HasTreatGlobalObjectsAsRoots()929 bool HasTreatGlobalObjectsAsRoots() const 930 { 931 return treatGlobalObjectsAsRoots_.has_value(); 932 } 933 GetCaptureNumericValue()934 bool GetCaptureNumericValue() const 935 { 936 return captureNumericValue_.value_or(false); 937 } 938 HasCaptureNumericValue()939 bool HasCaptureNumericValue() const 940 { 941 return captureNumericValue_.has_value(); 942 } 943 944 private: 945 NO_COPY_SEMANTIC(StopTrackingHeapObjectsParams); 946 NO_MOVE_SEMANTIC(StopTrackingHeapObjectsParams); 947 948 std::optional<bool> reportProgress_ {}; 949 std::optional<bool> treatGlobalObjectsAsRoots_ {}; 950 std::optional<bool> captureNumericValue_ {}; 951 }; 952 953 class AddInspectedHeapObjectParams : public PtBaseParams { 954 public: 955 AddInspectedHeapObjectParams() = default; 956 ~AddInspectedHeapObjectParams() override = default; 957 958 static std::unique_ptr<AddInspectedHeapObjectParams> Create(const PtJson ¶ms); 959 GetHeapObjectId()960 HeapSnapshotObjectId GetHeapObjectId() const 961 { 962 return heapObjectId_; 963 } 964 965 private: 966 NO_COPY_SEMANTIC(AddInspectedHeapObjectParams); 967 NO_MOVE_SEMANTIC(AddInspectedHeapObjectParams); 968 969 HeapSnapshotObjectId heapObjectId_ {}; 970 }; 971 972 class GetHeapObjectIdParams : public PtBaseParams { 973 public: 974 GetHeapObjectIdParams() = default; 975 ~GetHeapObjectIdParams() override = default; 976 977 static std::unique_ptr<GetHeapObjectIdParams> Create(const PtJson ¶ms); 978 GetObjectId()979 RemoteObjectId GetObjectId() const 980 { 981 return objectId_; 982 } 983 984 private: 985 NO_COPY_SEMANTIC(GetHeapObjectIdParams); 986 NO_MOVE_SEMANTIC(GetHeapObjectIdParams); 987 988 RemoteObjectId objectId_ {}; 989 }; 990 991 class GetObjectByHeapObjectIdParams : public PtBaseParams { 992 public: 993 GetObjectByHeapObjectIdParams() = default; 994 ~GetObjectByHeapObjectIdParams() override = default; 995 996 static std::unique_ptr<GetObjectByHeapObjectIdParams> Create(const PtJson ¶ms); 997 GetObjectId()998 HeapSnapshotObjectId GetObjectId() const 999 { 1000 return objectId_; 1001 } 1002 GetObjectGroup()1003 const std::string &GetObjectGroup() const 1004 { 1005 ASSERT(HasObjectGroup()); 1006 return objectGroup_.value(); 1007 } 1008 HasObjectGroup()1009 bool HasObjectGroup() const 1010 { 1011 return objectGroup_.has_value(); 1012 } 1013 1014 private: 1015 NO_COPY_SEMANTIC(GetObjectByHeapObjectIdParams); 1016 NO_MOVE_SEMANTIC(GetObjectByHeapObjectIdParams); 1017 1018 HeapSnapshotObjectId objectId_ {}; 1019 std::optional<std::string> objectGroup_ {}; 1020 }; 1021 1022 class StartPreciseCoverageParams : public PtBaseParams { 1023 public: 1024 StartPreciseCoverageParams() = default; 1025 ~StartPreciseCoverageParams() override = default; 1026 1027 static std::unique_ptr<StartPreciseCoverageParams> Create(const PtJson ¶ms); 1028 GetCallCount()1029 bool GetCallCount() const 1030 { 1031 return callCount_.value_or(false); 1032 } 1033 HasCallCount()1034 bool HasCallCount() const 1035 { 1036 return callCount_.has_value(); 1037 } 1038 GetDetailed()1039 bool GetDetailed() const 1040 { 1041 return detailed_.value_or(false); 1042 } 1043 HasDetailed()1044 bool HasDetailed() const 1045 { 1046 return detailed_.has_value(); 1047 } 1048 GetAllowTriggeredUpdates()1049 bool GetAllowTriggeredUpdates() const 1050 { 1051 return allowTriggeredUpdates_.value_or(false); 1052 } 1053 HasAllowTriggeredUpdates()1054 bool HasAllowTriggeredUpdates() const 1055 { 1056 return allowTriggeredUpdates_.has_value(); 1057 } 1058 1059 private: 1060 NO_COPY_SEMANTIC(StartPreciseCoverageParams); 1061 NO_MOVE_SEMANTIC(StartPreciseCoverageParams); 1062 1063 std::optional<bool> callCount_ {}; 1064 std::optional<bool> detailed_ {}; 1065 std::optional<bool> allowTriggeredUpdates_ {}; 1066 }; 1067 1068 class SetSamplingIntervalParams : public PtBaseParams { 1069 public: 1070 SetSamplingIntervalParams() = default; 1071 ~SetSamplingIntervalParams() override = default; 1072 1073 static std::unique_ptr<SetSamplingIntervalParams> Create(const PtJson ¶ms); 1074 GetInterval()1075 int32_t GetInterval() const 1076 { 1077 return interval_; 1078 } 1079 SetInterval(int32_t interval)1080 SetSamplingIntervalParams &SetInterval(int32_t interval) 1081 { 1082 interval_ = interval; 1083 return *this; 1084 } 1085 1086 private: 1087 NO_COPY_SEMANTIC(SetSamplingIntervalParams); 1088 NO_MOVE_SEMANTIC(SetSamplingIntervalParams); 1089 1090 int32_t interval_ {0}; 1091 }; 1092 1093 class RecordClockSyncMarkerParams : public PtBaseParams { 1094 public: 1095 RecordClockSyncMarkerParams() = default; 1096 ~RecordClockSyncMarkerParams() override = default; 1097 1098 static std::unique_ptr<RecordClockSyncMarkerParams> Create(const PtJson ¶ms); 1099 GetSyncId()1100 std::string GetSyncId() const 1101 { 1102 return syncId_; 1103 } 1104 SetSyncId(std::string syncId)1105 RecordClockSyncMarkerParams &SetSyncId(std::string syncId) 1106 { 1107 syncId_ = syncId; 1108 return *this; 1109 } 1110 1111 private: 1112 NO_COPY_SEMANTIC(RecordClockSyncMarkerParams); 1113 NO_MOVE_SEMANTIC(RecordClockSyncMarkerParams); 1114 1115 std::string syncId_ {}; 1116 }; 1117 1118 class RequestMemoryDumpParams : public PtBaseParams { 1119 public: 1120 RequestMemoryDumpParams() = default; 1121 ~RequestMemoryDumpParams() override = default; 1122 1123 static std::unique_ptr<RequestMemoryDumpParams> Create(const PtJson ¶ms); 1124 GetDeterministic()1125 bool GetDeterministic() const 1126 { 1127 return deterministic_.value(); 1128 } 1129 SetDeterministic(bool deterministic)1130 RequestMemoryDumpParams &SetDeterministic(bool deterministic) 1131 { 1132 deterministic_ = deterministic; 1133 return *this; 1134 } 1135 HasDeterministic()1136 bool HasDeterministic() const 1137 { 1138 return deterministic_.has_value(); 1139 } 1140 GetLevelOfDetail()1141 MemoryDumpLevelOfDetail GetLevelOfDetail() const 1142 { 1143 return levelOfDetail_.value(); 1144 } 1145 SetLevelOfDetail(const MemoryDumpLevelOfDetail & levelOfDetail)1146 RequestMemoryDumpParams &SetLevelOfDetail(const MemoryDumpLevelOfDetail &levelOfDetail) 1147 { 1148 levelOfDetail_ = levelOfDetail; 1149 return *this; 1150 } 1151 HasLevelOfDetail()1152 bool HasLevelOfDetail() const 1153 { 1154 return levelOfDetail_.has_value(); 1155 } 1156 1157 private: 1158 NO_COPY_SEMANTIC(RequestMemoryDumpParams); 1159 NO_MOVE_SEMANTIC(RequestMemoryDumpParams); 1160 1161 std::optional<bool> deterministic_ {}; 1162 std::optional<MemoryDumpLevelOfDetail> levelOfDetail_ {}; 1163 }; 1164 1165 class StartParams : public PtBaseParams { 1166 public: 1167 StartParams() = default; 1168 ~StartParams() override = default; 1169 1170 static std::unique_ptr<StartParams> Create(const PtJson ¶ms); 1171 GetCategories()1172 std::string GetCategories() const 1173 { 1174 return categories_.value(); 1175 } 1176 SetCategories(std::string categories)1177 StartParams &SetCategories(std::string categories) 1178 { 1179 categories_ = categories; 1180 return *this; 1181 } 1182 HasCategories()1183 bool HasCategories() const 1184 { 1185 return categories_.has_value(); 1186 } 1187 GetOptions()1188 std::string GetOptions() const 1189 { 1190 return options_.value(); 1191 } 1192 SetOptions(std::string options)1193 StartParams &SetOptions(std::string options) 1194 { 1195 options_ = options; 1196 return *this; 1197 } 1198 HasOptions()1199 bool HasOptions() const 1200 { 1201 return options_.has_value(); 1202 } 1203 GetBufferUsageReportingInterval()1204 int32_t GetBufferUsageReportingInterval() const 1205 { 1206 return bufferUsageReportingInterval_.value(); 1207 } 1208 SetBufferUsageReportingInterval(int32_t bufferUsageReportingInterval)1209 StartParams &SetBufferUsageReportingInterval(int32_t bufferUsageReportingInterval) 1210 { 1211 bufferUsageReportingInterval_ = bufferUsageReportingInterval; 1212 return *this; 1213 } 1214 HasBufferUsageReportingInterval()1215 bool HasBufferUsageReportingInterval() const 1216 { 1217 return bufferUsageReportingInterval_.has_value(); 1218 } 1219 GetTransferMode()1220 std::string GetTransferMode() const 1221 { 1222 return transferMode_.value(); 1223 } 1224 SetTransferMode(std::string transferMode)1225 StartParams &SetTransferMode(std::string transferMode) 1226 { 1227 transferMode_ = transferMode; 1228 return *this; 1229 } 1230 HasTransferMode()1231 bool HasTransferMode() const 1232 { 1233 return transferMode_.has_value(); 1234 } 1235 1236 struct TransferModeValues { ValidTransferModeValues1237 static bool Valid(const std::string &values) 1238 { 1239 return values == ReportEvents() || values == ReturnAsStream(); 1240 } ReportEventsTransferModeValues1241 static std::string ReportEvents() 1242 { 1243 return "ReportEvents"; 1244 } ReturnAsStreamTransferModeValues1245 static std::string ReturnAsStream() 1246 { 1247 return "ReturnAsStream"; 1248 } 1249 }; 1250 GetStreamFormat()1251 StreamFormat GetStreamFormat() const 1252 { 1253 return streamFormat_.value(); 1254 } 1255 SetStreamFormat(const StreamFormat & streamFormat)1256 StartParams &SetStreamFormat(const StreamFormat &streamFormat) 1257 { 1258 streamFormat_ = streamFormat; 1259 return *this; 1260 } 1261 HasStreamFormat()1262 bool HasStreamFormat() const 1263 { 1264 return streamFormat_.has_value(); 1265 } 1266 GetStreamCompression()1267 StreamCompression GetStreamCompression() const 1268 { 1269 return streamCompression_.value(); 1270 } 1271 SetStreamCompression(const StreamCompression & streamCompression)1272 StartParams &SetStreamCompression(const StreamCompression &streamCompression) 1273 { 1274 streamCompression_ = streamCompression; 1275 return *this; 1276 } 1277 HasStreamCompression()1278 bool HasStreamCompression() const 1279 { 1280 return streamCompression_.has_value(); 1281 } 1282 GetTraceConfig()1283 TraceConfig *GetTraceConfig() const 1284 { 1285 if (traceConfig_) { 1286 return traceConfig_->get(); 1287 } 1288 return nullptr; 1289 } 1290 SetTraceConfig(std::unique_ptr<TraceConfig> & traceConfig)1291 StartParams &SetTraceConfig(std::unique_ptr<TraceConfig> &traceConfig) 1292 { 1293 traceConfig_ = std::move(traceConfig); 1294 return *this; 1295 } 1296 HasTraceConfig()1297 bool HasTraceConfig() const 1298 { 1299 return traceConfig_.has_value(); 1300 } 1301 GetPerfettoConfig()1302 std::string GetPerfettoConfig() const 1303 { 1304 return perfettoConfig_.value(); 1305 } 1306 SetPerfettoConfig(std::string perfettoConfig)1307 StartParams &SetPerfettoConfig(std::string perfettoConfig) 1308 { 1309 perfettoConfig_ = perfettoConfig; 1310 return *this; 1311 } 1312 HasPerfettoConfig()1313 bool HasPerfettoConfig() const 1314 { 1315 return perfettoConfig_.has_value(); 1316 } 1317 GetTracingBackend()1318 TracingBackend GetTracingBackend() const 1319 { 1320 return tracingBackend_.value(); 1321 } 1322 SetTracingBackend(const TracingBackend & tracingBackend)1323 StartParams &SetTracingBackend(const TracingBackend &tracingBackend) 1324 { 1325 tracingBackend_ = tracingBackend; 1326 return *this; 1327 } 1328 HasTracingBackend()1329 bool HasTracingBackend() const 1330 { 1331 return tracingBackend_.has_value(); 1332 } 1333 1334 private: 1335 NO_COPY_SEMANTIC(StartParams); 1336 NO_MOVE_SEMANTIC(StartParams); 1337 1338 std::optional<std::string> categories_ {}; 1339 std::optional<std::string> options_ {}; 1340 std::optional<int32_t> bufferUsageReportingInterval_ {}; 1341 std::optional<std::string> transferMode_ {}; 1342 std::optional<StreamFormat> streamFormat_ {}; 1343 std::optional<StreamCompression> streamCompression_ {}; 1344 std::optional<std::unique_ptr<TraceConfig>> traceConfig_ {}; 1345 std::optional<std::string> perfettoConfig_ {}; 1346 std::optional<TracingBackend> tracingBackend_ {}; 1347 }; 1348 1349 class SeriliazationTimeoutCheckEnableParams : public PtBaseParams { 1350 public: 1351 SeriliazationTimeoutCheckEnableParams() = default; 1352 ~SeriliazationTimeoutCheckEnableParams() override = default; 1353 1354 static std::unique_ptr<SeriliazationTimeoutCheckEnableParams> Create(const PtJson ¶ms); 1355 GetThreshold()1356 int32_t GetThreshold() const 1357 { 1358 return threshold_; 1359 } 1360 SetThreshold(int32_t threshold)1361 SeriliazationTimeoutCheckEnableParams &SetThreshold(int32_t threshold) 1362 { 1363 threshold_ = threshold; 1364 return *this; 1365 } 1366 1367 private: 1368 NO_COPY_SEMANTIC(SeriliazationTimeoutCheckEnableParams); 1369 NO_MOVE_SEMANTIC(SeriliazationTimeoutCheckEnableParams); 1370 static constexpr int32_t DEFAULT_THRESHOLD = 8; 1371 int32_t threshold_ { DEFAULT_THRESHOLD }; 1372 }; 1373 } // namespace panda::ecmascript::tooling 1374 #endif