• 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_TYPES_H
17 #define ECMASCRIPT_TOOLING_BASE_PT_TYPES_H
18 
19 #include <memory>
20 #include <optional>
21 
22 #include "base/pt_json.h"
23 
24 #include "ecmascript/debugger/debugger_api.h"
25 #include "ecmascript/dfx/cpu_profiler/samples_record.h"
26 #include "libpandabase/macros.h"
27 
28 namespace panda::ecmascript::tooling {
29 // ========== Base types begin
30 class PtBaseTypes {
31 public:
32     PtBaseTypes() = default;
33     virtual ~PtBaseTypes() = default;
34     virtual std::unique_ptr<PtJson> ToJson() const = 0;
35 
36 private:
37     NO_COPY_SEMANTIC(PtBaseTypes);
38     NO_MOVE_SEMANTIC(PtBaseTypes);
39 
40     friend class ProtocolHandler;
41     friend class DebuggerImpl;
42 };
43 
44 // ========== Debugger types begin
45 // Debugger.BreakpointId
46 using BreakpointId = std::string;
47 struct BreakpointDetails {
ToStringBreakpointDetails48     static BreakpointId ToString(const BreakpointDetails &metaData)
49     {
50         return "id:" + std::to_string(metaData.line_) + ":" + std::to_string(metaData.column_) + ":" +
51             metaData.url_;
52     }
53 
ParseBreakpointIdBreakpointDetails54     static bool ParseBreakpointId(const BreakpointId &id, BreakpointDetails *metaData)
55     {
56         auto lineStart = id.find(':');
57         if (lineStart == std::string::npos) {
58             return false;
59         }
60         auto columnStart = id.find(':', lineStart + 1);
61         if (columnStart == std::string::npos) {
62             return false;
63         }
64         auto urlStart = id.find(':', columnStart + 1);
65         if (urlStart == std::string::npos) {
66             return false;
67         }
68         std::string lineStr = id.substr(lineStart + 1, columnStart - lineStart - 1);
69         std::string columnStr = id.substr(columnStart + 1, urlStart - columnStart - 1);
70         std::string url = id.substr(urlStart + 1);
71         metaData->line_ = std::stoi(lineStr);
72         metaData->column_ = std::stoi(columnStr);
73         metaData->url_ = url;
74 
75         return true;
76     }
77 
78     int32_t line_ {0};
79     int32_t column_ {0};
80     std::string url_ {};
81 };
82 
83 // Debugger.CallFrameId
84 using CallFrameId = int32_t;
85 
86 // ========== Runtime types begin
87 // Runtime.ScriptId
88 using ScriptId = int32_t;
89 
90 // Runtime.RemoteObjectId
91 
92 using RemoteObjectId = int32_t;
93 
94 // Runtime.ExecutionContextId
95 using ExecutionContextId = int32_t;
96 
97 // Runtime.UnserializableValue
98 using UnserializableValue = std::string;
99 
100 // Runtime.UniqueDebuggerId
101 using UniqueDebuggerId = int32_t;
102 
103 // Runtime.RemoteObject
104 class RemoteObject : public PtBaseTypes {
105 public:
106     RemoteObject() = default;
107     ~RemoteObject() override = default;
108 
109     static std::unique_ptr<RemoteObject> FromTagged(const EcmaVM *ecmaVm, Local<JSValueRef> tagged);
110     static std::unique_ptr<RemoteObject> Create(const PtJson &params);
111     std::unique_ptr<PtJson> ToJson() const override;
112 
113     /*
114      * @see {#ObjectType}
115      */
GetType()116     const std::string &GetType() const
117     {
118         return type_;
119     }
120 
SetType(const std::string & type)121     RemoteObject &SetType(const std::string &type)
122     {
123         type_ = type;
124         return *this;
125     }
126     /*
127      * @see {#ObjectSubType}
128      */
GetSubType()129     const std::string &GetSubType() const
130     {
131         ASSERT(HasSubType());
132         return subType_.value();
133     }
134 
SetSubType(const std::string & type)135     RemoteObject &SetSubType(const std::string &type)
136     {
137         subType_ = type;
138         return *this;
139     }
140 
HasSubType()141     bool HasSubType() const
142     {
143         return subType_.has_value();
144     }
145 
GetClassName()146     const std::string &GetClassName() const
147     {
148         ASSERT(HasClassName());
149         return className_.value();
150     }
151 
SetClassName(const std::string & className)152     RemoteObject &SetClassName(const std::string &className)
153     {
154         className_ = className;
155         return *this;
156     }
157 
HasClassName()158     bool HasClassName() const
159     {
160         return className_.has_value();
161     }
162 
GetValue()163     Local<JSValueRef> GetValue() const
164     {
165         return value_.value_or(Local<JSValueRef>());
166     }
167 
SetValue(Local<JSValueRef> value)168     RemoteObject &SetValue(Local<JSValueRef> value)
169     {
170         value_ = value;
171         return *this;
172     }
173 
HasValue()174     bool HasValue() const
175     {
176         return value_.has_value();
177     }
178 
GetUnserializableValue()179     const UnserializableValue &GetUnserializableValue() const
180     {
181         ASSERT(HasUnserializableValue());
182         return unserializableValue_.value();
183     }
184 
SetUnserializableValue(const UnserializableValue & unserializableValue)185     RemoteObject &SetUnserializableValue(const UnserializableValue &unserializableValue)
186     {
187         unserializableValue_ = unserializableValue;
188         return *this;
189     }
190 
HasUnserializableValue()191     bool HasUnserializableValue() const
192     {
193         return unserializableValue_.has_value();
194     }
195 
GetDescription()196     const std::string &GetDescription() const
197     {
198         ASSERT(HasDescription());
199         return description_.value();
200     }
201 
SetDescription(const std::string & description)202     RemoteObject &SetDescription(const std::string &description)
203     {
204         description_ = description;
205         return *this;
206     }
207 
HasDescription()208     bool HasDescription() const
209     {
210         return description_.has_value();
211     }
212 
GetObjectId()213     RemoteObjectId GetObjectId() const
214     {
215         return objectId_.value_or(0);
216     }
217 
SetObjectId(RemoteObjectId objectId)218     RemoteObject &SetObjectId(RemoteObjectId objectId)
219     {
220         objectId_ = objectId;
221         return *this;
222     }
223 
HasObjectId()224     bool HasObjectId() const
225     {
226         return objectId_.has_value();
227     }
228 
229     struct TypeName {
230         static const std::string Object;     // NOLINT (readability-identifier-naming)
231         static const std::string Function;   // NOLINT (readability-identifier-naming)
232         static const std::string Undefined;  // NOLINT (readability-identifier-naming)
233         static const std::string String;     // NOLINT (readability-identifier-naming)
234         static const std::string Number;     // NOLINT (readability-identifier-naming)
235         static const std::string Boolean;    // NOLINT (readability-identifier-naming)
236         static const std::string Symbol;     // NOLINT (readability-identifier-naming)
237         static const std::string Bigint;     // NOLINT (readability-identifier-naming)
238         static const std::string Wasm;       // NOLINT (readability-identifier-naming)
ValidTypeName239         static bool Valid(const std::string &type)
240         {
241             return type == Object || type == Function || type == Undefined || type == String || type == Number ||
242                    type == Boolean || type == Symbol || type == Bigint || type == Wasm;
243         }
244     };
245 
246     struct SubTypeName {
247         static const std::string Array;        // NOLINT (readability-identifier-naming)
248         static const std::string Null;         // NOLINT (readability-identifier-naming)
249         static const std::string Node;         // NOLINT (readability-identifier-naming)
250         static const std::string Regexp;       // NOLINT (readability-identifier-naming)
251         static const std::string Date;         // NOLINT (readability-identifier-naming)
252         static const std::string Map;          // NOLINT (readability-identifier-naming)
253         static const std::string Set;          // NOLINT (readability-identifier-naming)
254         static const std::string Weakmap;      // NOLINT (readability-identifier-naming)
255         static const std::string Weakset;      // NOLINT (readability-identifier-naming)
256         static const std::string Iterator;     // NOLINT (readability-identifier-naming)
257         static const std::string Generator;    // NOLINT (readability-identifier-naming)
258         static const std::string Error;        // NOLINT (readability-identifier-naming)
259         static const std::string Proxy;        // NOLINT (readability-identifier-naming)
260         static const std::string Promise;      // NOLINT (readability-identifier-naming)
261         static const std::string Typedarray;   // NOLINT (readability-identifier-naming)
262         static const std::string Arraybuffer;  // NOLINT (readability-identifier-naming)
263         static const std::string Dataview;     // NOLINT (readability-identifier-naming)
264         static const std::string I32;          // NOLINT (readability-identifier-naming)
265         static const std::string I64;          // NOLINT (readability-identifier-naming)
266         static const std::string F32;          // NOLINT (readability-identifier-naming)
267         static const std::string F64;          // NOLINT (readability-identifier-naming)
268         static const std::string V128;         // NOLINT (readability-identifier-naming)
269         static const std::string Externref;    // NOLINT (readability-identifier-naming)
ValidSubTypeName270         static bool Valid(const std::string &type)
271         {
272             return type == Array || type == Null || type == Node || type == Regexp || type == Map || type == Set ||
273                    type == Weakmap || type == Iterator || type == Generator || type == Error || type == Proxy ||
274                    type == Promise || type == Typedarray || type == Arraybuffer || type == Dataview || type == I32 ||
275                    type == I64 || type == F32 || type == F64 || type == V128 || type == Externref;
276         }
277     };
278     struct ClassName {
279         static const std::string Object;          // NOLINT (readability-identifier-naming)
280         static const std::string Function;        // NOLINT (readability-identifier-naming)
281         static const std::string Array;           // NOLINT (readability-identifier-naming)
282         static const std::string Regexp;          // NOLINT (readability-identifier-naming)
283         static const std::string Date;            // NOLINT (readability-identifier-naming)
284         static const std::string Map;             // NOLINT (readability-identifier-naming)
285         static const std::string Set;             // NOLINT (readability-identifier-naming)
286         static const std::string Weakmap;         // NOLINT (readability-identifier-naming)
287         static const std::string Weakset;         // NOLINT (readability-identifier-naming)
288         static const std::string ArrayIterator;   // NOLINT (readability-identifier-naming)
289         static const std::string StringIterator;  // NOLINT (readability-identifier-naming)
290         static const std::string SetIterator;     // NOLINT (readability-identifier-naming)
291         static const std::string MapIterator;     // NOLINT (readability-identifier-naming)
292         static const std::string Iterator;        // NOLINT (readability-identifier-naming)
293         static const std::string Error;           // NOLINT (readability-identifier-naming)
294         static const std::string Proxy;           // NOLINT (readability-identifier-naming)
295         static const std::string Promise;         // NOLINT (readability-identifier-naming)
296         static const std::string Typedarray;      // NOLINT (readability-identifier-naming)
297         static const std::string Arraybuffer;     // NOLINT (readability-identifier-naming)
298         static const std::string Global;          // NOLINT (readability-identifier-naming)
299         static const std::string Generator;       // NOLINT (readability-identifier-naming)
ValidClassName300         static bool Valid(const std::string &type)
301         {
302             return type == Object || type == Array || type == Regexp || type == Date || type == Map || type == Set ||
303                    type == Weakmap || type == Weakset || type == ArrayIterator || type == StringIterator ||
304                    type == Error || type == SetIterator || type == MapIterator || type == Iterator || type == Proxy ||
305                    type == Promise || type == Typedarray || type == Arraybuffer || type == Function;
306         }
307     };
308     static const std::string ObjectDescription;          // NOLINT (readability-identifier-naming)
309     static const std::string GlobalDescription;          // NOLINT (readability-identifier-naming)
310     static const std::string ProxyDescription;           // NOLINT (readability-identifier-naming)
311     static const std::string PromiseDescription;         // NOLINT (readability-identifier-naming)
312     static const std::string ArrayIteratorDescription;   // NOLINT (readability-identifier-naming)
313     static const std::string StringIteratorDescription;  // NOLINT (readability-identifier-naming)
314     static const std::string SetIteratorDescription;     // NOLINT (readability-identifier-naming)
315     static const std::string MapIteratorDescription;     // NOLINT (readability-identifier-naming)
316     static const std::string WeakRefDescription;         // NOLINT (readability-identifier-naming)
317     static const std::string WeakMapDescription;         // NOLINT (readability-identifier-naming)
318     static const std::string WeakSetDescription;         // NOLINT (readability-identifier-naming)
319     static const std::string JSPrimitiveRefDescription;     // NOLINT (readability-identifier-naming)
320     static const std::string JSPrimitiveNumberDescription;  // NOLINT (readability-identifier-naming)
321     static const std::string JSPrimitiveBooleanDescription; // NOLINT (readability-identifier-naming)
322     static const std::string JSPrimitiveStringDescription;  // NOLINT (readability-identifier-naming)
323     static const std::string JSPrimitiveSymbolDescription;  // NOLINT (readability-identifier-naming)
324     static const std::string JSIntlDescription;             // NOLINT (readability-identifier-naming)
325     static const std::string DateTimeFormatDescription;     // NOLINT (readability-identifier-naming)
326     static const std::string NumberFormatDescription;       // NOLINT (readability-identifier-naming)
327     static const std::string CollatorDescription;           // NOLINT (readability-identifier-naming)
328     static const std::string PluralRulesDescription;        // NOLINT (readability-identifier-naming)
329     static const std::string JSLocaleDescription;              // NOLINT (readability-identifier-naming)
330     static const std::string JSListFormatDescription;          // NOLINT (readability-identifier-naming)
331     static const std::string JSRelativeTimeFormatDescription;  // NOLINT (readability-identifier-naming)
332 
333 private:
334     NO_COPY_SEMANTIC(RemoteObject);
335     NO_MOVE_SEMANTIC(RemoteObject);
336 
337     std::string type_ {};
338     std::optional<std::string> subType_ {};
339     std::optional<std::string> className_ {};
340     std::optional<Local<JSValueRef>> value_ {};
341     std::optional<UnserializableValue> unserializableValue_ {};
342     std::optional<std::string> description_ {};
343     std::optional<RemoteObjectId> objectId_ {};
344 };
345 
346 class PrimitiveRemoteObject final : public RemoteObject {
347 public:
348     PrimitiveRemoteObject(const EcmaVM *ecmaVm, Local<JSValueRef> tagged);
349     ~PrimitiveRemoteObject() override = default;
350 };
351 
352 class StringRemoteObject final : public RemoteObject {
353 public:
354     StringRemoteObject(const EcmaVM *ecmaVm, Local<StringRef> tagged);
355     ~StringRemoteObject() override = default;
356 };
357 
358 class SymbolRemoteObject final : public RemoteObject {
359 public:
360     SymbolRemoteObject(const EcmaVM *ecmaVm, Local<SymbolRef> tagged);
361     ~SymbolRemoteObject() override = default;
362 
363 private:
364     std::string DescriptionForSymbol(const EcmaVM *ecmaVm, Local<SymbolRef> tagged) const;
365 };
366 
367 class FunctionRemoteObject final : public RemoteObject {
368 public:
369     FunctionRemoteObject(const EcmaVM *ecmaVm, Local<JSValueRef> tagged);
370     ~FunctionRemoteObject() override = default;
371 
372 private:
373     std::string DescriptionForFunction(const EcmaVM *ecmaVm, Local<FunctionRef> tagged) const;
374 };
375 
376 class GeneratorFunctionRemoteObject final : public RemoteObject {
377 public:
378     GeneratorFunctionRemoteObject(const EcmaVM *ecmaVm, Local<JSValueRef> tagged);
379     ~GeneratorFunctionRemoteObject() override = default;
380 
381 private:
382     std::string DescriptionForGeneratorFunction(const EcmaVM *ecmaVm, Local<FunctionRef> tagged) const;
383 };
384 
385 class ObjectRemoteObject final : public RemoteObject {
386 public:
387     ObjectRemoteObject(const EcmaVM *ecmaVm, Local<JSValueRef> tagged, const std::string &classname);
388     ObjectRemoteObject(const EcmaVM *ecmaVm, Local<JSValueRef> tagged, const std::string &classname,
389         const std::string &subtype);
390     ~ObjectRemoteObject() override = default;
391     static std::string DescriptionForObject(const EcmaVM *ecmaVm, Local<JSValueRef> tagged);
392 
393 private:
394     enum NumberSize : uint8_t { BYTES_OF_16BITS = 2, BYTES_OF_32BITS = 4, BYTES_OF_64BITS = 8 };
395     static std::string DescriptionForArray(const EcmaVM *ecmaVm, Local<ArrayRef> tagged);
396     static std::string DescriptionForRegexp(const EcmaVM *ecmaVm, Local<RegExpRef> tagged);
397     static std::string DescriptionForDate(const EcmaVM *ecmaVm, Local<DateRef> tagged);
398     static std::string DescriptionForMap(const EcmaVM *ecmaVm, Local<MapRef> tagged);
399     static std::string DescriptionForSet(const EcmaVM *ecmaVm, Local<SetRef> tagged);
400     static std::string DescriptionForError(const EcmaVM *ecmaVm, Local<JSValueRef> tagged);
401     static std::string DescriptionForArrayIterator();
402     static std::string DescriptionForMapIterator();
403     static std::string DescriptionForSetIterator();
404     static std::string DescriptionForArrayBuffer(const EcmaVM *ecmaVm, Local<ArrayBufferRef> tagged);
405     static std::string DescriptionForSharedArrayBuffer(const EcmaVM *ecmaVm, Local<ArrayBufferRef> tagged);
406     static std::string DescriptionForUint8Array(const EcmaVM *ecmaVm, Local<TypedArrayRef> tagged);
407     static std::string DescriptionForInt8Array(const EcmaVM *ecmaVm, Local<TypedArrayRef> tagged);
408     static std::string DescriptionForInt16Array(const EcmaVM *ecmaVm, Local<TypedArrayRef> tagged);
409     static std::string DescriptionForInt32Array(const EcmaVM *ecmaVm, Local<TypedArrayRef> tagged);
410     static std::string DescriptionForPrimitiveNumber(const EcmaVM *ecmaVm, const Local<JSValueRef> &tagged);
411     static std::string DescriptionForPrimitiveString(const EcmaVM *ecmaVm, const Local<JSValueRef> &tagged);
412     static std::string DescriptionForPrimitiveBoolean(const EcmaVM *ecmaVm, const Local<JSValueRef> &tagged);
413     static std::string DescriptionForGeneratorObject(const EcmaVM *ecmaVm, const Local<JSValueRef> &tagged);
414     static std::string DescriptionForWeakRef();
415     static std::string DescriptionForDateTimeFormat();
416     static std::string DescriptionForNumberFormat();
417     static std::string DescriptionForCollator();
418     static std::string DescriptionForPluralRules();
419     static std::string DescriptionForJSLocale();
420     static std::string DescriptionForJSRelativeTimeFormat();
421     static std::string DescriptionForJSListFormat();
422 };
423 
424 // Runtime.ExceptionDetails
425 class ExceptionDetails final : public PtBaseTypes {
426 public:
427     ExceptionDetails() = default;
428     ~ExceptionDetails() override = default;
429     static std::unique_ptr<ExceptionDetails> Create(const PtJson &params);
430     std::unique_ptr<PtJson> ToJson() const override;
431 
GetExceptionId()432     int32_t GetExceptionId() const
433     {
434         return exceptionId_;
435     }
436 
SetExceptionId(int32_t exceptionId)437     ExceptionDetails &SetExceptionId(int32_t exceptionId)
438     {
439         exceptionId_ = exceptionId;
440         return *this;
441     }
442 
GetText()443     const std::string &GetText() const
444     {
445         return text_;
446     }
447 
SetText(const std::string & text)448     ExceptionDetails &SetText(const std::string &text)
449     {
450         text_ = text;
451         return *this;
452     }
453 
GetLine()454     int32_t GetLine() const
455     {
456         return lineNumber_;
457     }
458 
SetLine(int32_t lineNumber)459     ExceptionDetails &SetLine(int32_t lineNumber)
460     {
461         lineNumber_ = lineNumber;
462         return *this;
463     }
464 
GetColumn()465     int32_t GetColumn() const
466     {
467         return columnNumber_;
468     }
469 
SetColumn(int32_t columnNumber)470     ExceptionDetails &SetColumn(int32_t columnNumber)
471     {
472         columnNumber_ = columnNumber;
473         return *this;
474     }
475 
GetScriptId()476     ScriptId GetScriptId() const
477     {
478         return scriptId_.value_or(0);
479     }
480 
SetScriptId(ScriptId scriptId)481     ExceptionDetails &SetScriptId(ScriptId scriptId)
482     {
483         scriptId_ = scriptId;
484         return *this;
485     }
486 
HasScriptId()487     bool HasScriptId() const
488     {
489         return scriptId_.has_value();
490     }
491 
GetUrl()492     const std::string &GetUrl() const
493     {
494         ASSERT(HasUrl());
495         return url_.value();
496     }
497 
SetUrl(const std::string & url)498     ExceptionDetails &SetUrl(const std::string &url)
499     {
500         url_ = url;
501         return *this;
502     }
503 
HasUrl()504     bool HasUrl() const
505     {
506         return url_.has_value();
507     }
508 
GetException()509     RemoteObject *GetException() const
510     {
511         if (exception_) {
512             return exception_->get();
513         }
514         return nullptr;
515     }
516 
SetException(std::unique_ptr<RemoteObject> exception)517     ExceptionDetails &SetException(std::unique_ptr<RemoteObject> exception)
518     {
519         exception_ = std::move(exception);
520         return *this;
521     }
522 
HasException()523     bool HasException() const
524     {
525         return exception_.has_value();
526     }
527 
GetExecutionContextId()528     ExecutionContextId GetExecutionContextId() const
529     {
530         return executionContextId_.value_or(-1);
531     }
532 
SetExecutionContextId(ExecutionContextId executionContextId)533     ExceptionDetails &SetExecutionContextId(ExecutionContextId executionContextId)
534     {
535         executionContextId_ = executionContextId;
536         return *this;
537     }
538 
HasExecutionContextId()539     bool HasExecutionContextId() const
540     {
541         return executionContextId_.has_value();
542     }
543 
544 private:
545     NO_COPY_SEMANTIC(ExceptionDetails);
546     NO_MOVE_SEMANTIC(ExceptionDetails);
547 
548     int32_t exceptionId_ {0};
549     std::string text_ {};
550     int32_t lineNumber_ {0};
551     int32_t columnNumber_ {0};
552     std::optional<ScriptId> scriptId_ {};
553     std::optional<std::string> url_ {};
554     std::optional<std::unique_ptr<RemoteObject>> exception_ {};
555     std::optional<ExecutionContextId> executionContextId_ {0};
556 };
557 
558 // Runtime.InternalPropertyDescriptor
559 class InternalPropertyDescriptor final : public PtBaseTypes {
560 public:
561     InternalPropertyDescriptor() = default;
562     ~InternalPropertyDescriptor() override = default;
563 
564     static std::unique_ptr<InternalPropertyDescriptor> Create(const PtJson &params);
565     std::unique_ptr<PtJson> ToJson() const override;
566 
GetName()567     std::string GetName() const
568     {
569         return name_;
570     }
571 
SetName(const std::string & name)572     InternalPropertyDescriptor &SetName(const std::string &name)
573     {
574         name_ = name;
575         return *this;
576     }
577 
GetValue()578     RemoteObject *GetValue() const
579     {
580         if (value_) {
581             return value_->get();
582         }
583         return nullptr;
584     }
585 
SetValue(std::unique_ptr<RemoteObject> value)586     InternalPropertyDescriptor &SetValue(std::unique_ptr<RemoteObject> value)
587     {
588         value_ = std::move(value);
589         return *this;
590     }
591 
HasValue()592     bool HasValue() const
593     {
594         return value_.has_value();
595     }
596 
597 private:
598     NO_COPY_SEMANTIC(InternalPropertyDescriptor);
599     NO_MOVE_SEMANTIC(InternalPropertyDescriptor);
600 
601     std::string name_ {};
602     std::optional<std::unique_ptr<RemoteObject>> value_ {};
603 };
604 
605 // Runtime.PrivatePropertyDescriptor
606 class PrivatePropertyDescriptor final : public PtBaseTypes {
607 public:
608     PrivatePropertyDescriptor() = default;
609     ~PrivatePropertyDescriptor() override = default;
610 
611     static std::unique_ptr<PrivatePropertyDescriptor> Create(const PtJson &params);
612     std::unique_ptr<PtJson> ToJson() const override;
613 
GetName()614     std::string GetName() const
615     {
616         return name_;
617     }
618 
SetName(const std::string & name)619     PrivatePropertyDescriptor &SetName(const std::string &name)
620     {
621         name_ = name;
622         return *this;
623     }
624 
GetValue()625     RemoteObject *GetValue() const
626     {
627         if (value_) {
628             return value_->get();
629         }
630         return nullptr;
631     }
632 
SetValue(std::unique_ptr<RemoteObject> value)633     PrivatePropertyDescriptor &SetValue(std::unique_ptr<RemoteObject> value)
634     {
635         value_ = std::move(value);
636         return *this;
637     }
638 
HasValue()639     bool HasValue() const
640     {
641         return value_.has_value();
642     }
643 
GetGet()644     RemoteObject *GetGet() const
645     {
646         if (get_) {
647             return get_->get();
648         }
649         return nullptr;
650     }
651 
SetGet(std::unique_ptr<RemoteObject> get)652     PrivatePropertyDescriptor &SetGet(std::unique_ptr<RemoteObject> get)
653     {
654         get_ = std::move(get);
655         return *this;
656     }
657 
HasGet()658     bool HasGet() const
659     {
660         return get_.has_value();
661     }
662 
GetSet()663     RemoteObject *GetSet() const
664     {
665         if (set_) {
666             return set_->get();
667         }
668         return nullptr;
669     }
670 
SetSet(std::unique_ptr<RemoteObject> set)671     PrivatePropertyDescriptor &SetSet(std::unique_ptr<RemoteObject> set)
672     {
673         set_ = std::move(set);
674         return *this;
675     }
676 
HasSet()677     bool HasSet() const
678     {
679         return set_.has_value();
680     }
681 
682 private:
683     NO_COPY_SEMANTIC(PrivatePropertyDescriptor);
684     NO_MOVE_SEMANTIC(PrivatePropertyDescriptor);
685 
686     std::string name_ {};
687     std::optional<std::unique_ptr<RemoteObject>> value_ {};
688     std::optional<std::unique_ptr<RemoteObject>> get_ {};
689     std::optional<std::unique_ptr<RemoteObject>> set_ {};
690 };
691 
692 // Runtime.PropertyDescriptor
693 class PropertyDescriptor final : public PtBaseTypes {
694 public:
695     PropertyDescriptor() = default;
696     ~PropertyDescriptor() override = default;
697 
698     static std::unique_ptr<PropertyDescriptor> FromProperty(const EcmaVM *ecmaVm, Local<JSValueRef> name,
699         const PropertyAttribute &property);
700     static std::unique_ptr<PropertyDescriptor> Create(const PtJson &params);
701     std::unique_ptr<PtJson> ToJson() const override;
702 
GetName()703     std::string GetName() const
704     {
705         return name_;
706     }
707 
SetName(const std::string & name)708     PropertyDescriptor &SetName(const std::string &name)
709     {
710         name_ = name;
711         return *this;
712     }
713 
GetValue()714     RemoteObject *GetValue() const
715     {
716         if (value_) {
717             return value_->get();
718         }
719         return nullptr;
720     }
721 
SetValue(std::unique_ptr<RemoteObject> value)722     PropertyDescriptor &SetValue(std::unique_ptr<RemoteObject> value)
723     {
724         value_ = std::move(value);
725         return *this;
726     }
727 
HasValue()728     bool HasValue() const
729     {
730         return value_.has_value();
731     }
732 
GetWritable()733     bool GetWritable() const
734     {
735         return writable_.value_or(false);
736     }
737 
SetWritable(bool writable)738     PropertyDescriptor &SetWritable(bool writable)
739     {
740         writable_ = writable;
741         return *this;
742     }
743 
HasWritable()744     bool HasWritable() const
745     {
746         return writable_.has_value();
747     }
748 
GetGet()749     RemoteObject *GetGet() const
750     {
751         if (get_) {
752             return get_->get();
753         }
754         return nullptr;
755     }
756 
SetGet(std::unique_ptr<RemoteObject> get)757     PropertyDescriptor &SetGet(std::unique_ptr<RemoteObject> get)
758     {
759         get_ = std::move(get);
760         return *this;
761     }
762 
HasGet()763     bool HasGet() const
764     {
765         return get_.has_value();
766     }
767 
GetSet()768     RemoteObject *GetSet() const
769     {
770         if (set_) {
771             return set_->get();
772         }
773         return nullptr;
774     }
775 
SetSet(std::unique_ptr<RemoteObject> set)776     PropertyDescriptor &SetSet(std::unique_ptr<RemoteObject> set)
777     {
778         set_ = std::move(set);
779         return *this;
780     }
781 
HasSet()782     bool HasSet() const
783     {
784         return set_.has_value();
785     }
786 
GetConfigurable()787     bool GetConfigurable() const
788     {
789         return configurable_;
790     }
791 
SetConfigurable(bool configurable)792     PropertyDescriptor &SetConfigurable(bool configurable)
793     {
794         configurable_ = configurable;
795         return *this;
796     }
797 
GetEnumerable()798     bool GetEnumerable() const
799     {
800         return enumerable_;
801     }
802 
SetEnumerable(bool enumerable)803     PropertyDescriptor &SetEnumerable(bool enumerable)
804     {
805         enumerable_ = enumerable;
806         return *this;
807     }
808 
GetWasThrown()809     bool GetWasThrown() const
810     {
811         return wasThrown_.value_or(false);
812     }
813 
SetWasThrown(bool wasThrown)814     PropertyDescriptor &SetWasThrown(bool wasThrown)
815     {
816         wasThrown_ = wasThrown;
817         return *this;
818     }
819 
HasWasThrown()820     bool HasWasThrown() const
821     {
822         return wasThrown_.has_value();
823     }
824 
GetIsOwn()825     bool GetIsOwn() const
826     {
827         return isOwn_.value_or(false);
828     }
829 
SetIsOwn(bool isOwn)830     PropertyDescriptor &SetIsOwn(bool isOwn)
831     {
832         isOwn_ = isOwn;
833         return *this;
834     }
835 
HasIsOwn()836     bool HasIsOwn() const
837     {
838         return isOwn_.has_value();
839     }
840 
GetSymbol()841     RemoteObject *GetSymbol() const
842     {
843         if (symbol_) {
844             return symbol_->get();
845         }
846         return nullptr;
847     }
848 
SetSymbol(std::unique_ptr<RemoteObject> symbol)849     PropertyDescriptor &SetSymbol(std::unique_ptr<RemoteObject> symbol)
850     {
851         symbol_ = std::move(symbol);
852         return *this;
853     }
854 
HasSymbol()855     bool HasSymbol() const
856     {
857         return symbol_.has_value();
858     }
859 
860 private:
861     NO_COPY_SEMANTIC(PropertyDescriptor);
862     NO_MOVE_SEMANTIC(PropertyDescriptor);
863 
864     std::string name_ {};
865     std::optional<std::unique_ptr<RemoteObject>> value_ {};
866     std::optional<bool> writable_ {};
867     std::optional<std::unique_ptr<RemoteObject>> get_ {};
868     std::optional<std::unique_ptr<RemoteObject>> set_ {};
869     bool configurable_ {false};
870     bool enumerable_ {false};
871     std::optional<bool> wasThrown_ {};
872     std::optional<bool> isOwn_ {};
873     std::optional<std::unique_ptr<RemoteObject>> symbol_ {};
874 };
875 
876 // Runtime.CallArgument
877 class CallArgument final : public PtBaseTypes {
878 public:
879     CallArgument() = default;
880     ~CallArgument() override = default;
881 
882     static std::unique_ptr<CallArgument> Create(const PtJson &params);
883     std::unique_ptr<PtJson> ToJson() const override;
884 
GetValue()885     Local<JSValueRef> GetValue() const
886     {
887         return value_.value_or(Local<JSValueRef>());
888     }
889 
SetValue(Local<JSValueRef> value)890     CallArgument &SetValue(Local<JSValueRef> value)
891     {
892         value_ = value;
893         return *this;
894     }
895 
HasValue()896     bool HasValue() const
897     {
898         return value_.has_value();
899     }
900 
GetUnserializableValue()901     const UnserializableValue &GetUnserializableValue() const
902     {
903         ASSERT(HasUnserializableValue());
904         return unserializableValue_.value();
905     }
906 
SetUnserializableValue(const UnserializableValue & unserializableValue)907     CallArgument &SetUnserializableValue(const UnserializableValue &unserializableValue)
908     {
909         unserializableValue_ = unserializableValue;
910         return *this;
911     }
912 
HasUnserializableValue()913     bool HasUnserializableValue() const
914     {
915         return unserializableValue_.has_value();
916     }
917 
GetObjectId()918     RemoteObjectId GetObjectId() const
919     {
920         return objectId_.value_or(0);
921     }
922 
SetObjectId(RemoteObjectId objectId)923     CallArgument &SetObjectId(RemoteObjectId objectId)
924     {
925         objectId_ = objectId;
926         return *this;
927     }
928 
HasObjectId()929     bool HasObjectId() const
930     {
931         return objectId_.has_value();
932     }
933 
934 private:
935     NO_COPY_SEMANTIC(CallArgument);
936     NO_MOVE_SEMANTIC(CallArgument);
937 
938     std::optional<Local<JSValueRef>> value_ {};
939     std::optional<UnserializableValue> unserializableValue_ {};
940     std::optional<RemoteObjectId> objectId_ {};
941 };
942 
943 // ========== Debugger types begin
944 // Debugger.ScriptLanguage
945 struct ScriptLanguage {
ValidScriptLanguage946     static bool Valid(const std::string &language)
947     {
948         return language == JavaScript() || language == WebAssembly();
949     }
JavaScriptScriptLanguage950     static std::string JavaScript()
951     {
952         return "JavaScript";
953     }
WebAssemblyScriptLanguage954     static std::string WebAssembly()
955     {
956         return "WebAssembly";
957     }
958 };
959 
960 // Debugger.Location
961 class Location : public PtBaseTypes {
962 public:
963     Location() = default;
964     ~Location() override = default;
965 
966     static std::unique_ptr<Location> Create(const PtJson &params);
967     std::unique_ptr<PtJson> ToJson() const override;
968 
GetScriptId()969     ScriptId GetScriptId() const
970     {
971         return scriptId_;
972     }
973 
SetScriptId(ScriptId scriptId)974     Location &SetScriptId(ScriptId scriptId)
975     {
976         scriptId_ = scriptId;
977         return *this;
978     }
979 
GetLine()980     int32_t GetLine() const
981     {
982         return lineNumber_;
983     }
984 
SetLine(int32_t line)985     Location &SetLine(int32_t line)
986     {
987         lineNumber_ = line;
988         return *this;
989     }
990 
GetColumn()991     int32_t GetColumn() const
992     {
993         return columnNumber_.value_or(-1);
994     }
995 
SetColumn(int32_t column)996     Location &SetColumn(int32_t column)
997     {
998         columnNumber_ = column;
999         return *this;
1000     }
1001 
HasColumn()1002     bool HasColumn() const
1003     {
1004         return columnNumber_.has_value();
1005     }
1006 
1007 private:
1008     NO_COPY_SEMANTIC(Location);
1009     NO_MOVE_SEMANTIC(Location);
1010 
1011     ScriptId scriptId_ {0};
1012     int32_t lineNumber_ {0};
1013     std::optional<int32_t> columnNumber_ {};
1014 };
1015 
1016 // Debugger.ScriptPosition
1017 class ScriptPosition : public PtBaseTypes {
1018 public:
1019     ScriptPosition() = default;
1020     ~ScriptPosition() override = default;
1021 
1022     static std::unique_ptr<ScriptPosition> Create(const PtJson &params);
1023     std::unique_ptr<PtJson> ToJson() const override;
1024 
GetLine()1025     int32_t GetLine() const
1026     {
1027         return lineNumber_;
1028     }
1029 
SetLine(int32_t line)1030     ScriptPosition &SetLine(int32_t line)
1031     {
1032         lineNumber_ = line;
1033         return *this;
1034     }
1035 
GetColumn()1036     int32_t GetColumn() const
1037     {
1038         return columnNumber_;
1039     }
1040 
SetColumn(int32_t column)1041     ScriptPosition &SetColumn(int32_t column)
1042     {
1043         columnNumber_ = column;
1044         return *this;
1045     }
1046 
1047 private:
1048     NO_COPY_SEMANTIC(ScriptPosition);
1049     NO_MOVE_SEMANTIC(ScriptPosition);
1050 
1051     int32_t lineNumber_ {0};
1052     int32_t columnNumber_ {0};
1053 };
1054 
1055 // Debugger.SearchMatch
1056 class SearchMatch : public PtBaseTypes {
1057 public:
1058     SearchMatch() = default;
1059     ~SearchMatch() override = default;
1060     static std::unique_ptr<SearchMatch> Create(const PtJson &params);
1061     std::unique_ptr<PtJson> ToJson() const override;
1062 
1063 private:
1064     NO_COPY_SEMANTIC(SearchMatch);
1065     NO_MOVE_SEMANTIC(SearchMatch);
1066 
1067     int32_t lineNumber_ {0};
1068     std::string lineContent_ {};
1069 };
1070 
1071 // Debugger.LocationRange
1072 class LocationRange : public PtBaseTypes {
1073 public:
1074     LocationRange() = default;
1075     ~LocationRange() override = default;
1076 
1077     static std::unique_ptr<LocationRange> Create(const PtJson &params);
1078     std::unique_ptr<PtJson> ToJson() const override;
1079 
GetScriptId()1080     ScriptId GetScriptId() const
1081     {
1082         return scriptId_;
1083     }
1084 
SetScriptId(ScriptId scriptId)1085     LocationRange &SetScriptId(ScriptId scriptId)
1086     {
1087         scriptId_ = scriptId;
1088         return *this;
1089     }
1090 
GetStart()1091     ScriptPosition *GetStart() const
1092     {
1093         return start_.get();
1094     }
1095 
SetStart(std::unique_ptr<ScriptPosition> start)1096     LocationRange &SetStart(std::unique_ptr<ScriptPosition> start)
1097     {
1098         start_ = std::move(start);
1099         return *this;
1100     }
1101 
GetEnd()1102     ScriptPosition *GetEnd() const
1103     {
1104         return end_.get();
1105     }
1106 
SetEnd(std::unique_ptr<ScriptPosition> end)1107     LocationRange &SetEnd(std::unique_ptr<ScriptPosition> end)
1108     {
1109         end_ = std::move(end);
1110         return *this;
1111     }
1112 
1113 private:
1114     NO_COPY_SEMANTIC(LocationRange);
1115     NO_MOVE_SEMANTIC(LocationRange);
1116 
1117     ScriptId scriptId_ {0};
1118     std::unique_ptr<ScriptPosition> start_ {nullptr};
1119     std::unique_ptr<ScriptPosition> end_ {nullptr};
1120 };
1121 
1122 // Debugger.BreakLocation
1123 class BreakLocation final : public PtBaseTypes {
1124 public:
1125     BreakLocation() = default;
1126     ~BreakLocation() override = default;
1127 
1128     static std::unique_ptr<BreakLocation> Create(const PtJson &params);
1129     std::unique_ptr<PtJson> ToJson() const override;
1130 
GetScriptId()1131     ScriptId GetScriptId() const
1132     {
1133         return scriptId_;
1134     }
1135 
SetScriptId(ScriptId scriptId)1136     BreakLocation &SetScriptId(ScriptId scriptId)
1137     {
1138         scriptId_ = scriptId;
1139         return *this;
1140     }
1141 
GetLine()1142     int32_t GetLine() const
1143     {
1144         return lineNumber_;
1145     }
1146 
SetLine(int32_t lineNumber)1147     BreakLocation &SetLine(int32_t lineNumber)
1148     {
1149         lineNumber_ = lineNumber;
1150         return *this;
1151     }
1152 
GetColumn()1153     int32_t GetColumn() const
1154     {
1155         return columnNumber_.value_or(-1);
1156     }
1157 
SetColumn(int32_t columnNumber)1158     BreakLocation &SetColumn(int32_t columnNumber)
1159     {
1160         columnNumber_ = columnNumber;
1161         return *this;
1162     }
1163 
HasColumn()1164     bool HasColumn() const
1165     {
1166         return columnNumber_.has_value();
1167     }
1168 
1169     /*
1170      * @see {#BreakType}
1171      */
GetType()1172     const std::string &GetType() const
1173     {
1174         ASSERT(HasType());
1175         return type_.value();
1176     }
1177 
SetType(const std::string & type)1178     BreakLocation &SetType(const std::string &type)
1179     {
1180         type_ = type;
1181         return *this;
1182     }
1183 
HasType()1184     bool HasType() const
1185     {
1186         return type_.has_value();
1187     }
1188 
1189     struct Type {
ValidType1190         static bool Valid(const std::string &type)
1191         {
1192             return type == DebuggerStatement() || type == Call() || type == Return();
1193         }
DebuggerStatementType1194         static std::string DebuggerStatement()
1195         {
1196             return "debuggerStatement";
1197         }
CallType1198         static std::string Call()
1199         {
1200             return "call";
1201         }
ReturnType1202         static std::string Return()
1203         {
1204             return "return";
1205         }
1206     };
1207 
1208 private:
1209     NO_COPY_SEMANTIC(BreakLocation);
1210     NO_MOVE_SEMANTIC(BreakLocation);
1211 
1212     ScriptId scriptId_ {0};
1213     int32_t lineNumber_ {0};
1214     std::optional<int32_t> columnNumber_ {};
1215     std::optional<std::string> type_ {};
1216 };
1217 using BreakType = BreakLocation::Type;
1218 
1219 enum class ScopeType : uint8_t {
1220     GLOBAL,
1221     LOCAL,
1222     WITH,
1223     CLOSURE,
1224     CATCH,
1225     BLOCK,
1226     SCRIPT,
1227     EVAL,
1228     MODULE,
1229     WASM_EXPRESSION_STACK
1230 };
1231 
1232 // Debugger.Scope
1233 class Scope final : public PtBaseTypes {
1234 public:
1235     Scope() = default;
1236     ~Scope() override = default;
1237 
1238     static std::unique_ptr<Scope> Create(const PtJson &params);
1239     std::unique_ptr<PtJson> ToJson() const override;
1240 
1241     /*
1242      * @see {#Scope::Type}
1243      */
GetType()1244     const std::string &GetType() const
1245     {
1246         return type_;
1247     }
1248 
SetType(const std::string & type)1249     Scope &SetType(const std::string &type)
1250     {
1251         type_ = type;
1252         return *this;
1253     }
1254 
GetObject()1255     RemoteObject *GetObject() const
1256     {
1257         return object_.get();
1258     }
1259 
SetObject(std::unique_ptr<RemoteObject> params)1260     Scope &SetObject(std::unique_ptr<RemoteObject> params)
1261     {
1262         object_ = std::move(params);
1263         return *this;
1264     }
1265 
GetName()1266     const std::string &GetName() const
1267     {
1268         ASSERT(HasName());
1269         return name_.value();
1270     }
1271 
SetName(const std::string & name)1272     Scope &SetName(const std::string &name)
1273     {
1274         name_ = name;
1275         return *this;
1276     }
1277 
HasName()1278     bool HasName() const
1279     {
1280         return name_.has_value();
1281     }
1282 
GetStartLocation()1283     Location *GetStartLocation() const
1284     {
1285         if (startLocation_) {
1286             return startLocation_->get();
1287         }
1288         return nullptr;
1289     }
1290 
SetStartLocation(std::unique_ptr<Location> location)1291     Scope &SetStartLocation(std::unique_ptr<Location> location)
1292     {
1293         startLocation_ = std::move(location);
1294         return *this;
1295     }
1296 
HasStartLocation()1297     bool HasStartLocation() const
1298     {
1299         return startLocation_.has_value();
1300     }
1301 
GetEndLocation()1302     Location *GetEndLocation() const
1303     {
1304         if (endLocation_) {
1305             return endLocation_->get();
1306         }
1307         return nullptr;
1308     }
1309 
SetEndLocation(std::unique_ptr<Location> location)1310     Scope &SetEndLocation(std::unique_ptr<Location> location)
1311     {
1312         endLocation_ = std::move(location);
1313         return *this;
1314     }
1315 
HasEndLocation()1316     bool HasEndLocation() const
1317     {
1318         return endLocation_.has_value();
1319     }
1320 
1321     struct Type {
ValidType1322         static bool Valid(const std::string &type)
1323         {
1324             return type == Global() || type == Local() || type == With() || type == Closure() || type == Catch() ||
1325                    type == Block() || type == Script() || type == Eval() || type == Module() ||
1326                    type == WasmExpressionStack();
1327         }
GlobalType1328         static std::string Global()
1329         {
1330             return "global";
1331         }
LocalType1332         static std::string Local()
1333         {
1334             return "local";
1335         }
WithType1336         static std::string With()
1337         {
1338             return "with";
1339         }
ClosureType1340         static std::string Closure()
1341         {
1342             return "closure";
1343         }
CatchType1344         static std::string Catch()
1345         {
1346             return "catch";
1347         }
BlockType1348         static std::string Block()
1349         {
1350             return "block";
1351         }
ScriptType1352         static std::string Script()
1353         {
1354             return "script";
1355         }
EvalType1356         static std::string Eval()
1357         {
1358             return "eval";
1359         }
ModuleType1360         static std::string Module()
1361         {
1362             return "module";
1363         }
WasmExpressionStackType1364         static std::string WasmExpressionStack()
1365         {
1366             return "wasm-expression-stack";
1367         }
1368     };
1369 
1370 private:
1371     NO_COPY_SEMANTIC(Scope);
1372     NO_MOVE_SEMANTIC(Scope);
1373 
1374     std::string type_ {};
1375     std::unique_ptr<RemoteObject> object_ {nullptr};
1376     std::optional<std::string> name_ {};
1377     std::optional<std::unique_ptr<Location>> startLocation_ {};
1378     std::optional<std::unique_ptr<Location>> endLocation_ {};
1379 };
1380 
1381 // Debugger.CallFrame
1382 class CallFrame final : public PtBaseTypes {
1383 public:
1384     CallFrame() = default;
1385     ~CallFrame() override = default;
1386 
1387     static std::unique_ptr<CallFrame> Create(const PtJson &params);
1388     std::unique_ptr<PtJson> ToJson() const override;
1389 
GetCallFrameId()1390     CallFrameId GetCallFrameId() const
1391     {
1392         return callFrameId_;
1393     }
1394 
SetCallFrameId(CallFrameId callFrameId)1395     CallFrame &SetCallFrameId(CallFrameId callFrameId)
1396     {
1397         callFrameId_ = callFrameId;
1398         return *this;
1399     }
1400 
GetFunctionName()1401     const std::string &GetFunctionName() const
1402     {
1403         return functionName_;
1404     }
1405 
SetFunctionName(const std::string & functionName)1406     CallFrame &SetFunctionName(const std::string &functionName)
1407     {
1408         functionName_ = functionName;
1409         return *this;
1410     }
1411 
GetFunctionLocation()1412     Location *GetFunctionLocation() const
1413     {
1414         if (functionLocation_) {
1415             return functionLocation_->get();
1416         }
1417         return nullptr;
1418     }
1419 
SetFunctionLocation(std::unique_ptr<Location> location)1420     CallFrame &SetFunctionLocation(std::unique_ptr<Location> location)
1421     {
1422         functionLocation_ = std::move(location);
1423         return *this;
1424     }
1425 
HasFunctionLocation()1426     bool HasFunctionLocation() const
1427     {
1428         return functionLocation_.has_value();
1429     }
1430 
GetLocation()1431     Location *GetLocation() const
1432     {
1433         return location_.get();
1434     }
1435 
SetLocation(std::unique_ptr<Location> location)1436     CallFrame &SetLocation(std::unique_ptr<Location> location)
1437     {
1438         location_ = std::move(location);
1439         return *this;
1440     }
1441 
GetUrl()1442     const std::string &GetUrl() const
1443     {
1444         return url_;
1445     }
1446 
SetUrl(const std::string & url)1447     CallFrame &SetUrl(const std::string &url)
1448     {
1449         url_ = url;
1450         return *this;
1451     }
1452 
GetScopeChain()1453     const std::vector<std::unique_ptr<Scope>> *GetScopeChain() const
1454     {
1455         return &scopeChain_;
1456     }
1457 
SetScopeChain(std::vector<std::unique_ptr<Scope>> scopeChain)1458     CallFrame &SetScopeChain(std::vector<std::unique_ptr<Scope>> scopeChain)
1459     {
1460         scopeChain_ = std::move(scopeChain);
1461         return *this;
1462     }
GetThis()1463     RemoteObject *GetThis() const
1464     {
1465         return this_.get();
1466     }
1467 
SetThis(std::unique_ptr<RemoteObject> thisObj)1468     CallFrame &SetThis(std::unique_ptr<RemoteObject> thisObj)
1469     {
1470         this_ = std::move(thisObj);
1471         return *this;
1472     }
1473 
GetReturnValue()1474     RemoteObject *GetReturnValue() const
1475     {
1476         if (returnValue_) {
1477             return returnValue_->get();
1478         }
1479         return nullptr;
1480     }
1481 
SetReturnValue(std::unique_ptr<RemoteObject> returnValue)1482     CallFrame &SetReturnValue(std::unique_ptr<RemoteObject> returnValue)
1483     {
1484         returnValue_ = std::move(returnValue);
1485         return *this;
1486     }
1487 
HasReturnValue()1488     bool HasReturnValue() const
1489     {
1490         return returnValue_.has_value();
1491     }
1492 
1493 private:
1494     NO_COPY_SEMANTIC(CallFrame);
1495     NO_MOVE_SEMANTIC(CallFrame);
1496 
1497     CallFrameId callFrameId_ {};
1498     std::string functionName_ {};
1499     std::optional<std::unique_ptr<Location>> functionLocation_ {};
1500     std::unique_ptr<Location> location_ {nullptr};
1501     std::string url_ {};
1502     std::vector<std::unique_ptr<Scope>> scopeChain_ {};
1503     std::unique_ptr<RemoteObject> this_ {nullptr};
1504     std::optional<std::unique_ptr<RemoteObject>> returnValue_ {};
1505 };
1506 
1507 // ========== Heapprofiler types begin
1508 
1509 using HeapSnapshotObjectId = int32_t;
1510 
1511 class SamplingHeapProfileSample  final :  public PtBaseTypes {
1512 public:
1513     SamplingHeapProfileSample() = default;
1514     ~SamplingHeapProfileSample() override = default;
1515     static std::unique_ptr<SamplingHeapProfileSample> Create(const PtJson &params);
1516     std::unique_ptr<PtJson> ToJson() const override;
1517 
SetSize(int32_t size)1518     SamplingHeapProfileSample &SetSize(int32_t size)
1519     {
1520         size_ = size;
1521         return *this;
1522     }
1523 
GetSize()1524     int32_t GetSize() const
1525     {
1526         return size_;
1527     }
1528 
SetNodeId(int32_t nodeId)1529     SamplingHeapProfileSample &SetNodeId(int32_t nodeId)
1530     {
1531         nodeId_ = nodeId;
1532         return *this;
1533     }
1534 
GetNodeId()1535     int32_t GetNodeId() const
1536     {
1537         return nodeId_;
1538     }
1539 
SetOrdinal(int32_t ordinal)1540     SamplingHeapProfileSample &SetOrdinal(int32_t ordinal)
1541     {
1542         ordinal_ = ordinal;
1543         return *this;
1544     }
1545 
GetOrdinal()1546     int32_t GetOrdinal() const
1547     {
1548         return ordinal_;
1549     }
1550 
1551 private:
1552     NO_COPY_SEMANTIC(SamplingHeapProfileSample);
1553     NO_MOVE_SEMANTIC(SamplingHeapProfileSample);
1554 
1555     int32_t size_ {0};
1556     int32_t nodeId_ {0};
1557     int32_t ordinal_ {0};
1558 };
1559 
1560 class RuntimeCallFrame  final :  public PtBaseTypes {
1561 public:
1562     RuntimeCallFrame() = default;
1563     ~RuntimeCallFrame() override = default;
1564     static std::unique_ptr<RuntimeCallFrame> Create(const PtJson &params);
1565     static std::unique_ptr<RuntimeCallFrame> FromFrameInfo(const FrameInfo &cpuFrameInfo);
1566     std::unique_ptr<PtJson> ToJson() const override;
1567 
SetFunctionName(const std::string & functionName)1568     RuntimeCallFrame &SetFunctionName(const std::string &functionName)
1569     {
1570         functionName_ = functionName;
1571         return *this;
1572     }
1573 
GetFunctionName()1574     const std::string &GetFunctionName() const
1575     {
1576         return functionName_;
1577     }
1578 
SetScriptId(const std::string & scriptId)1579     RuntimeCallFrame &SetScriptId(const std::string &scriptId)
1580     {
1581         scriptId_ = scriptId;
1582         return *this;
1583     }
1584 
GetScriptId()1585     const std::string &GetScriptId() const
1586     {
1587         return scriptId_;
1588     }
1589 
SetUrl(const std::string & url)1590     RuntimeCallFrame &SetUrl(const std::string &url)
1591     {
1592         url_ = url;
1593         return *this;
1594     }
1595 
GetUrl()1596     const std::string &GetUrl() const
1597     {
1598         return url_;
1599     }
1600 
SetLineNumber(int32_t lineNumber)1601     RuntimeCallFrame &SetLineNumber(int32_t lineNumber)
1602     {
1603         lineNumber_ = lineNumber;
1604         return *this;
1605     }
1606 
GetLineNumber()1607     int32_t GetLineNumber() const
1608     {
1609         return lineNumber_;
1610     }
1611 
SetColumnNumber(int32_t columnNumber)1612     RuntimeCallFrame &SetColumnNumber(int32_t columnNumber)
1613     {
1614         columnNumber_ = columnNumber;
1615         return *this;
1616     }
1617 
GetColumnNumber()1618     int32_t GetColumnNumber() const
1619     {
1620         return columnNumber_;
1621     }
1622 
1623 private:
1624     NO_COPY_SEMANTIC(RuntimeCallFrame);
1625     NO_MOVE_SEMANTIC(RuntimeCallFrame);
1626 
1627     std::string functionName_ {};
1628     std::string scriptId_ {};
1629     std::string url_ {};
1630     int32_t lineNumber_ {0};
1631     int32_t columnNumber_ {0};
1632 };
1633 
1634 class SamplingHeapProfileNode  final :  public PtBaseTypes {
1635 public:
1636     SamplingHeapProfileNode() = default;
1637     ~SamplingHeapProfileNode() override = default;
1638     static std::unique_ptr<SamplingHeapProfileNode> Create(const PtJson &params);
1639     std::unique_ptr<PtJson> ToJson() const override;
1640 
SetCallFrame(std::unique_ptr<RuntimeCallFrame> callFrame)1641     SamplingHeapProfileNode &SetCallFrame(std::unique_ptr<RuntimeCallFrame> callFrame)
1642     {
1643         callFrame_ = std::move(callFrame);
1644         return *this;
1645     }
1646 
GetCallFrame()1647     RuntimeCallFrame *GetCallFrame() const
1648     {
1649         return callFrame_.get();
1650     }
1651 
SetSelfSize(int32_t selfSize)1652     SamplingHeapProfileNode &SetSelfSize(int32_t selfSize)
1653     {
1654         selfSize_ = selfSize;
1655         return *this;
1656     }
1657 
GetSelfSize()1658     int32_t GetSelfSize() const
1659     {
1660         return selfSize_;
1661     }
1662 
SetId(int32_t id)1663     SamplingHeapProfileNode &SetId(int32_t id)
1664     {
1665         id_ = id;
1666         return *this;
1667     }
1668 
GetId()1669     int32_t GetId() const
1670     {
1671         return id_;
1672     }
1673 
SetChildren(std::vector<std::unique_ptr<SamplingHeapProfileNode>> children)1674     SamplingHeapProfileNode &SetChildren(std::vector<std::unique_ptr<SamplingHeapProfileNode>> children)
1675     {
1676         children_ = std::move(children);
1677         return *this;
1678     }
1679 
GetChildren()1680     const std::vector<std::unique_ptr<SamplingHeapProfileNode>> *GetChildren() const
1681     {
1682         return &children_;
1683     }
1684 
1685 private:
1686     NO_COPY_SEMANTIC(SamplingHeapProfileNode);
1687     NO_MOVE_SEMANTIC(SamplingHeapProfileNode);
1688 
1689     std::unique_ptr<RuntimeCallFrame> callFrame_ {nullptr};
1690     int32_t selfSize_ {0};
1691     int32_t id_ {0};
1692     std::vector<std::unique_ptr<SamplingHeapProfileNode>> children_ {};
1693 };
1694 
1695 class SamplingHeapProfile final : public PtBaseTypes {
1696 public:
1697     SamplingHeapProfile() = default;
1698     ~SamplingHeapProfile() override = default;
1699     static std::unique_ptr<SamplingHeapProfile> Create(const PtJson &params);
1700     std::unique_ptr<PtJson> ToJson() const override;
1701 
SetHead(std::unique_ptr<SamplingHeapProfileNode> head)1702     SamplingHeapProfile &SetHead(std::unique_ptr<SamplingHeapProfileNode> head)
1703     {
1704         head_ = std::move(head);
1705         return *this;
1706     }
1707 
GetHead()1708     SamplingHeapProfileNode *GetHead() const
1709     {
1710         return head_.get();
1711     }
1712 
SetSamples(std::vector<std::unique_ptr<SamplingHeapProfileSample>> samples)1713     SamplingHeapProfile &SetSamples(std::vector<std::unique_ptr<SamplingHeapProfileSample>> samples)
1714     {
1715         samples_ = std::move(samples);
1716         return *this;
1717     }
1718 
GetSamples()1719     const std::vector<std::unique_ptr<SamplingHeapProfileSample>> *GetSamples() const
1720     {
1721         return &samples_;
1722     }
1723 
1724 private:
1725     NO_COPY_SEMANTIC(SamplingHeapProfile);
1726     NO_MOVE_SEMANTIC(SamplingHeapProfile);
1727 
1728     std::unique_ptr<SamplingHeapProfileNode> head_ {nullptr};
1729     std::vector<std::unique_ptr<SamplingHeapProfileSample>> samples_ {};
1730 };
1731 
1732 // ========== Profiler types begin
1733 // Profiler.PositionTickInfo
1734 class PositionTickInfo final : public PtBaseTypes {
1735 public:
1736     PositionTickInfo() = default;
1737     ~PositionTickInfo() override = default;
1738 
1739     static std::unique_ptr<PositionTickInfo> Create(const PtJson &params);
1740     std::unique_ptr<PtJson> ToJson() const override;
1741 
GetLine()1742     int32_t GetLine() const
1743     {
1744         return line_;
1745     }
1746 
SetLine(int32_t line)1747     PositionTickInfo &SetLine(int32_t line)
1748     {
1749         line_ = line;
1750         return *this;
1751     }
1752 
GetTicks()1753     int32_t GetTicks() const
1754     {
1755         return ticks_;
1756     }
1757 
SetTicks(int32_t ticks)1758     PositionTickInfo &SetTicks(int32_t ticks)
1759     {
1760         ticks_ = ticks;
1761         return *this;
1762     }
1763 
1764 private:
1765     NO_COPY_SEMANTIC(PositionTickInfo);
1766     NO_MOVE_SEMANTIC(PositionTickInfo);
1767     int32_t line_ {0};
1768     int32_t ticks_ {0};
1769 };
1770 
1771 // Profiler.ProfileNode
1772 class ProfileNode final : public PtBaseTypes {
1773 public:
1774     ProfileNode() = default;
1775     ~ProfileNode() override = default;
1776 
1777     static std::unique_ptr<ProfileNode> Create(const PtJson &params);
1778     static std::unique_ptr<ProfileNode> FromCpuProfileNode(const CpuProfileNode &cpuProfileNode);
1779     std::unique_ptr<PtJson> ToJson() const override;
1780 
GetId()1781     int32_t GetId() const
1782     {
1783         return id_;
1784     }
1785 
SetId(int32_t id)1786     ProfileNode &SetId(int32_t id)
1787     {
1788         id_ = id;
1789         return *this;
1790     }
1791 
GetCallFrame()1792     RuntimeCallFrame *GetCallFrame() const
1793     {
1794         return callFrame_.get();
1795     }
1796 
SetCallFrame(std::unique_ptr<RuntimeCallFrame> callFrame)1797     ProfileNode &SetCallFrame(std::unique_ptr<RuntimeCallFrame> callFrame)
1798     {
1799         callFrame_ = std::move(callFrame);
1800         return *this;
1801     }
1802 
GetHitCount()1803     int32_t GetHitCount() const
1804     {
1805         ASSERT(HasHitCount());
1806         return hitCount_.value();
1807     }
1808 
SetHitCount(int32_t hitCount)1809     ProfileNode &SetHitCount(int32_t hitCount)
1810     {
1811         hitCount_ = hitCount;
1812         return *this;
1813     }
1814 
HasHitCount()1815     bool HasHitCount() const
1816     {
1817         return hitCount_.has_value();
1818     }
1819 
GetChildren()1820     const std::vector<int32_t> *GetChildren() const
1821     {
1822         if (children_) {
1823             return &children_.value();
1824         }
1825         return nullptr;
1826     }
1827 
SetChildren(std::vector<int32_t> children)1828     ProfileNode &SetChildren(std::vector<int32_t> children)
1829     {
1830         children_ = std::move(children);
1831         return *this;
1832     }
1833 
HasChildren()1834     bool HasChildren() const
1835     {
1836         return children_.has_value();
1837     }
1838 
GetPositionTicks()1839     const std::vector<std::unique_ptr<PositionTickInfo>> *GetPositionTicks() const
1840     {
1841         if (positionTicks_) {
1842             return &positionTicks_.value();
1843         }
1844         return nullptr;
1845     }
1846 
SetPositionTicks(std::vector<std::unique_ptr<PositionTickInfo>> positionTicks)1847     ProfileNode &SetPositionTicks(std::vector<std::unique_ptr<PositionTickInfo>> positionTicks)
1848     {
1849         positionTicks_ = std::move(positionTicks);
1850         return *this;
1851     }
1852 
HasPositionTicks()1853     bool HasPositionTicks() const
1854     {
1855         return positionTicks_.has_value();
1856     }
1857 
GetDeoptReason()1858     const std::string &GetDeoptReason() const
1859     {
1860         ASSERT(HasDeoptReason());
1861         return deoptReason_.value();
1862     }
1863 
SetDeoptReason(const std::string & deoptReason)1864     ProfileNode &SetDeoptReason(const std::string &deoptReason)
1865     {
1866         deoptReason_ = deoptReason;
1867         return *this;
1868     }
1869 
HasDeoptReason()1870     bool HasDeoptReason() const
1871     {
1872         return deoptReason_.has_value();
1873     }
1874 
1875 private:
1876     NO_COPY_SEMANTIC(ProfileNode);
1877     NO_MOVE_SEMANTIC(ProfileNode);
1878     int32_t id_ {0};
1879     std::unique_ptr<RuntimeCallFrame> callFrame_ {nullptr};
1880     std::optional<int32_t> hitCount_ {0};
1881     std::optional<std::vector<int32_t>> children_ {};
1882     std::optional<std::vector<std::unique_ptr<PositionTickInfo>>> positionTicks_ {};
1883     std::optional<std::string> deoptReason_ {};
1884 };
1885 
1886 // Profiler.Profile
1887 class Profile final : public PtBaseTypes {
1888 public:
1889     Profile() = default;
1890     ~Profile() override = default;
1891 
1892     static std::unique_ptr<Profile> Create(const PtJson &params);
1893     static std::unique_ptr<Profile> FromProfileInfo(const ProfileInfo &profileInfo);
1894     std::unique_ptr<PtJson> ToJson() const override;
1895 
GetTid()1896     int64_t GetTid() const
1897     {
1898         return tid_;
1899     }
1900 
SetTid(int64_t tid)1901     Profile &SetTid(int64_t tid)
1902     {
1903         tid_ = tid;
1904         return *this;
1905     }
1906 
GetStartTime()1907     int64_t GetStartTime() const
1908     {
1909         return startTime_;
1910     }
1911 
SetStartTime(int64_t startTime)1912     Profile &SetStartTime(int64_t startTime)
1913     {
1914         startTime_ = startTime;
1915         return *this;
1916     }
1917 
GetEndTime()1918     int64_t GetEndTime() const
1919     {
1920         return endTime_;
1921     }
1922 
SetEndTime(int64_t endTime)1923     Profile &SetEndTime(int64_t endTime)
1924     {
1925         endTime_ = endTime;
1926         return *this;
1927     }
1928 
GetGcTime()1929     int64_t GetGcTime() const
1930     {
1931         return gcTime_;
1932     }
1933 
SetGcTime(int64_t gcTime)1934     Profile &SetGcTime(int64_t gcTime)
1935     {
1936         gcTime_ = gcTime;
1937         return *this;
1938     }
1939 
GetCInterpreterTime()1940     int64_t GetCInterpreterTime() const
1941     {
1942         return cInterpreterTime_;
1943     }
1944 
SetCInterpreterTime(int64_t cInterpreterTime)1945     Profile &SetCInterpreterTime(int64_t cInterpreterTime)
1946     {
1947         cInterpreterTime_ = cInterpreterTime;
1948         return *this;
1949     }
1950 
GetAsmInterpreterTime()1951     int64_t GetAsmInterpreterTime() const
1952     {
1953         return asmInterpreterTime_;
1954     }
1955 
SetAsmInterpreterTime(int64_t asmInterpreterTime)1956     Profile &SetAsmInterpreterTime(int64_t asmInterpreterTime)
1957     {
1958         asmInterpreterTime_ = asmInterpreterTime;
1959         return *this;
1960     }
1961 
GetAotTime()1962     int64_t GetAotTime() const
1963     {
1964         return aotTime_;
1965     }
1966 
SetAotTime(int64_t aotTime)1967     Profile &SetAotTime(int64_t aotTime)
1968     {
1969         aotTime_ = aotTime;
1970         return *this;
1971     }
1972 
GetBuiltinTime()1973     int64_t GetBuiltinTime() const
1974     {
1975         return builtinTime_;
1976     }
1977 
SetBuiltinTime(int64_t builtinTime)1978     Profile &SetBuiltinTime(int64_t builtinTime)
1979     {
1980         builtinTime_ = builtinTime;
1981         return *this;
1982     }
1983 
GetNapiTime()1984     int64_t GetNapiTime() const
1985     {
1986         return napiTime_;
1987     }
1988 
SetNapiTime(int64_t napiTime)1989     Profile &SetNapiTime(int64_t napiTime)
1990     {
1991         napiTime_ = napiTime;
1992         return *this;
1993     }
1994 
GetArkuiEngineTime()1995     int64_t GetArkuiEngineTime() const
1996     {
1997         return arkuiEngineTime_;
1998     }
1999 
SetArkuiEngineTime(int64_t arkuiEngineTime)2000     Profile &SetArkuiEngineTime(int64_t arkuiEngineTime)
2001     {
2002         arkuiEngineTime_ = arkuiEngineTime;
2003         return *this;
2004     }
2005 
GetRuntimeTime()2006     int64_t GetRuntimeTime() const
2007     {
2008         return runtimeTime_;
2009     }
2010 
SetRuntimeTime(int64_t runtimeTime)2011     Profile &SetRuntimeTime(int64_t runtimeTime)
2012     {
2013         runtimeTime_ = runtimeTime;
2014         return *this;
2015     }
2016 
GetOtherTime()2017     int64_t GetOtherTime() const
2018     {
2019         return otherTime_;
2020     }
2021 
SetOtherTime(int64_t otherTime)2022     Profile &SetOtherTime(int64_t otherTime)
2023     {
2024         otherTime_ = otherTime;
2025         return *this;
2026     }
2027 
GetNodes()2028     const std::vector<std::unique_ptr<ProfileNode>> *GetNodes() const
2029     {
2030         return &nodes_;
2031     }
2032 
SetNodes(std::vector<std::unique_ptr<ProfileNode>> nodes)2033     Profile &SetNodes(std::vector<std::unique_ptr<ProfileNode>> nodes)
2034     {
2035         nodes_ = std::move(nodes);
2036         return *this;
2037     }
2038 
GetSamples()2039     const std::vector<int32_t> *GetSamples() const
2040     {
2041         if (samples_) {
2042             return &samples_.value();
2043         }
2044         return nullptr;
2045     }
2046 
SetSamples(std::vector<int32_t> samples)2047     Profile &SetSamples(std::vector<int32_t> samples)
2048     {
2049         samples_ = std::move(samples);
2050         return *this;
2051     }
2052 
HasSamples()2053     bool HasSamples() const
2054     {
2055         return samples_.has_value();
2056     }
2057 
GetTimeDeltas()2058     const std::vector<int32_t> *GetTimeDeltas() const
2059     {
2060         if (timeDeltas_) {
2061             return &timeDeltas_.value();
2062         }
2063         return nullptr;
2064     }
2065 
SetTimeDeltas(std::vector<int32_t> timeDeltas)2066     Profile &SetTimeDeltas(std::vector<int32_t> timeDeltas)
2067     {
2068         timeDeltas_ = std::move(timeDeltas);
2069         return *this;
2070     }
2071 
HasTimeDeltas()2072     bool HasTimeDeltas() const
2073     {
2074         return timeDeltas_.has_value();
2075     }
2076 
2077 private:
2078     NO_COPY_SEMANTIC(Profile);
2079     NO_MOVE_SEMANTIC(Profile);
2080 
2081     int64_t tid_ {0};
2082     int64_t startTime_ {0};
2083     int64_t endTime_ {0};
2084     int64_t gcTime_ {0};
2085     int64_t cInterpreterTime_ {0};
2086     int64_t asmInterpreterTime_ {0};
2087     int64_t aotTime_ {0};
2088     int64_t builtinTime_ {0};
2089     int64_t napiTime_ {0};
2090     int64_t arkuiEngineTime_ {0};
2091     int64_t runtimeTime_ {0};
2092     int64_t otherTime_ {0};
2093     std::vector<std::unique_ptr<ProfileNode>> nodes_ {};
2094     std::optional<std::vector<int32_t>> samples_ {};
2095     std::optional<std::vector<int32_t>> timeDeltas_ {};
2096 };
2097 
2098 // Profiler.Coverage
2099 class Coverage final : public PtBaseTypes {
2100 public:
2101     Coverage() = default;
2102     ~Coverage() override = default;
2103 
2104     static std::unique_ptr<Coverage> Create(const PtJson &params);
2105     std::unique_ptr<PtJson> ToJson() const override;
2106 
GetStartOffset()2107     int32_t GetStartOffset() const
2108     {
2109         return startOffset_;
2110     }
2111 
SetStartOffset(int32_t startOffset)2112     Coverage &SetStartOffset(int32_t startOffset)
2113     {
2114         startOffset_ = startOffset;
2115         return *this;
2116     }
2117 
GetEndOffset()2118     int32_t GetEndOffset() const
2119     {
2120         return endOffset_;
2121     }
2122 
SetEndOffset(int32_t endOffset)2123     Coverage &SetEndOffset(int32_t endOffset)
2124     {
2125         endOffset_ = endOffset;
2126         return *this;
2127     }
2128 
GetCount()2129     int32_t GetCount() const
2130     {
2131         return count_;
2132     }
2133 
SetCount(int32_t count)2134     Coverage &SetCount(int32_t count)
2135     {
2136         count_ = count;
2137         return *this;
2138     }
2139 
2140 private:
2141     NO_COPY_SEMANTIC(Coverage);
2142     NO_MOVE_SEMANTIC(Coverage);
2143 
2144     int32_t startOffset_ {0};
2145     int32_t endOffset_ {0};
2146     int32_t count_ {0};
2147 };
2148 
2149 // Profiler.FunctionCoverage
2150 class FunctionCoverage final : public PtBaseTypes {
2151 public:
2152     FunctionCoverage() = default;
2153     ~FunctionCoverage() override = default;
2154 
2155     static std::unique_ptr<FunctionCoverage> Create(const PtJson &params);
2156     std::unique_ptr<PtJson> ToJson() const override;
2157 
GetFunctionName()2158     const std::string &GetFunctionName() const
2159     {
2160         return functionName_;
2161     }
2162 
SetFunctionName(const std::string & functionName)2163     FunctionCoverage &SetFunctionName(const std::string &functionName)
2164     {
2165         functionName_ = functionName;
2166         return *this;
2167     }
2168 
GetRanges()2169     const std::vector<std::unique_ptr<Coverage>> *GetRanges() const
2170     {
2171         return &ranges_;
2172     }
2173 
SetFunctions(std::vector<std::unique_ptr<Coverage>> ranges)2174     FunctionCoverage &SetFunctions(std::vector<std::unique_ptr<Coverage>> ranges)
2175     {
2176         ranges_ = std::move(ranges);
2177         return *this;
2178     }
2179 
GetIsBlockCoverage()2180     bool GetIsBlockCoverage() const
2181     {
2182         return isBlockCoverage_;
2183     }
2184 
SetisBlockCoverage(bool isBlockCoverage)2185     FunctionCoverage &SetisBlockCoverage(bool isBlockCoverage)
2186     {
2187         isBlockCoverage_ = isBlockCoverage;
2188         return *this;
2189     }
2190 
2191 private:
2192     NO_COPY_SEMANTIC(FunctionCoverage);
2193     NO_MOVE_SEMANTIC(FunctionCoverage);
2194 
2195     std::string functionName_ {};
2196     std::vector<std::unique_ptr<Coverage>> ranges_ {};
2197     bool isBlockCoverage_ {};
2198 };
2199 
2200 // Profiler.ScriptCoverage
2201 // Profiler.GetBestEffortCoverage and Profiler.TakePreciseCoverage share this return value type
2202 class ScriptCoverage final : public PtBaseTypes {
2203 public:
2204     ScriptCoverage() = default;
2205     ~ScriptCoverage() override = default;
2206 
2207     static std::unique_ptr<ScriptCoverage> Create(const PtJson &params);
2208     std::unique_ptr<PtJson> ToJson() const override;
2209 
GetScriptId()2210     const std::string &GetScriptId() const
2211     {
2212         return scriptId_;
2213     }
2214 
SetScriptId(const std::string & scriptId)2215     ScriptCoverage &SetScriptId(const std::string &scriptId)
2216     {
2217         scriptId_ = scriptId;
2218         return *this;
2219     }
2220 
GetUrl()2221     const std::string &GetUrl() const
2222     {
2223         return url_;
2224     }
2225 
SetUrl(const std::string & url)2226     ScriptCoverage &SetUrl(const std::string &url)
2227     {
2228         url_ = url;
2229         return *this;
2230     }
2231 
GetFunctions()2232     const std::vector<std::unique_ptr<FunctionCoverage>> *GetFunctions() const
2233     {
2234         return &functions_;
2235     }
2236 
SetFunctions(std::vector<std::unique_ptr<FunctionCoverage>> functions)2237     ScriptCoverage &SetFunctions(std::vector<std::unique_ptr<FunctionCoverage>> functions)
2238     {
2239         functions_ = std::move(functions);
2240         return *this;
2241     }
2242 
2243 private:
2244     NO_COPY_SEMANTIC(ScriptCoverage);
2245     NO_MOVE_SEMANTIC(ScriptCoverage);
2246 
2247     std::string scriptId_ {};
2248     std::string url_ {};
2249     std::vector<std::unique_ptr<FunctionCoverage>> functions_ {};
2250 };
2251 
2252 // Profiler.TypeObject
2253 class TypeObject final : public PtBaseTypes {
2254 public:
2255     TypeObject() = default;
2256     ~TypeObject() override = default;
2257 
2258     static std::unique_ptr<TypeObject> Create(const PtJson &params);
2259     std::unique_ptr<PtJson> ToJson() const override;
2260 
GetName()2261     const std::string &GetName() const
2262     {
2263         return name_;
2264     }
2265 
SetName(const std::string & name)2266     TypeObject &SetName(const std::string &name)
2267     {
2268         name_ = name;
2269         return *this;
2270     }
2271 
2272 private:
2273     NO_COPY_SEMANTIC(TypeObject);
2274     NO_MOVE_SEMANTIC(TypeObject);
2275 
2276     std::string name_ {};
2277 };
2278 
2279 // Profiler.TypeProfileEntry
2280 class TypeProfileEntry final : public PtBaseTypes {
2281 public:
2282     TypeProfileEntry() = default;
2283     ~TypeProfileEntry() override = default;
2284 
2285     static std::unique_ptr<TypeProfileEntry> Create(const PtJson &params);
2286     std::unique_ptr<PtJson> ToJson() const override;
2287 
GetOffset()2288     int32_t GetOffset() const
2289     {
2290         return offset_;
2291     }
2292 
SetOffset(int32_t offset)2293     TypeProfileEntry &SetOffset(int32_t offset)
2294     {
2295         offset_ = offset;
2296         return *this;
2297     }
2298 
GetTypes()2299     const std::vector<std::unique_ptr<TypeObject>> *GetTypes() const
2300     {
2301         return &types_;
2302     }
2303 
SetTypes(std::vector<std::unique_ptr<TypeObject>> types)2304     TypeProfileEntry &SetTypes(std::vector<std::unique_ptr<TypeObject>> types)
2305     {
2306         types_ = std::move(types);
2307         return *this;
2308     }
2309 
2310 private:
2311     NO_COPY_SEMANTIC(TypeProfileEntry);
2312     NO_MOVE_SEMANTIC(TypeProfileEntry);
2313 
2314     int32_t offset_ {0};
2315     std::vector<std::unique_ptr<TypeObject>> types_ {};
2316 };
2317 
2318 // Profiler.ScriptTypeProfile
2319 class ScriptTypeProfile final : public PtBaseTypes {
2320 public:
2321     ScriptTypeProfile() = default;
2322     ~ScriptTypeProfile() override = default;
2323 
2324     static std::unique_ptr<ScriptTypeProfile> Create(const PtJson &params);
2325     std::unique_ptr<PtJson> ToJson() const override;
2326 
GetScriptId()2327     const std::string &GetScriptId() const
2328     {
2329         return scriptId_;
2330     }
2331 
SetScriptId(const std::string & scriptId)2332     ScriptTypeProfile &SetScriptId(const std::string &scriptId)
2333     {
2334         scriptId_ = scriptId;
2335         return *this;
2336     }
2337 
GetUrl()2338     const std::string &GetUrl() const
2339     {
2340         return url_;
2341     }
2342 
SetUrl(const std::string & url)2343     ScriptTypeProfile &SetUrl(const std::string &url)
2344     {
2345         url_ = url;
2346         return *this;
2347     }
2348 
GetEntries()2349     const std::vector<std::unique_ptr<TypeProfileEntry>> *GetEntries() const
2350     {
2351         return &entries_;
2352     }
2353 
SetEntries(std::vector<std::unique_ptr<TypeProfileEntry>> entries)2354     ScriptTypeProfile &SetEntries(std::vector<std::unique_ptr<TypeProfileEntry>> entries)
2355     {
2356         entries_ = std::move(entries);
2357         return *this;
2358     }
2359 
2360 private:
2361     NO_COPY_SEMANTIC(ScriptTypeProfile);
2362     NO_MOVE_SEMANTIC(ScriptTypeProfile);
2363 
2364     std::string scriptId_ {};
2365     std::string url_ {};
2366     std::vector<std::unique_ptr<TypeProfileEntry>> entries_ {};
2367 };
2368 
2369 // ========== Tracing types begin
2370 // Tracing.MemoryDumpConfig
2371 using MemoryDumpConfig = PtJson;
2372 
2373 // Tracing.MemoryDumpLevelOfDetail
2374 using MemoryDumpLevelOfDetail = std::string;
2375 struct MemoryDumpLevelOfDetailValues {
ValidMemoryDumpLevelOfDetailValues2376     static bool Valid(const std::string &values)
2377     {
2378         return values == Background() || values == Light() || values == Detailed();
2379     }
BackgroundMemoryDumpLevelOfDetailValues2380     static std::string Background()
2381     {
2382         return "background";
2383     }
LightMemoryDumpLevelOfDetailValues2384     static std::string Light()
2385     {
2386         return "light";
2387     }
DetailedMemoryDumpLevelOfDetailValues2388     static std::string Detailed()
2389     {
2390         return "detailed";
2391     }
2392 };
2393 
2394 // Tracing.StreamCompression
2395 using StreamCompression = std::string;
2396 struct StreamCompressionValues {
ValidStreamCompressionValues2397     static bool Valid(const std::string &values)
2398     {
2399         return values == None() || values == Gzip();
2400     }
NoneStreamCompressionValues2401     static std::string None()
2402     {
2403         return "none";
2404     }
GzipStreamCompressionValues2405     static std::string Gzip()
2406     {
2407         return "gzip";
2408     }
2409 };
2410 
2411 // Tracing.StreamFormat
2412 using StreamFormat = std::string;
2413 struct StreamFormatValues {
ValidStreamFormatValues2414     static bool Valid(const std::string &values)
2415     {
2416         return values == Json() || values == Proto();
2417     }
JsonStreamFormatValues2418     static std::string Json()
2419     {
2420         return "json";
2421     }
ProtoStreamFormatValues2422     static std::string Proto()
2423     {
2424         return "proto";
2425     }
2426 };
2427 
2428 // Tracing.TraceConfig
2429 class TraceConfig final : public PtBaseTypes {
2430 public:
2431     TraceConfig() = default;
2432     ~TraceConfig() override = default;
2433 
2434     static std::unique_ptr<TraceConfig> Create(const PtJson &params);
2435     std::unique_ptr<PtJson> ToJson() const override;
2436 
GetRecordMode()2437     std::string GetRecordMode() const
2438     {
2439         return recordMode_.value();
2440     }
2441 
SetRecordMode(std::string recordMode)2442     TraceConfig &SetRecordMode(std::string recordMode)
2443     {
2444         recordMode_ = recordMode;
2445         return *this;
2446     }
2447 
HasRecordMode()2448     bool HasRecordMode() const
2449     {
2450         return recordMode_.has_value();
2451     }
2452 
2453     struct RecordModeValues {
ValidRecordModeValues2454         static bool Valid(const std::string &values)
2455         {
2456             return values == RecordUntilFull() || values == RecordContinuously() ||
2457                    values == RecordAsMuchAsPossible() || values == EchoToConsole();
2458         }
RecordUntilFullRecordModeValues2459         static std::string RecordUntilFull()
2460         {
2461             return "recordUntilFull";
2462         }
RecordContinuouslyRecordModeValues2463         static std::string RecordContinuously()
2464         {
2465             return "recordContinuously";
2466         }
RecordAsMuchAsPossibleRecordModeValues2467         static std::string RecordAsMuchAsPossible()
2468         {
2469             return "recordAsMuchAsPossible";
2470         }
EchoToConsoleRecordModeValues2471         static std::string EchoToConsole()
2472         {
2473             return "echoToConsole";
2474         }
2475     };
2476 
GetEnableSampling()2477     bool GetEnableSampling() const
2478     {
2479         return enableSampling_.value();
2480     }
2481 
SetEnableSampling(bool enableSampling)2482     TraceConfig &SetEnableSampling(bool enableSampling)
2483     {
2484         enableSampling_ = enableSampling;
2485         return *this;
2486     }
2487 
HasEnableSampling()2488     bool HasEnableSampling() const
2489     {
2490         return enableSampling_.has_value();
2491     }
2492 
GetEnableSystrace()2493     bool GetEnableSystrace() const
2494     {
2495         return enableSystrace_.value();
2496     }
2497 
SetEnableSystrace(bool enableSystrace)2498     TraceConfig &SetEnableSystrace(bool enableSystrace)
2499     {
2500         enableSystrace_ = enableSystrace;
2501         return *this;
2502     }
2503 
HasEnableSystrace()2504     bool HasEnableSystrace() const
2505     {
2506         return enableSystrace_.has_value();
2507     }
2508 
GetEnableArgumentFilter()2509     bool GetEnableArgumentFilter() const
2510     {
2511         return enableArgumentFilter_.value();
2512     }
2513 
SetEnableArgumentFilter(bool enableArgumentFilter)2514     TraceConfig &SetEnableArgumentFilter(bool enableArgumentFilter)
2515     {
2516         enableArgumentFilter_ = enableArgumentFilter;
2517         return *this;
2518     }
2519 
HasEnableArgumentFilter()2520     bool HasEnableArgumentFilter() const
2521     {
2522         return enableArgumentFilter_.has_value();
2523     }
2524 
GetIncludedCategories()2525     const std::vector<std::string> *GetIncludedCategories() const
2526     {
2527         if (includedCategories_) {
2528             return &includedCategories_.value();
2529         }
2530         return nullptr;
2531     }
2532 
SetIncludedCategories(std::vector<std::string> includedCategories)2533     TraceConfig &SetIncludedCategories(std::vector<std::string> includedCategories)
2534     {
2535         includedCategories_ = includedCategories;
2536         return *this;
2537     }
2538 
HasIncludedCategories()2539     bool HasIncludedCategories() const
2540     {
2541         return includedCategories_.has_value();
2542     }
2543 
GetExcludedCategories()2544     const std::vector<std::string> *GetExcludedCategories() const
2545     {
2546         if (excludedCategories_) {
2547             return &excludedCategories_.value();
2548         }
2549         return nullptr;
2550     }
2551 
SetExcludedCategories(std::vector<std::string> excludedCategories)2552     TraceConfig &SetExcludedCategories(std::vector<std::string> excludedCategories)
2553     {
2554         excludedCategories_ = excludedCategories;
2555         return *this;
2556     }
2557 
HasExcludedCategories()2558     bool HasExcludedCategories() const
2559     {
2560         return excludedCategories_.has_value();
2561     }
2562 
GetSyntheticDelays()2563     const std::vector<std::string> *GetSyntheticDelays() const
2564     {
2565         if (syntheticDelays_) {
2566             return &syntheticDelays_.value();
2567         }
2568         return nullptr;
2569     }
2570 
SetSyntheticDelays(std::vector<std::string> syntheticDelays)2571     TraceConfig &SetSyntheticDelays(std::vector<std::string> syntheticDelays)
2572     {
2573         syntheticDelays_ = syntheticDelays;
2574         return *this;
2575     }
2576 
HasSyntheticDelays()2577     bool HasSyntheticDelays() const
2578     {
2579         return syntheticDelays_.has_value();
2580     }
2581 
2582 private:
2583     NO_COPY_SEMANTIC(TraceConfig);
2584     NO_MOVE_SEMANTIC(TraceConfig);
2585 
2586     std::optional<std::string> recordMode_ {};
2587     std::optional<bool> enableSampling_ {};
2588     std::optional<bool> enableSystrace_ {};
2589     std::optional<bool> enableArgumentFilter_ {};
2590     std::optional<std::vector<std::string>> includedCategories_ {};
2591     std::optional<std::vector<std::string>> excludedCategories_ {};
2592     std::optional<std::vector<std::string>> syntheticDelays_ {};
2593     std::optional<std::unique_ptr<MemoryDumpConfig>> memoryDumpConfig_ {};
2594 };
2595 
2596 // Tracing.TracingBackend
2597 using TracingBackend = std::string;
2598 struct TracingBackendValues {
ValidTracingBackendValues2599     static bool Valid(const std::string &values)
2600     {
2601         return values == Auto() || values == Chrome() || values == System();
2602     }
AutoTracingBackendValues2603     static std::string Auto()
2604     {
2605         return "auto";
2606     }
ChromeTracingBackendValues2607     static std::string Chrome()
2608     {
2609         return "chrome";
2610     }
SystemTracingBackendValues2611     static std::string System()
2612     {
2613         return "system";
2614     }
2615 };
2616 }  // namespace panda::ecmascript::tooling
2617 #endif
2618