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