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