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