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