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_RETURNS_H 17 #define ECMASCRIPT_TOOLING_BASE_PT_RETURNS_H 18 19 #include "tooling/dynamic/base/pt_types.h" 20 21 namespace panda::ecmascript::tooling { 22 class PtBaseReturns : public PtBaseTypes { 23 public: 24 PtBaseReturns() = default; 25 ~PtBaseReturns() override = default; ToJson()26 std::unique_ptr<PtJson> ToJson() const override 27 { 28 return PtJson::CreateObject(); 29 } 30 31 private: 32 NO_COPY_SEMANTIC(PtBaseReturns); 33 NO_MOVE_SEMANTIC(PtBaseReturns); 34 }; 35 36 class DebuggerEnableReturns : public PtBaseReturns { 37 public: DebuggerEnableReturns(UniqueDebuggerId id,std::vector<std::string> list)38 explicit DebuggerEnableReturns(UniqueDebuggerId id, std::vector<std::string> list) 39 : debuggerId_(id), protocols_(list) {} 40 ~DebuggerEnableReturns() override = default; 41 42 std::unique_ptr<PtJson> ToJson() const override; 43 44 private: 45 DebuggerEnableReturns() = default; 46 NO_COPY_SEMANTIC(DebuggerEnableReturns); 47 NO_MOVE_SEMANTIC(DebuggerEnableReturns); 48 49 UniqueDebuggerId debuggerId_ {}; 50 std::vector<std::string> protocols_ {}; 51 }; 52 53 class EnableReturns : public PtBaseReturns { 54 public: EnableReturns(std::vector<std::string> list)55 explicit EnableReturns(std::vector<std::string> list) : protocols_(list) {} 56 ~EnableReturns() override = default; 57 58 std::unique_ptr<PtJson> ToJson() const override; 59 60 private: 61 EnableReturns() = default; 62 NO_COPY_SEMANTIC(EnableReturns); 63 NO_MOVE_SEMANTIC(EnableReturns); 64 65 std::vector<std::string> protocols_ {}; 66 }; 67 68 class SetBreakpointByUrlReturns : public PtBaseReturns { 69 public: SetBreakpointByUrlReturns(const std::string & id,std::vector<std::unique_ptr<Location>> locations)70 explicit SetBreakpointByUrlReturns(const std::string &id, std::vector<std::unique_ptr<Location>> locations) 71 : id_(id), locations_(std::move(locations)) 72 {} 73 ~SetBreakpointByUrlReturns() override = default; 74 75 std::unique_ptr<PtJson> ToJson() const override; 76 77 private: 78 SetBreakpointByUrlReturns() = default; 79 NO_COPY_SEMANTIC(SetBreakpointByUrlReturns); 80 NO_MOVE_SEMANTIC(SetBreakpointByUrlReturns); 81 82 std::string id_ {}; 83 std::vector<std::unique_ptr<Location>> locations_ {}; 84 }; 85 86 class GetPossibleAndSetBreakpointByUrlReturns : public PtBaseReturns { 87 public: GetPossibleAndSetBreakpointByUrlReturns(std::vector<std::shared_ptr<BreakpointReturnInfo>> locations)88 explicit GetPossibleAndSetBreakpointByUrlReturns(std::vector<std::shared_ptr<BreakpointReturnInfo>> locations) 89 : locations_(std::move(locations)) 90 {} 91 ~GetPossibleAndSetBreakpointByUrlReturns() override = default; 92 93 std::unique_ptr<PtJson> ToJson() const override; 94 95 private: 96 GetPossibleAndSetBreakpointByUrlReturns() = default; 97 NO_COPY_SEMANTIC(GetPossibleAndSetBreakpointByUrlReturns); 98 NO_MOVE_SEMANTIC(GetPossibleAndSetBreakpointByUrlReturns); 99 100 std::vector<std::shared_ptr<BreakpointReturnInfo>> locations_ {}; 101 }; 102 103 class EvaluateOnCallFrameReturns : public PtBaseReturns { 104 public: 105 explicit EvaluateOnCallFrameReturns(std::unique_ptr<RemoteObject> result, 106 std::optional<std::unique_ptr<ExceptionDetails>> exceptionDetails = std::nullopt) result_(std::move (result))107 : result_(std::move(result)), exceptionDetails_(std::move(exceptionDetails)) 108 {} 109 ~EvaluateOnCallFrameReturns() override = default; 110 std::unique_ptr<PtJson> ToJson() const override; 111 112 private: 113 EvaluateOnCallFrameReturns() = default; 114 NO_COPY_SEMANTIC(EvaluateOnCallFrameReturns); 115 NO_MOVE_SEMANTIC(EvaluateOnCallFrameReturns); 116 117 std::unique_ptr<RemoteObject> result_ {}; 118 std::optional<std::unique_ptr<ExceptionDetails>> exceptionDetails_ {}; 119 }; 120 121 class GetPossibleBreakpointsReturns : public PtBaseReturns { 122 public: GetPossibleBreakpointsReturns(std::vector<std::unique_ptr<BreakLocation>> locations)123 explicit GetPossibleBreakpointsReturns(std::vector<std::unique_ptr<BreakLocation>> locations) 124 : locations_(std::move(locations)) 125 {} 126 ~GetPossibleBreakpointsReturns() override = default; 127 128 std::unique_ptr<PtJson> ToJson() const override; 129 130 private: 131 GetPossibleBreakpointsReturns() = default; 132 NO_COPY_SEMANTIC(GetPossibleBreakpointsReturns); 133 NO_MOVE_SEMANTIC(GetPossibleBreakpointsReturns); 134 135 std::vector<std::unique_ptr<BreakLocation>> locations_ {}; 136 }; 137 138 class GetScriptSourceReturns : public PtBaseReturns { 139 public: 140 explicit GetScriptSourceReturns(const std::string &scriptSource, std::optional<std::string> bytecode = std::nullopt) scriptSource_(scriptSource)141 : scriptSource_(scriptSource), bytecode_(std::move(bytecode)) 142 {} 143 ~GetScriptSourceReturns() override = default; 144 145 std::unique_ptr<PtJson> ToJson() const override; 146 147 private: 148 GetScriptSourceReturns() = default; 149 NO_COPY_SEMANTIC(GetScriptSourceReturns); 150 NO_MOVE_SEMANTIC(GetScriptSourceReturns); 151 152 std::string scriptSource_ {}; 153 std::optional<std::string> bytecode_ {}; 154 }; 155 156 class RestartFrameReturns : public PtBaseReturns { 157 public: RestartFrameReturns(std::vector<std::unique_ptr<CallFrame>> callFrames)158 explicit RestartFrameReturns(std::vector<std::unique_ptr<CallFrame>> callFrames) 159 : callFrames_(std::move(callFrames)) 160 {} 161 ~RestartFrameReturns() override = default; 162 std::unique_ptr<PtJson> ToJson() const override; 163 164 private: 165 RestartFrameReturns() = default; 166 NO_COPY_SEMANTIC(RestartFrameReturns); 167 NO_MOVE_SEMANTIC(RestartFrameReturns); 168 169 std::vector<std::unique_ptr<CallFrame>> callFrames_ {}; 170 }; 171 172 class SearchInContentReturns : public PtBaseReturns { 173 public: SearchInContentReturns(std::vector<std::unique_ptr<SearchMatch>> result)174 explicit SearchInContentReturns(std::vector<std::unique_ptr<SearchMatch>> result) : result_(std::move(result)) 175 {} 176 ~SearchInContentReturns() override = default; 177 std::unique_ptr<PtJson> ToJson() const override; 178 179 private: 180 SearchInContentReturns() = default; 181 NO_COPY_SEMANTIC(SearchInContentReturns); 182 NO_MOVE_SEMANTIC(SearchInContentReturns); 183 184 std::vector<std::unique_ptr<SearchMatch>> result_ {}; 185 }; 186 187 class SetBreakpointReturns : public PtBaseReturns { 188 public: SetBreakpointReturns(const std::string & id,std::unique_ptr<Location> location)189 explicit SetBreakpointReturns(const std::string &id, std::unique_ptr<Location> location) 190 : breakpointId_(id), location_(std::move(location)) 191 {} 192 ~SetBreakpointReturns() override = default; 193 std::unique_ptr<PtJson> ToJson() const override; 194 195 private: 196 SetBreakpointReturns() = default; 197 NO_COPY_SEMANTIC(SetBreakpointReturns); 198 NO_MOVE_SEMANTIC(SetBreakpointReturns); 199 std::string breakpointId_ {}; 200 std::unique_ptr<Location> location_ {}; 201 }; 202 203 class SetInstrumentationBreakpointReturns : public PtBaseReturns { 204 public: SetInstrumentationBreakpointReturns(const std::string & id)205 explicit SetInstrumentationBreakpointReturns(const std::string &id) : breakpointId_(id) 206 {} 207 ~SetInstrumentationBreakpointReturns() override = default; 208 std::unique_ptr<PtJson> ToJson() const override; 209 210 private: 211 SetInstrumentationBreakpointReturns() = default; 212 NO_COPY_SEMANTIC(SetInstrumentationBreakpointReturns); 213 NO_MOVE_SEMANTIC(SetInstrumentationBreakpointReturns); 214 215 std::string breakpointId_ {}; 216 }; 217 218 class SetScriptSourceReturns : public PtBaseReturns { 219 public: 220 explicit SetScriptSourceReturns(std::optional<std::vector<std::unique_ptr<CallFrame>>> callFrames = std::nullopt, 221 std::optional<bool> stackChanged = std::nullopt, 222 std::optional<std::unique_ptr<ExceptionDetails>> exceptionDetails = std::nullopt) callFrames_(std::move (callFrames))223 : callFrames_(std::move(callFrames)), 224 stackChanged_(stackChanged), 225 exceptionDetails_(std::move(exceptionDetails)) 226 {} 227 ~SetScriptSourceReturns() override = default; 228 std::unique_ptr<PtJson> ToJson() const override; 229 230 private: 231 SetScriptSourceReturns() = default; 232 NO_COPY_SEMANTIC(SetScriptSourceReturns); 233 NO_MOVE_SEMANTIC(SetScriptSourceReturns); 234 235 std::optional<std::vector<std::unique_ptr<CallFrame>>> callFrames_ {}; 236 std::optional<bool> stackChanged_ {}; 237 std::optional<std::unique_ptr<ExceptionDetails>> exceptionDetails_ {}; 238 }; 239 240 class GetPropertiesReturns : public PtBaseReturns { 241 public: 242 explicit GetPropertiesReturns(std::vector<std::unique_ptr<PropertyDescriptor>> descriptor, 243 std::optional<std::vector<std::unique_ptr<InternalPropertyDescriptor>>> internalDescripties = std::nullopt, 244 std::optional<std::vector<std::unique_ptr<PrivatePropertyDescriptor>>> privateProperties = std::nullopt, 245 std::optional<std::unique_ptr<ExceptionDetails>> exceptionDetails = std::nullopt) result_(std::move (descriptor))246 : result_(std::move(descriptor)), 247 internalPropertyDescripties_(std::move(internalDescripties)), 248 privateProperties_(std::move(privateProperties)), 249 exceptionDetails_(std::move(exceptionDetails)) 250 {} 251 ~GetPropertiesReturns() override = default; 252 std::unique_ptr<PtJson> ToJson() const override; 253 254 private: 255 GetPropertiesReturns() = default; 256 NO_COPY_SEMANTIC(GetPropertiesReturns); 257 NO_MOVE_SEMANTIC(GetPropertiesReturns); 258 259 std::vector<std::unique_ptr<PropertyDescriptor>> result_ {}; 260 std::optional<std::vector<std::unique_ptr<InternalPropertyDescriptor>>> internalPropertyDescripties_ {}; 261 std::optional<std::vector<std::unique_ptr<PrivatePropertyDescriptor>>> privateProperties_ {}; 262 std::optional<std::unique_ptr<ExceptionDetails>> exceptionDetails_ {}; 263 }; 264 265 class CallFunctionOnReturns : public PtBaseReturns { 266 public: 267 explicit CallFunctionOnReturns(std::unique_ptr<RemoteObject> result, 268 std::optional<std::unique_ptr<ExceptionDetails>> exceptionDetails = std::nullopt) result_(std::move (result))269 : result_(std::move(result)), 270 exceptionDetails_(std::move(exceptionDetails)) 271 {} 272 ~CallFunctionOnReturns() override = default; 273 std::unique_ptr<PtJson> ToJson() const override; 274 275 private: 276 CallFunctionOnReturns() = default; 277 NO_COPY_SEMANTIC(CallFunctionOnReturns); 278 NO_MOVE_SEMANTIC(CallFunctionOnReturns); 279 280 std::unique_ptr<RemoteObject> result_ {}; 281 std::optional<std::unique_ptr<ExceptionDetails>> exceptionDetails_ {}; 282 }; 283 284 class StopSamplingReturns : public PtBaseReturns { 285 public: StopSamplingReturns(std::unique_ptr<SamplingHeapProfile> profile)286 explicit StopSamplingReturns(std::unique_ptr<SamplingHeapProfile> profile) 287 : profile_(std::move(profile)) 288 {} 289 ~StopSamplingReturns() override = default; 290 291 std::unique_ptr<PtJson> ToJson() const override; 292 293 private: 294 StopSamplingReturns() = default; 295 NO_COPY_SEMANTIC(StopSamplingReturns); 296 NO_MOVE_SEMANTIC(StopSamplingReturns); 297 298 std::unique_ptr<SamplingHeapProfile> profile_ {}; 299 }; 300 301 class GetHeapObjectIdReturns : public PtBaseReturns { 302 public: GetHeapObjectIdReturns(HeapSnapshotObjectId heapSnapshotObjectId)303 explicit GetHeapObjectIdReturns(HeapSnapshotObjectId heapSnapshotObjectId) 304 : heapSnapshotObjectId_(std::move(heapSnapshotObjectId)) 305 {} 306 ~GetHeapObjectIdReturns() override = default; 307 308 std::unique_ptr<PtJson> ToJson() const override; 309 310 private: 311 GetHeapObjectIdReturns() = default; 312 NO_COPY_SEMANTIC(GetHeapObjectIdReturns); 313 NO_MOVE_SEMANTIC(GetHeapObjectIdReturns); 314 315 HeapSnapshotObjectId heapSnapshotObjectId_ {}; 316 }; 317 318 class GetObjectByHeapObjectIdReturns : public PtBaseReturns { 319 public: GetObjectByHeapObjectIdReturns(std::unique_ptr<RemoteObject> remoteObjectResult)320 explicit GetObjectByHeapObjectIdReturns(std::unique_ptr<RemoteObject> remoteObjectResult) 321 : remoteObjectResult_(std::move(remoteObjectResult)) 322 {} 323 ~GetObjectByHeapObjectIdReturns() override = default; 324 325 std::unique_ptr<PtJson> ToJson() const override; 326 327 private: 328 GetObjectByHeapObjectIdReturns() = default; 329 NO_COPY_SEMANTIC(GetObjectByHeapObjectIdReturns); 330 NO_MOVE_SEMANTIC(GetObjectByHeapObjectIdReturns); 331 332 std::unique_ptr<RemoteObject> remoteObjectResult_ {}; 333 }; 334 335 class StopReturns : public PtBaseReturns { 336 public: StopReturns(std::unique_ptr<Profile> profile)337 explicit StopReturns(std::unique_ptr<Profile> profile) : profile_(std::move(profile)) {} 338 ~StopReturns() override = default; 339 std::unique_ptr<PtJson> ToJson() const override; 340 341 private: 342 StopReturns() = default; 343 NO_COPY_SEMANTIC(StopReturns); 344 NO_MOVE_SEMANTIC(StopReturns); 345 346 std::unique_ptr<Profile> profile_ {}; 347 }; 348 349 class TOOLCHAIN_EXPORT GetHeapUsageReturns : public PtBaseReturns { 350 public: 351 GetHeapUsageReturns() = default; GetHeapUsageReturns(double usedSize,double totalSize)352 explicit GetHeapUsageReturns(double usedSize, double totalSize) 353 : usedSize_(usedSize), totalSize_(totalSize) {} 354 ~GetHeapUsageReturns() override = default; 355 std::unique_ptr<PtJson> ToJson() const override; 356 357 static std::unique_ptr<GetHeapUsageReturns> Create(const PtJson ¶ms); 358 SetUsedSize(const double & usedSize)359 void SetUsedSize(const double &usedSize) 360 { 361 usedSize_ = usedSize; 362 } 363 GetUsedSize()364 double GetUsedSize() const 365 { 366 return usedSize_; 367 } 368 SetTotalSize(const double & totalSize)369 void SetTotalSize(const double &totalSize) 370 { 371 totalSize_ = totalSize; 372 } 373 GetTotalSize()374 double GetTotalSize() const 375 { 376 return totalSize_; 377 } 378 379 private: 380 NO_COPY_SEMANTIC(GetHeapUsageReturns); 381 NO_MOVE_SEMANTIC(GetHeapUsageReturns); 382 383 double usedSize_ {0.0}; 384 double totalSize_ {0.0}; 385 }; 386 387 class GetBestEffortCoverageReturns : public PtBaseReturns { 388 public: GetBestEffortCoverageReturns(std::vector<std::unique_ptr<ScriptCoverage>> result)389 explicit GetBestEffortCoverageReturns(std::vector<std::unique_ptr<ScriptCoverage>> result) 390 : result_(std::move(result)) 391 {} 392 ~GetBestEffortCoverageReturns() override = default; 393 std::unique_ptr<PtJson> ToJson() const override; 394 395 private: 396 GetBestEffortCoverageReturns() = default; 397 NO_COPY_SEMANTIC(GetBestEffortCoverageReturns); 398 NO_MOVE_SEMANTIC(GetBestEffortCoverageReturns); 399 400 std::vector<std::unique_ptr<ScriptCoverage>> result_ {}; 401 }; 402 403 class StartPreciseCoverageReturns : public PtBaseReturns { 404 public: StartPreciseCoverageReturns(int64_t tamp)405 explicit StartPreciseCoverageReturns(int64_t tamp) : timestamp_(tamp) {} 406 ~StartPreciseCoverageReturns() override = default; 407 std::unique_ptr<PtJson> ToJson() const override; 408 409 private: 410 StartPreciseCoverageReturns() = default; 411 NO_COPY_SEMANTIC(StartPreciseCoverageReturns); 412 NO_MOVE_SEMANTIC(StartPreciseCoverageReturns); 413 414 int64_t timestamp_ {0}; 415 }; 416 417 class TakePreciseCoverageReturns : public PtBaseReturns { 418 public: TakePreciseCoverageReturns(std::vector<std::unique_ptr<ScriptCoverage>> result,int64_t tamp)419 explicit TakePreciseCoverageReturns(std::vector<std::unique_ptr<ScriptCoverage>> result, int64_t tamp) 420 : result_(std::move(result)), 421 timestamp_(tamp) 422 {} 423 ~TakePreciseCoverageReturns() override = default; 424 std::unique_ptr<PtJson> ToJson() const override; 425 426 private: 427 TakePreciseCoverageReturns() = default; 428 NO_COPY_SEMANTIC(TakePreciseCoverageReturns); 429 NO_MOVE_SEMANTIC(TakePreciseCoverageReturns); 430 431 std::vector<std::unique_ptr<ScriptCoverage>> result_ {}; 432 int64_t timestamp_ {0}; 433 }; 434 435 class TakeTypeProfileReturns : public PtBaseReturns { 436 public: TakeTypeProfileReturns(std::vector<std::unique_ptr<ScriptTypeProfile>> result)437 explicit TakeTypeProfileReturns(std::vector<std::unique_ptr<ScriptTypeProfile>> result) 438 : result_(std::move(result)) 439 {} 440 ~TakeTypeProfileReturns() override = default; 441 std::unique_ptr<PtJson> ToJson() const override; 442 443 private: 444 TakeTypeProfileReturns() = default; 445 NO_COPY_SEMANTIC(TakeTypeProfileReturns); 446 NO_MOVE_SEMANTIC(TakeTypeProfileReturns); 447 448 std::vector<std::unique_ptr<ScriptTypeProfile>> result_ {}; 449 }; 450 451 class GetCategoriesReturns : public PtBaseReturns { 452 public: GetCategoriesReturns(std::vector<std::string> categories)453 explicit GetCategoriesReturns(std::vector<std::string> categories) 454 : categories_(std::move(categories)) 455 {} 456 ~GetCategoriesReturns() override = default; 457 std::unique_ptr<PtJson> ToJson() const override; 458 459 private: 460 GetCategoriesReturns() = default; 461 NO_COPY_SEMANTIC(GetCategoriesReturns); 462 NO_MOVE_SEMANTIC(GetCategoriesReturns); 463 464 std::vector<std::string> categories_ {}; 465 }; 466 467 class RequestMemoryDumpReturns : public PtBaseReturns { 468 public: RequestMemoryDumpReturns(std::string dumpGuid,bool success)469 explicit RequestMemoryDumpReturns(std::string dumpGuid, bool success) 470 : dumpGuid_(dumpGuid), success_(success) {} 471 ~RequestMemoryDumpReturns() override = default; 472 std::unique_ptr<PtJson> ToJson() const override; 473 474 private: 475 RequestMemoryDumpReturns() = default; 476 NO_COPY_SEMANTIC(RequestMemoryDumpReturns); 477 NO_MOVE_SEMANTIC(RequestMemoryDumpReturns); 478 479 std::string dumpGuid_ {}; 480 bool success_ {}; 481 }; 482 483 class GetNavigationHistoryReturns : public PtBaseReturns { 484 public: 485 GetNavigationHistoryReturns() = default; 486 ~GetNavigationHistoryReturns() override = default; 487 std::unique_ptr<PtJson> ToJson() const override; 488 489 private: 490 NO_COPY_SEMANTIC(GetNavigationHistoryReturns); 491 NO_MOVE_SEMANTIC(GetNavigationHistoryReturns); 492 }; 493 } // namespace panda::ecmascript::tooling 494 #endif