• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #ifndef ECMASCRIPT_TOOLING_BASE_PT_RETURNS_H
17 #define ECMASCRIPT_TOOLING_BASE_PT_RETURNS_H
18 
19 #include "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 GetHeapUsageReturns : public PtBaseReturns {
333 public:
GetHeapUsageReturns(double usedSize,double totalSize)334     explicit GetHeapUsageReturns(double usedSize, double totalSize)
335         : usedSize_(usedSize), totalSize_(totalSize) {}
336     ~GetHeapUsageReturns() override = default;
337     std::unique_ptr<PtJson> ToJson() const override;
338 
339 private:
340     GetHeapUsageReturns() = default;
341     NO_COPY_SEMANTIC(GetHeapUsageReturns);
342     NO_MOVE_SEMANTIC(GetHeapUsageReturns);
343 
344     double usedSize_ {0.0};
345     double totalSize_ {0.0};
346 };
347 
348 class GetBestEffortCoverageReturns : public PtBaseReturns {
349 public:
GetBestEffortCoverageReturns(std::vector<std::unique_ptr<ScriptCoverage>> result)350     explicit GetBestEffortCoverageReturns(std::vector<std::unique_ptr<ScriptCoverage>> result)
351         : result_(std::move(result))
352     {}
353     ~GetBestEffortCoverageReturns() override = default;
354     std::unique_ptr<PtJson> ToJson() const override;
355 
356 private:
357     GetBestEffortCoverageReturns() = default;
358     NO_COPY_SEMANTIC(GetBestEffortCoverageReturns);
359     NO_MOVE_SEMANTIC(GetBestEffortCoverageReturns);
360 
361     std::vector<std::unique_ptr<ScriptCoverage>> result_ {};
362 };
363 
364 class StartPreciseCoverageReturns : public PtBaseReturns {
365 public:
StartPreciseCoverageReturns(int64_t tamp)366     explicit StartPreciseCoverageReturns(int64_t tamp) : timestamp_(tamp) {}
367     ~StartPreciseCoverageReturns() override = default;
368     std::unique_ptr<PtJson> ToJson() const override;
369 
370 private:
371     StartPreciseCoverageReturns() = default;
372     NO_COPY_SEMANTIC(StartPreciseCoverageReturns);
373     NO_MOVE_SEMANTIC(StartPreciseCoverageReturns);
374 
375     int64_t timestamp_ {0};
376 };
377 
378 class TakePreciseCoverageReturns : public PtBaseReturns {
379 public:
TakePreciseCoverageReturns(std::vector<std::unique_ptr<ScriptCoverage>> result,int64_t tamp)380     explicit TakePreciseCoverageReturns(std::vector<std::unique_ptr<ScriptCoverage>> result, int64_t tamp)
381         : result_(std::move(result)),
382           timestamp_(tamp)
383     {}
384     ~TakePreciseCoverageReturns() override = default;
385     std::unique_ptr<PtJson> ToJson() const override;
386 
387 private:
388     TakePreciseCoverageReturns() = default;
389     NO_COPY_SEMANTIC(TakePreciseCoverageReturns);
390     NO_MOVE_SEMANTIC(TakePreciseCoverageReturns);
391 
392     std::vector<std::unique_ptr<ScriptCoverage>> result_ {};
393     int64_t timestamp_ {0};
394 };
395 
396 class TakeTypeProfileReturns : public PtBaseReturns {
397 public:
TakeTypeProfileReturns(std::vector<std::unique_ptr<ScriptTypeProfile>> result)398     explicit TakeTypeProfileReturns(std::vector<std::unique_ptr<ScriptTypeProfile>> result)
399         : result_(std::move(result))
400     {}
401     ~TakeTypeProfileReturns() override = default;
402     std::unique_ptr<PtJson> ToJson() const override;
403 
404 private:
405     TakeTypeProfileReturns() = default;
406     NO_COPY_SEMANTIC(TakeTypeProfileReturns);
407     NO_MOVE_SEMANTIC(TakeTypeProfileReturns);
408 
409     std::vector<std::unique_ptr<ScriptTypeProfile>> result_ {};
410 };
411 
412 class GetCategoriesReturns : public PtBaseReturns {
413 public:
GetCategoriesReturns(std::vector<std::string> categories)414     explicit GetCategoriesReturns(std::vector<std::string> categories)
415         : categories_(std::move(categories))
416     {}
417     ~GetCategoriesReturns() override = default;
418     std::unique_ptr<PtJson> ToJson() const override;
419 
420 private:
421     GetCategoriesReturns() = default;
422     NO_COPY_SEMANTIC(GetCategoriesReturns);
423     NO_MOVE_SEMANTIC(GetCategoriesReturns);
424 
425     std::vector<std::string> categories_ {};
426 };
427 
428 class RequestMemoryDumpReturns : public PtBaseReturns {
429 public:
RequestMemoryDumpReturns(std::string dumpGuid,bool success)430     explicit RequestMemoryDumpReturns(std::string dumpGuid, bool success)
431         : dumpGuid_(dumpGuid), success_(success) {}
432     ~RequestMemoryDumpReturns() override = default;
433     std::unique_ptr<PtJson> ToJson() const override;
434 
435 private:
436     RequestMemoryDumpReturns() = default;
437     NO_COPY_SEMANTIC(RequestMemoryDumpReturns);
438     NO_MOVE_SEMANTIC(RequestMemoryDumpReturns);
439 
440     std::string dumpGuid_ {};
441     bool success_ {};
442 };
443 }  // namespace panda::ecmascript::tooling
444 #endif