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