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