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