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 "ecmascript/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 EvaluateOnCallFrameReturns : public PtBaseReturns { 70 public: 71 explicit EvaluateOnCallFrameReturns(std::unique_ptr<RemoteObject> result, 72 std::optional<std::unique_ptr<ExceptionDetails>> exceptionDetails = std::nullopt) result_(std::move (result))73 : result_(std::move(result)), exceptionDetails_(std::move(exceptionDetails)) 74 {} 75 ~EvaluateOnCallFrameReturns() override = default; 76 std::unique_ptr<PtJson> ToJson() const override; 77 78 private: 79 EvaluateOnCallFrameReturns() = default; 80 NO_COPY_SEMANTIC(EvaluateOnCallFrameReturns); 81 NO_MOVE_SEMANTIC(EvaluateOnCallFrameReturns); 82 83 std::unique_ptr<RemoteObject> result_ {}; 84 std::optional<std::unique_ptr<ExceptionDetails>> exceptionDetails_ {}; 85 }; 86 87 class GetPossibleBreakpointsReturns : public PtBaseReturns { 88 public: GetPossibleBreakpointsReturns(std::vector<std::unique_ptr<BreakLocation>> locations)89 explicit GetPossibleBreakpointsReturns(std::vector<std::unique_ptr<BreakLocation>> locations) 90 : locations_(std::move(locations)) 91 {} 92 ~GetPossibleBreakpointsReturns() override = default; 93 94 std::unique_ptr<PtJson> ToJson() const override; 95 96 private: 97 GetPossibleBreakpointsReturns() = default; 98 NO_COPY_SEMANTIC(GetPossibleBreakpointsReturns); 99 NO_MOVE_SEMANTIC(GetPossibleBreakpointsReturns); 100 101 std::vector<std::unique_ptr<BreakLocation>> locations_ {}; 102 }; 103 104 class GetScriptSourceReturns : public PtBaseReturns { 105 public: 106 explicit GetScriptSourceReturns(const std::string &scriptSource, std::optional<std::string> bytecode = std::nullopt) scriptSource_(scriptSource)107 : scriptSource_(scriptSource), bytecode_(std::move(bytecode)) 108 {} 109 ~GetScriptSourceReturns() override = default; 110 111 std::unique_ptr<PtJson> ToJson() const override; 112 113 private: 114 GetScriptSourceReturns() = default; 115 NO_COPY_SEMANTIC(GetScriptSourceReturns); 116 NO_MOVE_SEMANTIC(GetScriptSourceReturns); 117 118 std::string scriptSource_ {}; 119 std::optional<std::string> bytecode_ {}; 120 }; 121 122 class RestartFrameReturns : public PtBaseReturns { 123 public: RestartFrameReturns(std::vector<std::unique_ptr<CallFrame>> callFrames)124 explicit RestartFrameReturns(std::vector<std::unique_ptr<CallFrame>> callFrames) 125 : callFrames_(std::move(callFrames)) 126 {} 127 ~RestartFrameReturns() override = default; 128 std::unique_ptr<PtJson> ToJson() const override; 129 130 private: 131 RestartFrameReturns() = default; 132 NO_COPY_SEMANTIC(RestartFrameReturns); 133 NO_MOVE_SEMANTIC(RestartFrameReturns); 134 135 std::vector<std::unique_ptr<CallFrame>> callFrames_ {}; 136 }; 137 138 class SearchInContentReturns : public PtBaseReturns { 139 public: SearchInContentReturns(std::vector<std::unique_ptr<SearchMatch>> result)140 explicit SearchInContentReturns(std::vector<std::unique_ptr<SearchMatch>> result) : result_(std::move(result)) 141 {} 142 ~SearchInContentReturns() override = default; 143 std::unique_ptr<PtJson> ToJson() const override; 144 145 private: 146 SearchInContentReturns() = default; 147 NO_COPY_SEMANTIC(SearchInContentReturns); 148 NO_MOVE_SEMANTIC(SearchInContentReturns); 149 150 std::vector<std::unique_ptr<SearchMatch>> result_ {}; 151 }; 152 153 class SetBreakpointReturns : public PtBaseReturns { 154 public: SetBreakpointReturns(const std::string & id,std::unique_ptr<Location> location)155 explicit SetBreakpointReturns(const std::string &id, std::unique_ptr<Location> location) 156 : breakpointId_(id), location_(std::move(location)) 157 {} 158 ~SetBreakpointReturns() override = default; 159 std::unique_ptr<PtJson> ToJson() const override; 160 161 private: 162 SetBreakpointReturns() = default; 163 NO_COPY_SEMANTIC(SetBreakpointReturns); 164 NO_MOVE_SEMANTIC(SetBreakpointReturns); 165 std::string breakpointId_ {}; 166 std::unique_ptr<Location> location_ {}; 167 }; 168 169 class SetInstrumentationBreakpointReturns : public PtBaseReturns { 170 public: SetInstrumentationBreakpointReturns(const std::string & id)171 explicit SetInstrumentationBreakpointReturns(const std::string &id) : breakpointId_(id) 172 {} 173 ~SetInstrumentationBreakpointReturns() override = default; 174 std::unique_ptr<PtJson> ToJson() const override; 175 176 private: 177 SetInstrumentationBreakpointReturns() = default; 178 NO_COPY_SEMANTIC(SetInstrumentationBreakpointReturns); 179 NO_MOVE_SEMANTIC(SetInstrumentationBreakpointReturns); 180 181 std::string breakpointId_ {}; 182 }; 183 184 class SetScriptSourceReturns : public PtBaseReturns { 185 public: 186 explicit SetScriptSourceReturns(std::optional<std::vector<std::unique_ptr<CallFrame>>> callFrames = std::nullopt, 187 std::optional<bool> stackChanged = std::nullopt, 188 std::optional<std::unique_ptr<ExceptionDetails>> exceptionDetails = std::nullopt) callFrames_(std::move (callFrames))189 : callFrames_(std::move(callFrames)), 190 stackChanged_(stackChanged), 191 exceptionDetails_(std::move(exceptionDetails)) 192 {} 193 ~SetScriptSourceReturns() override = default; 194 std::unique_ptr<PtJson> ToJson() const override; 195 196 private: 197 SetScriptSourceReturns() = default; 198 NO_COPY_SEMANTIC(SetScriptSourceReturns); 199 NO_MOVE_SEMANTIC(SetScriptSourceReturns); 200 201 std::optional<std::vector<std::unique_ptr<CallFrame>>> callFrames_ {}; 202 std::optional<bool> stackChanged_ {}; 203 std::optional<std::unique_ptr<ExceptionDetails>> exceptionDetails_ {}; 204 }; 205 206 class GetPropertiesReturns : public PtBaseReturns { 207 public: 208 explicit GetPropertiesReturns(std::vector<std::unique_ptr<PropertyDescriptor>> descriptor, 209 std::optional<std::vector<std::unique_ptr<InternalPropertyDescriptor>>> internalDescripties = std::nullopt, 210 std::optional<std::vector<std::unique_ptr<PrivatePropertyDescriptor>>> privateProperties = std::nullopt, 211 std::optional<std::unique_ptr<ExceptionDetails>> exceptionDetails = std::nullopt) result_(std::move (descriptor))212 : result_(std::move(descriptor)), 213 internalPropertyDescripties_(std::move(internalDescripties)), 214 privateProperties_(std::move(privateProperties)), 215 exceptionDetails_(std::move(exceptionDetails)) 216 {} 217 ~GetPropertiesReturns() override = default; 218 std::unique_ptr<PtJson> ToJson() const override; 219 220 private: 221 GetPropertiesReturns() = default; 222 NO_COPY_SEMANTIC(GetPropertiesReturns); 223 NO_MOVE_SEMANTIC(GetPropertiesReturns); 224 225 std::vector<std::unique_ptr<PropertyDescriptor>> result_ {}; 226 std::optional<std::vector<std::unique_ptr<InternalPropertyDescriptor>>> internalPropertyDescripties_ {}; 227 std::optional<std::vector<std::unique_ptr<PrivatePropertyDescriptor>>> privateProperties_ {}; 228 std::optional<std::unique_ptr<ExceptionDetails>> exceptionDetails_ {}; 229 }; 230 231 class CallFunctionOnReturns : public PtBaseReturns { 232 public: 233 explicit CallFunctionOnReturns(std::unique_ptr<RemoteObject> result, 234 std::optional<std::unique_ptr<ExceptionDetails>> exceptionDetails = std::nullopt) result_(std::move (result))235 : result_(std::move(result)), 236 exceptionDetails_(std::move(exceptionDetails)) 237 {} 238 ~CallFunctionOnReturns() override = default; 239 std::unique_ptr<PtJson> ToJson() const override; 240 241 private: 242 CallFunctionOnReturns() = default; 243 NO_COPY_SEMANTIC(CallFunctionOnReturns); 244 NO_MOVE_SEMANTIC(CallFunctionOnReturns); 245 246 std::unique_ptr<RemoteObject> result_ {}; 247 std::optional<std::unique_ptr<ExceptionDetails>> exceptionDetails_ {}; 248 }; 249 250 class GetHeapUsageReturns : public PtBaseReturns { 251 public: GetHeapUsageReturns(double usedSize,double totalSize)252 explicit GetHeapUsageReturns(double usedSize, double totalSize) 253 : usedSize_(usedSize), totalSize_(totalSize) {} 254 ~GetHeapUsageReturns() override = default; 255 std::unique_ptr<PtJson> ToJson() const override; 256 257 private: 258 GetHeapUsageReturns() = default; 259 NO_COPY_SEMANTIC(GetHeapUsageReturns); 260 NO_MOVE_SEMANTIC(GetHeapUsageReturns); 261 262 double usedSize_ {0.0}; 263 double totalSize_ {0.0}; 264 }; 265 266 #ifdef SUPPORT_PROFILER_CDP 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 GetBestEffortCoverageReturns : public PtBaseReturns { 333 public: GetBestEffortCoverageReturns(std::vector<std::unique_ptr<ScriptCoverage>> result)334 explicit GetBestEffortCoverageReturns(std::vector<std::unique_ptr<ScriptCoverage>> result) 335 : result_(std::move(result)) 336 {} 337 ~GetBestEffortCoverageReturns() override = default; 338 std::unique_ptr<PtJson> ToJson() const override; 339 340 private: 341 GetBestEffortCoverageReturns() = default; 342 NO_COPY_SEMANTIC(GetBestEffortCoverageReturns); 343 NO_MOVE_SEMANTIC(GetBestEffortCoverageReturns); 344 345 std::vector<std::unique_ptr<ScriptCoverage>> result_ {}; 346 }; 347 348 class StartPreciseCoverageReturns : public PtBaseReturns { 349 public: StartPreciseCoverageReturns(int64_t tamp)350 explicit StartPreciseCoverageReturns(int64_t tamp) : timestamp_(tamp) {} 351 ~StartPreciseCoverageReturns() override = default; 352 std::unique_ptr<PtJson> ToJson() const override; 353 354 private: 355 StartPreciseCoverageReturns() = default; 356 NO_COPY_SEMANTIC(StartPreciseCoverageReturns); 357 NO_MOVE_SEMANTIC(StartPreciseCoverageReturns); 358 359 int64_t timestamp_ {0}; 360 }; 361 362 class TakePreciseCoverageReturns : public PtBaseReturns { 363 public: TakePreciseCoverageReturns(std::vector<std::unique_ptr<ScriptCoverage>> result,int64_t tamp)364 explicit TakePreciseCoverageReturns(std::vector<std::unique_ptr<ScriptCoverage>> result, int64_t tamp) 365 : result_(std::move(result)), 366 timestamp_(tamp) 367 {} 368 ~TakePreciseCoverageReturns() override = default; 369 std::unique_ptr<PtJson> ToJson() const override; 370 371 private: 372 TakePreciseCoverageReturns() = default; 373 NO_COPY_SEMANTIC(TakePreciseCoverageReturns); 374 NO_MOVE_SEMANTIC(TakePreciseCoverageReturns); 375 376 std::vector<std::unique_ptr<ScriptCoverage>> result_ {}; 377 int64_t timestamp_ {0}; 378 }; 379 380 class TakeTypeProfileReturns : public PtBaseReturns { 381 public: TakeTypeProfileReturns(std::vector<std::unique_ptr<ScriptTypeProfile>> result)382 explicit TakeTypeProfileReturns(std::vector<std::unique_ptr<ScriptTypeProfile>> result) 383 : result_(std::move(result)) 384 {} 385 ~TakeTypeProfileReturns() override = default; 386 std::unique_ptr<PtJson> ToJson() const override; 387 388 private: 389 TakeTypeProfileReturns() = default; 390 NO_COPY_SEMANTIC(TakeTypeProfileReturns); 391 NO_MOVE_SEMANTIC(TakeTypeProfileReturns); 392 393 std::vector<std::unique_ptr<ScriptTypeProfile>> result_ {}; 394 }; 395 #endif 396 } // namespace panda::ecmascript::tooling 397 #endif