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_EVENTS_H 17 #define ECMASCRIPT_TOOLING_BASE_PT_EVENTS_H 18 19 #include <memory> 20 #include <optional> 21 22 #include "libpandabase/macros.h" 23 #include "ecmascript/tooling/base/pt_script.h" 24 #include "ecmascript/tooling/base/pt_types.h" 25 #include "ecmascript/tooling/dispatcher.h" 26 27 namespace panda::ecmascript::tooling { 28 class PtBaseEvents : public PtBaseTypes { 29 public: 30 PtBaseEvents() = default; 31 ~PtBaseEvents() override = default; 32 virtual std::string GetName() const = 0; 33 34 private: 35 NO_COPY_SEMANTIC(PtBaseEvents); 36 NO_MOVE_SEMANTIC(PtBaseEvents); 37 }; 38 39 class BreakpointResolved final : public PtBaseEvents { 40 public: 41 BreakpointResolved() = default; 42 ~BreakpointResolved() override = default; 43 std::unique_ptr<PtJson> ToJson() const override; 44 GetName()45 std::string GetName() const override 46 { 47 return "Debugger.breakpointResolved"; 48 } 49 GetBreakpointId()50 BreakpointId GetBreakpointId() const 51 { 52 return breakpointId_; 53 } 54 SetBreakpointId(const BreakpointId & breakpointId)55 BreakpointResolved &SetBreakpointId(const BreakpointId &breakpointId) 56 { 57 breakpointId_ = breakpointId; 58 return *this; 59 } 60 GetLocation()61 Location *GetLocation() const 62 { 63 return location_.get(); 64 } 65 SetLocation(std::unique_ptr<Location> location)66 BreakpointResolved &SetLocation(std::unique_ptr<Location> location) 67 { 68 location_ = std::move(location); 69 return *this; 70 } 71 72 private: 73 NO_COPY_SEMANTIC(BreakpointResolved); 74 NO_MOVE_SEMANTIC(BreakpointResolved); 75 76 BreakpointId breakpointId_ {}; 77 std::unique_ptr<Location> location_ {nullptr}; 78 }; 79 80 class Paused final : public PtBaseEvents { 81 public: 82 Paused() = default; 83 ~Paused() override = default; 84 std::unique_ptr<PtJson> ToJson() const override; 85 GetName()86 std::string GetName() const override 87 { 88 return "Debugger.paused"; 89 } 90 GetCallFrames()91 const std::vector<std::unique_ptr<CallFrame>> *GetCallFrames() const 92 { 93 return &callFrames_; 94 } 95 SetCallFrames(std::vector<std::unique_ptr<CallFrame>> callFrames)96 Paused &SetCallFrames(std::vector<std::unique_ptr<CallFrame>> callFrames) 97 { 98 callFrames_ = std::move(callFrames); 99 return *this; 100 } 101 GetReason()102 const std::string &GetReason() const 103 { 104 return reason_; 105 } 106 SetReason(PauseReason reason)107 Paused &SetReason(PauseReason reason) 108 { 109 reason_ = GetReasonString(reason); 110 return *this; 111 } 112 GetReasonString(PauseReason reason)113 static std::string GetReasonString(PauseReason reason) 114 { 115 switch (reason) { 116 case AMBIGUOUS: { 117 return "ambiguous"; 118 } 119 case ASSERT: { 120 return "assert"; 121 } 122 case DEBUGCOMMAND: { 123 return "debugCommand"; 124 } 125 case DOM: { 126 return "DOM"; 127 } 128 case EVENTLISTENER: { 129 return "EventListener"; 130 } 131 case EXCEPTION: { 132 return "exception"; 133 } 134 case INSTRUMENTATION: { 135 return "instrumentation"; 136 } 137 case OOM: { 138 return "OOM"; 139 } 140 case OTHER: { 141 return "other"; 142 } 143 case PROMISEREJECTION: { 144 return "promiseRejection"; 145 } 146 case XHR: { 147 return "XHR"; 148 } 149 case BREAK_ON_START: { 150 return "Break on start"; 151 } 152 default: { 153 LOG(ERROR, DEBUGGER) << "Unknown paused reason: " << reason; 154 } 155 } 156 return ""; 157 } 158 GetData()159 RemoteObject *GetData() const 160 { 161 if (data_) { 162 return data_->get(); 163 } 164 return nullptr; 165 } 166 SetData(std::unique_ptr<RemoteObject> data)167 Paused &SetData(std::unique_ptr<RemoteObject> data) 168 { 169 data_ = std::move(data); 170 return *this; 171 } 172 HasData()173 bool HasData() const 174 { 175 return data_.has_value(); 176 } 177 GetHitBreakpoints()178 std::vector<BreakpointId> GetHitBreakpoints() const 179 { 180 return hitBreakpoints_.value_or(std::vector<BreakpointId>()); 181 } 182 SetHitBreakpoints(std::vector<BreakpointId> hitBreakpoints)183 Paused &SetHitBreakpoints(std::vector<BreakpointId> hitBreakpoints) 184 { 185 hitBreakpoints_ = std::move(hitBreakpoints); 186 return *this; 187 } 188 HasHitBreakpoints()189 bool HasHitBreakpoints() const 190 { 191 return hitBreakpoints_.has_value(); 192 } 193 194 private: 195 NO_COPY_SEMANTIC(Paused); 196 NO_MOVE_SEMANTIC(Paused); 197 198 std::vector<std::unique_ptr<CallFrame>> callFrames_ {}; 199 std::string reason_ {}; 200 std::optional<std::unique_ptr<RemoteObject>> data_ {}; 201 std::optional<std::vector<BreakpointId>> hitBreakpoints_ {}; 202 }; 203 204 class Resumed final : public PtBaseEvents { 205 public: 206 Resumed() = default; 207 ~Resumed() override = default; 208 std::unique_ptr<PtJson> ToJson() const override; 209 GetName()210 std::string GetName() const override 211 { 212 return "Debugger.resumed"; 213 } 214 215 private: 216 NO_COPY_SEMANTIC(Resumed); 217 NO_MOVE_SEMANTIC(Resumed); 218 }; 219 220 class ScriptFailedToParse final : public PtBaseEvents { 221 public: 222 ScriptFailedToParse() = default; 223 ~ScriptFailedToParse() override = default; 224 std::unique_ptr<PtJson> ToJson() const override; 225 GetName()226 std::string GetName() const override 227 { 228 return "Debugger.scriptFailedToParse"; 229 } 230 GetScriptId()231 ScriptId GetScriptId() const 232 { 233 return scriptId_; 234 } 235 SetScriptId(ScriptId scriptId)236 ScriptFailedToParse &SetScriptId(ScriptId scriptId) 237 { 238 scriptId_ = scriptId; 239 return *this; 240 } 241 GetUrl()242 const std::string &GetUrl() const 243 { 244 return url_; 245 } 246 SetUrl(const std::string & url)247 ScriptFailedToParse &SetUrl(const std::string &url) 248 { 249 url_ = url; 250 return *this; 251 } 252 GetStartLine()253 int32_t GetStartLine() const 254 { 255 return startLine_; 256 } 257 SetStartLine(int32_t startLine)258 ScriptFailedToParse &SetStartLine(int32_t startLine) 259 { 260 startLine_ = startLine; 261 return *this; 262 } 263 GetStartColumn()264 int32_t GetStartColumn() const 265 { 266 return startColumn_; 267 } 268 SetStartColumn(int32_t startColumn)269 ScriptFailedToParse &SetStartColumn(int32_t startColumn) 270 { 271 startColumn_ = startColumn; 272 return *this; 273 } 274 GetEndLine()275 int32_t GetEndLine() const 276 { 277 return endLine_; 278 } 279 SetEndLine(int32_t endLine)280 ScriptFailedToParse &SetEndLine(int32_t endLine) 281 { 282 endLine_ = endLine; 283 return *this; 284 } 285 GetEndColumn()286 int32_t GetEndColumn() const 287 { 288 return endColumn_; 289 } 290 SetEndColumn(int32_t endColumn)291 ScriptFailedToParse &SetEndColumn(int32_t endColumn) 292 { 293 endColumn_ = endColumn; 294 return *this; 295 } 296 GetExecutionContextId()297 int32_t GetExecutionContextId() const 298 { 299 return executionContextId_; 300 } 301 SetExecutionContextId(int32_t executionContextId)302 ScriptFailedToParse &SetExecutionContextId(int32_t executionContextId) 303 { 304 executionContextId_ = executionContextId; 305 return *this; 306 } 307 GetHash()308 const std::string &GetHash() const 309 { 310 return hash_; 311 } 312 SetHash(const std::string & hash)313 ScriptFailedToParse &SetHash(const std::string &hash) 314 { 315 hash_ = hash; 316 return *this; 317 } 318 GetExecutionContextAuxData()319 Local<ObjectRef> GetExecutionContextAuxData() const 320 { 321 return execContextAuxData_.value_or(Local<ObjectRef>()); 322 } 323 SetExecutionContextAuxData(Local<ObjectRef> execContextAuxData)324 ScriptFailedToParse &SetExecutionContextAuxData(Local<ObjectRef> execContextAuxData) 325 { 326 execContextAuxData_ = execContextAuxData; 327 return *this; 328 } 329 HasExecutionContextAuxData()330 bool HasExecutionContextAuxData() const 331 { 332 return execContextAuxData_.has_value(); 333 } 334 GetSourceMapURL()335 const std::string &GetSourceMapURL() const 336 { 337 ASSERT(HasSourceMapUrl()); 338 return sourceMapUrl_.value(); 339 } 340 SetSourceMapURL(const std::string & sourceMapUrl)341 ScriptFailedToParse &SetSourceMapURL(const std::string &sourceMapUrl) 342 { 343 sourceMapUrl_ = sourceMapUrl; 344 return *this; 345 } 346 HasSourceMapUrl()347 bool HasSourceMapUrl() const 348 { 349 return sourceMapUrl_.has_value(); 350 } 351 GetHasSourceURL()352 bool GetHasSourceURL() const 353 { 354 return hasSourceUrl_.value_or(false); 355 } 356 SetHasSourceURL(bool hasSourceUrl)357 ScriptFailedToParse &SetHasSourceURL(bool hasSourceUrl) 358 { 359 hasSourceUrl_ = hasSourceUrl; 360 return *this; 361 } 362 HasHasSourceURL()363 bool HasHasSourceURL() const 364 { 365 return hasSourceUrl_.has_value(); 366 } 367 GetIsModule()368 bool GetIsModule() const 369 { 370 return isModule_.value_or(false); 371 } 372 SetIsModule(bool isModule)373 ScriptFailedToParse &SetIsModule(bool isModule) 374 { 375 isModule_ = isModule; 376 return *this; 377 } 378 HasIsModule()379 bool HasIsModule() const 380 { 381 return isModule_.has_value(); 382 } 383 GetLength()384 int32_t GetLength() const 385 { 386 return length_.value_or(0); 387 } 388 SetLength(int32_t length)389 ScriptFailedToParse &SetLength(int32_t length) 390 { 391 length_ = length; 392 return *this; 393 } 394 HasLength()395 bool HasLength() const 396 { 397 return length_.has_value(); 398 } 399 GetCodeOffset()400 int32_t GetCodeOffset() const 401 { 402 return codeOffset_.value_or(0); 403 } 404 SetCodeOffset(int32_t codeOffset)405 ScriptFailedToParse &SetCodeOffset(int32_t codeOffset) 406 { 407 codeOffset_ = codeOffset; 408 return *this; 409 } 410 HasCodeOffset()411 bool HasCodeOffset() const 412 { 413 return codeOffset_.has_value(); 414 } 415 GetScriptLanguage()416 const std::string &GetScriptLanguage() const 417 { 418 ASSERT(HasScriptLanguage()); 419 return scriptLanguage_.value(); 420 } 421 SetScriptLanguage(const std::string & scriptLanguage)422 ScriptFailedToParse &SetScriptLanguage(const std::string &scriptLanguage) 423 { 424 scriptLanguage_ = scriptLanguage; 425 return *this; 426 } 427 HasScriptLanguage()428 bool HasScriptLanguage() const 429 { 430 return scriptLanguage_.has_value(); 431 } 432 GetEmbedderName()433 const std::string &GetEmbedderName() const 434 { 435 ASSERT(HasEmbedderName()); 436 return embedderName_.value(); 437 } 438 SetEmbedderName(const std::string & embedderName)439 ScriptFailedToParse &SetEmbedderName(const std::string &embedderName) 440 { 441 embedderName_ = embedderName; 442 return *this; 443 } 444 HasEmbedderName()445 bool HasEmbedderName() const 446 { 447 return embedderName_.has_value(); 448 } 449 450 private: 451 NO_COPY_SEMANTIC(ScriptFailedToParse); 452 NO_MOVE_SEMANTIC(ScriptFailedToParse); 453 454 ScriptId scriptId_ {0}; 455 std::string url_ {}; 456 int32_t startLine_ {0}; 457 int32_t startColumn_ {0}; 458 int32_t endLine_ {0}; 459 int32_t endColumn_ {0}; 460 ExecutionContextId executionContextId_ {0}; 461 std::string hash_ {}; 462 std::optional<Local<ObjectRef>> execContextAuxData_ {}; 463 std::optional<std::string> sourceMapUrl_ {}; 464 std::optional<bool> hasSourceUrl_ {}; 465 std::optional<bool> isModule_ {}; 466 std::optional<int32_t> length_ {}; 467 std::optional<int32_t> codeOffset_ {}; 468 std::optional<std::string> scriptLanguage_ {}; 469 std::optional<std::string> embedderName_ {}; 470 }; 471 472 class ScriptParsed final : public PtBaseEvents { 473 public: 474 ScriptParsed() = default; 475 ~ScriptParsed() override = default; 476 std::unique_ptr<PtJson> ToJson() const override; 477 GetName()478 std::string GetName() const override 479 { 480 return "Debugger.scriptParsed"; 481 } 482 GetScriptId()483 ScriptId GetScriptId() const 484 { 485 return scriptId_; 486 } 487 SetScriptId(ScriptId scriptId)488 ScriptParsed &SetScriptId(ScriptId scriptId) 489 { 490 scriptId_ = scriptId; 491 return *this; 492 } 493 GetUrl()494 const std::string &GetUrl() const 495 { 496 return url_; 497 } 498 SetUrl(const std::string & url)499 ScriptParsed &SetUrl(const std::string &url) 500 { 501 url_ = url; 502 return *this; 503 } 504 GetStartLine()505 int32_t GetStartLine() const 506 { 507 return startLine_; 508 } 509 SetStartLine(int32_t startLine)510 ScriptParsed &SetStartLine(int32_t startLine) 511 { 512 startLine_ = startLine; 513 return *this; 514 } 515 GetStartColumn()516 int32_t GetStartColumn() const 517 { 518 return startColumn_; 519 } 520 SetStartColumn(int32_t startColumn)521 ScriptParsed &SetStartColumn(int32_t startColumn) 522 { 523 startColumn_ = startColumn; 524 return *this; 525 } 526 GetEndLine()527 int32_t GetEndLine() const 528 { 529 return endLine_; 530 } 531 SetEndLine(int32_t endLine)532 ScriptParsed &SetEndLine(int32_t endLine) 533 { 534 endLine_ = endLine; 535 return *this; 536 } 537 GetEndColumn()538 int32_t GetEndColumn() const 539 { 540 return endColumn_; 541 } 542 SetEndColumn(int32_t endColumn)543 ScriptParsed &SetEndColumn(int32_t endColumn) 544 { 545 endColumn_ = endColumn; 546 return *this; 547 } 548 GetExecutionContextId()549 int32_t GetExecutionContextId() const 550 { 551 return executionContextId_; 552 } 553 SetExecutionContextId(int32_t executionContextId)554 ScriptParsed &SetExecutionContextId(int32_t executionContextId) 555 { 556 executionContextId_ = executionContextId; 557 return *this; 558 } 559 GetHash()560 const std::string &GetHash() const 561 { 562 return hash_; 563 } 564 SetHash(const std::string & hash)565 ScriptParsed &SetHash(const std::string &hash) 566 { 567 hash_ = hash; 568 return *this; 569 } 570 GetIsLiveEdit()571 bool GetIsLiveEdit() const 572 { 573 return isLiveEdit_.value_or(false); 574 } 575 SetIsLiveEdit(bool isLiveEdit)576 ScriptParsed &SetIsLiveEdit(bool isLiveEdit) 577 { 578 isLiveEdit_ = isLiveEdit; 579 return *this; 580 } 581 HasIsLiveEdit()582 bool HasIsLiveEdit() const 583 { 584 return isLiveEdit_.has_value(); 585 } 586 GetExecutionContextAuxData()587 Local<ObjectRef> GetExecutionContextAuxData() const 588 { 589 return execContextAuxData_.value_or(Local<ObjectRef>()); 590 } 591 SetExecutionContextAuxData(Local<ObjectRef> execContextAuxData)592 ScriptParsed &SetExecutionContextAuxData(Local<ObjectRef> execContextAuxData) 593 { 594 execContextAuxData_ = execContextAuxData; 595 return *this; 596 } 597 HasExecutionContextAuxData()598 bool HasExecutionContextAuxData() const 599 { 600 return execContextAuxData_.has_value(); 601 } 602 GetSourceMapURL()603 const std::string &GetSourceMapURL() const 604 { 605 ASSERT(HasSourceMapUrl()); 606 return sourceMapUrl_.value(); 607 } 608 SetSourceMapURL(const std::string & sourceMapUrl)609 ScriptParsed &SetSourceMapURL(const std::string &sourceMapUrl) 610 { 611 sourceMapUrl_ = sourceMapUrl; 612 return *this; 613 } 614 HasSourceMapUrl()615 bool HasSourceMapUrl() const 616 { 617 return sourceMapUrl_.has_value(); 618 } 619 GetHasSourceURL()620 bool GetHasSourceURL() const 621 { 622 return hasSourceUrl_.value_or(false); 623 } 624 SetHasSourceURL(bool hasSourceUrl)625 ScriptParsed &SetHasSourceURL(bool hasSourceUrl) 626 { 627 hasSourceUrl_ = hasSourceUrl; 628 return *this; 629 } 630 HasHasSourceURL()631 bool HasHasSourceURL() const 632 { 633 return hasSourceUrl_.has_value(); 634 } 635 GetIsModule()636 bool GetIsModule() const 637 { 638 return isModule_.value_or(false); 639 } 640 SetIsModule(bool isModule)641 ScriptParsed &SetIsModule(bool isModule) 642 { 643 isModule_ = isModule; 644 return *this; 645 } 646 HasIsModule()647 bool HasIsModule() const 648 { 649 return isModule_.has_value(); 650 } 651 GetLength()652 int32_t GetLength() const 653 { 654 return length_.value_or(0); 655 } 656 SetLength(int32_t length)657 ScriptParsed &SetLength(int32_t length) 658 { 659 length_ = length; 660 return *this; 661 } 662 HasLength()663 bool HasLength() const 664 { 665 return length_.has_value(); 666 } 667 GetCodeOffset()668 int32_t GetCodeOffset() const 669 { 670 return codeOffset_.value_or(0); 671 } 672 SetCodeOffset(int32_t codeOffset)673 ScriptParsed &SetCodeOffset(int32_t codeOffset) 674 { 675 codeOffset_ = codeOffset; 676 return *this; 677 } 678 HasCodeOffset()679 bool HasCodeOffset() const 680 { 681 return codeOffset_.has_value(); 682 } 683 GetScriptLanguage()684 const std::string &GetScriptLanguage() const 685 { 686 ASSERT(HasScriptLanguage()); 687 return scriptLanguage_.value(); 688 } 689 SetScriptLanguage(const std::string & scriptLanguage)690 ScriptParsed &SetScriptLanguage(const std::string &scriptLanguage) 691 { 692 scriptLanguage_ = scriptLanguage; 693 return *this; 694 } 695 HasScriptLanguage()696 bool HasScriptLanguage() const 697 { 698 return scriptLanguage_.has_value(); 699 } 700 GetEmbedderName()701 const std::string &GetEmbedderName() const 702 { 703 ASSERT(HasEmbedderName()); 704 return embedderName_.value(); 705 } 706 SetEmbedderName(const std::string & embedderName)707 ScriptParsed &SetEmbedderName(const std::string &embedderName) 708 { 709 embedderName_ = embedderName; 710 return *this; 711 } 712 HasEmbedderName()713 bool HasEmbedderName() const 714 { 715 return embedderName_.has_value(); 716 } 717 718 private: 719 NO_COPY_SEMANTIC(ScriptParsed); 720 NO_MOVE_SEMANTIC(ScriptParsed); 721 722 ScriptId scriptId_ {0}; 723 std::string url_ {}; 724 int32_t startLine_ {0}; 725 int32_t startColumn_ {0}; 726 int32_t endLine_ {0}; 727 int32_t endColumn_ {0}; 728 ExecutionContextId executionContextId_ {0}; 729 std::string hash_ {}; 730 std::optional<Local<ObjectRef>> execContextAuxData_ {}; 731 std::optional<bool> isLiveEdit_ {}; 732 std::optional<std::string> sourceMapUrl_ {}; 733 std::optional<bool> hasSourceUrl_ {}; 734 std::optional<bool> isModule_ {}; 735 std::optional<int32_t> length_ {}; 736 std::optional<int32_t> codeOffset_ {}; 737 std::optional<std::string> scriptLanguage_ {}; 738 std::optional<std::string> embedderName_ {}; 739 }; 740 741 #ifdef SUPPORT_PROFILER_CDP 742 class AddHeapSnapshotChunk final : public PtBaseEvents { 743 public: 744 AddHeapSnapshotChunk() = default; 745 ~AddHeapSnapshotChunk() override = default; 746 std::unique_ptr<PtJson> ToJson() const override; 747 GetName()748 std::string GetName() const override 749 { 750 return "HeapProfiler.addHeapSnapshotChunk"; 751 } 752 GetChunk()753 std::string &GetChunk() 754 { 755 return chunk_; 756 } 757 758 private: 759 NO_COPY_SEMANTIC(AddHeapSnapshotChunk); 760 NO_MOVE_SEMANTIC(AddHeapSnapshotChunk); 761 762 std::string chunk_ {}; 763 }; 764 765 class ConsoleProfileFinished final : public PtBaseEvents { 766 public: 767 ConsoleProfileFinished() = default; 768 ~ConsoleProfileFinished() override = default; 769 std::unique_ptr<PtJson> ToJson() const override; GetName()770 std::string GetName() const override 771 { 772 return "Profile.ConsoleProfileFinished"; 773 } 774 GetId()775 const std::string &GetId() const 776 { 777 return id_; 778 } 779 SetId(const std::string & id)780 ConsoleProfileFinished &SetId(const std::string &id) 781 { 782 id_ = id; 783 return *this; 784 } 785 GetLocation()786 Location *GetLocation() const 787 { 788 return location_.get(); 789 } 790 SetLocation(std::unique_ptr<Location> location)791 ConsoleProfileFinished &SetLocation(std::unique_ptr<Location> location) 792 { 793 location_ = std::move(location); 794 return *this; 795 } 796 GetProfile()797 Profile *GetProfile() const 798 { 799 return profile_.get(); 800 } 801 SetProfile(std::unique_ptr<Profile> profile)802 ConsoleProfileFinished &SetProfile(std::unique_ptr<Profile> profile) 803 { 804 profile_ = std::move(profile); 805 return *this; 806 } 807 GetTitle()808 const std::string &GetTitle() const 809 { 810 ASSERT(HasTitle()); 811 return title_.value(); 812 } 813 SetTitle(const std::string & title)814 ConsoleProfileFinished &SetTitle(const std::string &title) 815 { 816 title_ = title; 817 return *this; 818 } 819 HasTitle()820 bool HasTitle() const 821 { 822 return title_.has_value(); 823 } 824 825 private: 826 NO_COPY_SEMANTIC(ConsoleProfileFinished); 827 NO_MOVE_SEMANTIC(ConsoleProfileFinished); 828 829 std::string id_ {}; 830 std::unique_ptr<Location> location_ {nullptr}; 831 std::unique_ptr<Profile> profile_ {nullptr}; 832 std::optional<std::string> title_ {}; 833 }; 834 835 class ConsoleProfileStarted final : public PtBaseEvents { 836 public: 837 ConsoleProfileStarted() = default; 838 ~ConsoleProfileStarted() override = default; 839 std::unique_ptr<PtJson> ToJson() const override; GetName()840 std::string GetName() const override 841 { 842 return "Profile.ConsoleProfileStarted"; 843 } 844 GetId()845 const std::string &GetId() const 846 { 847 return id_; 848 } 849 SetId(const std::string & id)850 ConsoleProfileStarted &SetId(const std::string &id) 851 { 852 id_ = id; 853 return *this; 854 } 855 GetLocation()856 Location *GetLocation() const 857 { 858 return location_.get(); 859 } 860 SetLocation(std::unique_ptr<Location> location)861 ConsoleProfileStarted &SetLocation(std::unique_ptr<Location> location) 862 { 863 location_ = std::move(location); 864 return *this; 865 } 866 GetTitle()867 const std::string &GetTitle() const 868 { 869 ASSERT(HasTitle()); 870 return title_.value(); 871 } 872 SetTitle(const std::string & title)873 ConsoleProfileStarted &SetTitle(const std::string &title) 874 { 875 title_ = title; 876 return *this; 877 } 878 HasTitle()879 bool HasTitle() const 880 { 881 return title_.has_value(); 882 } 883 884 private: 885 NO_COPY_SEMANTIC(ConsoleProfileStarted); 886 NO_MOVE_SEMANTIC(ConsoleProfileStarted); 887 888 std::string id_ {}; 889 std::unique_ptr<Location> location_ {nullptr}; 890 std::optional<std::string> title_ {}; 891 }; 892 893 class PreciseCoverageDeltaUpdate final : public PtBaseEvents { 894 public: 895 PreciseCoverageDeltaUpdate() = default; 896 ~PreciseCoverageDeltaUpdate() override = default; 897 std::unique_ptr<PtJson> ToJson() const override; GetName()898 std::string GetName() const override 899 { 900 return "Profile.PreciseCoverageDeltaUpdate"; 901 } 902 GetTimestamp()903 int64_t GetTimestamp() const 904 { 905 return timestamp_; 906 } 907 SetTimestamp(int64_t timestamp)908 PreciseCoverageDeltaUpdate &SetTimestamp(int64_t timestamp) 909 { 910 timestamp_ = timestamp; 911 return *this; 912 } 913 GetOccasion()914 const std::string &GetOccasion() const 915 { 916 return occasion_; 917 } 918 SetOccasion(const std::string & occasion)919 PreciseCoverageDeltaUpdate &SetOccasion(const std::string &occasion) 920 { 921 occasion_ = occasion; 922 return *this; 923 } 924 GetResult()925 const std::vector<std::unique_ptr<ScriptCoverage>> *GetResult() const 926 { 927 return &result_; 928 } 929 SetResult(std::vector<std::unique_ptr<ScriptCoverage>> result)930 PreciseCoverageDeltaUpdate &SetResult(std::vector<std::unique_ptr<ScriptCoverage>> result) 931 { 932 result_ = std::move(result); 933 return *this; 934 } 935 936 private: 937 NO_COPY_SEMANTIC(PreciseCoverageDeltaUpdate); 938 NO_MOVE_SEMANTIC(PreciseCoverageDeltaUpdate); 939 940 int64_t timestamp_ {0}; 941 std::string occasion_ {}; 942 std::vector<std::unique_ptr<ScriptCoverage>> result_ {}; 943 }; 944 945 class HeapStatsUpdate final : public PtBaseEvents { 946 public: 947 HeapStatsUpdate() = default; 948 ~HeapStatsUpdate() override = default; 949 std::unique_ptr<PtJson> ToJson() const override; 950 GetName()951 std::string GetName() const override 952 { 953 return "HeapProfiler.heapStatsUpdate"; 954 } 955 GetStatsUpdate()956 const std::vector<int32_t> *GetStatsUpdate() const 957 { 958 return &statsUpdate_; 959 } 960 SetStatsUpdate(std::vector<int32_t> statsUpdate)961 HeapStatsUpdate &SetStatsUpdate(std::vector<int32_t> statsUpdate) 962 { 963 statsUpdate_ = std::move(statsUpdate); 964 return *this; 965 } 966 967 private: 968 NO_COPY_SEMANTIC(HeapStatsUpdate); 969 NO_MOVE_SEMANTIC(HeapStatsUpdate); 970 971 std::vector<int32_t> statsUpdate_ {}; 972 }; 973 974 class LastSeenObjectId final : public PtBaseEvents { 975 public: 976 LastSeenObjectId() = default; 977 ~LastSeenObjectId() override = default; 978 std::unique_ptr<PtJson> ToJson() const override; 979 GetName()980 std::string GetName() const override 981 { 982 return "HeapProfiler.lastSeenObjectId"; 983 } 984 GetLastSeenObjectId()985 int32_t GetLastSeenObjectId() const 986 { 987 return lastSeenObjectId_; 988 } 989 SetLastSeenObjectId(int32_t lastSeenObjectId)990 LastSeenObjectId &SetLastSeenObjectId(int32_t lastSeenObjectId) 991 { 992 lastSeenObjectId_ = lastSeenObjectId; 993 return *this; 994 } 995 GetTimestamp()996 int64_t GetTimestamp() const 997 { 998 return timestamp_; 999 } 1000 SetTimestamp(int64_t timestamp)1001 LastSeenObjectId &SetTimestamp(int64_t timestamp) 1002 { 1003 timestamp_ = timestamp; 1004 return *this; 1005 } 1006 1007 private: 1008 NO_COPY_SEMANTIC(LastSeenObjectId); 1009 NO_MOVE_SEMANTIC(LastSeenObjectId); 1010 1011 int32_t lastSeenObjectId_ {}; 1012 int64_t timestamp_ {}; 1013 }; 1014 1015 class ReportHeapSnapshotProgress final : public PtBaseEvents { 1016 public: 1017 ReportHeapSnapshotProgress() = default; 1018 ~ReportHeapSnapshotProgress() override = default; 1019 std::unique_ptr<PtJson> ToJson() const override; 1020 GetName()1021 std::string GetName() const override 1022 { 1023 return "HeapProfiler.reportHeapSnapshotProgress"; 1024 } 1025 GetDone()1026 int32_t GetDone() const 1027 { 1028 return done_; 1029 } 1030 SetDone(int32_t done)1031 ReportHeapSnapshotProgress &SetDone(int32_t done) 1032 { 1033 done_ = done; 1034 return *this; 1035 } 1036 GetTotal()1037 int32_t GetTotal() const 1038 { 1039 return total_; 1040 } 1041 SetTotal(int32_t total)1042 ReportHeapSnapshotProgress &SetTotal(int32_t total) 1043 { 1044 total_ = total; 1045 return *this; 1046 } 1047 GetFinished()1048 bool GetFinished() const 1049 { 1050 return finished_.value_or(false); 1051 } 1052 SetFinished(bool finished)1053 ReportHeapSnapshotProgress &SetFinished(bool finished) 1054 { 1055 finished_ = finished; 1056 return *this; 1057 } 1058 1059 private: 1060 NO_COPY_SEMANTIC(ReportHeapSnapshotProgress); 1061 NO_MOVE_SEMANTIC(ReportHeapSnapshotProgress); 1062 1063 int32_t done_ {}; 1064 int32_t total_ {}; 1065 std::optional<bool> finished_ {}; 1066 }; 1067 #endif 1068 } // namespace panda::ecmascript::tooling 1069 #endif 1070