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