• 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 #include "base/pt_events.h"
17 
18 namespace panda::ecmascript::tooling {
ToJson() const19 std::unique_ptr<PtJson> BreakpointResolved::ToJson() const
20 {
21     std::unique_ptr<PtJson> result = PtJson::CreateObject();
22     result->Add("breakpointId", breakpointId_.c_str());
23     ASSERT(location_ != nullptr);
24     result->Add("location", location_->ToJson());
25 
26     std::unique_ptr<PtJson> object = PtJson::CreateObject();
27     object->Add("method", GetName().c_str());
28     object->Add("params", result);
29 
30     return object;
31 }
32 
ToJson() const33 std::unique_ptr<PtJson> Paused::ToJson() const
34 {
35     std::unique_ptr<PtJson> result = PtJson::CreateObject();
36 
37     std::unique_ptr<PtJson> array = PtJson::CreateArray();
38     size_t len = callFrames_.size();
39     for (size_t i = 0; i < len; i++) {
40         ASSERT(callFrames_[i] != nullptr);
41         array->Push(callFrames_[i]->ToJson());
42     }
43     result->Add("callFrames", array);
44     result->Add("reason", reason_.c_str());
45     if (data_) {
46         ASSERT(data_.value() != nullptr);
47         result->Add("data", data_.value()->ToJson());
48     }
49     if (hitBreakpoints_) {
50         std::unique_ptr<PtJson> breakpoints = PtJson::CreateArray();
51         len = hitBreakpoints_->size();
52         for (size_t i = 0; i < len; i++) {
53             breakpoints->Push(hitBreakpoints_.value()[i].c_str());
54         }
55         result->Add("hitBreakpoints", breakpoints);
56     }
57 
58     std::unique_ptr<PtJson> object = PtJson::CreateObject();
59     object->Add("method", GetName().c_str());
60     object->Add("params", result);
61 
62     return object;
63 }
64 
ToJson() const65 std::unique_ptr<PtJson> Resumed::ToJson() const
66 {
67     std::unique_ptr<PtJson> result = PtJson::CreateObject();
68 
69     std::unique_ptr<PtJson> object = PtJson::CreateObject();
70     object->Add("method", GetName().c_str());
71     object->Add("params", result);
72 
73     return object;
74 }
75 
ToJson() const76 std::unique_ptr<PtJson> NativeCalling::ToJson() const
77 {
78     std::unique_ptr<PtJson> result = PtJson::CreateObject();
79 
80     std::unique_ptr<PtJson> object = PtJson::CreateObject();
81     result->Add("nativeAddress", reinterpret_cast<int64_t>(GetNativeAddress()));
82     object->Add("method", GetName().c_str());
83     object->Add("params", result);
84 
85     return object;
86 }
87 
ToJson() const88 std::unique_ptr<PtJson> ScriptFailedToParse::ToJson() const
89 {
90     std::unique_ptr<PtJson> result = PtJson::CreateObject();
91 
92     result->Add("scriptId", std::to_string(scriptId_).c_str());
93     result->Add("url", url_.c_str());
94     result->Add("startLine", startLine_);
95     result->Add("startColumn", startColumn_);
96     result->Add("endLine", endLine_);
97     result->Add("endColumn", endColumn_);
98     result->Add("executionContextId", executionContextId_);
99     result->Add("hash", hash_.c_str());
100     if (sourceMapUrl_) {
101         result->Add("sourceMapURL", sourceMapUrl_->c_str());
102     }
103     if (hasSourceUrl_) {
104         result->Add("hasSourceURL", hasSourceUrl_.value());
105     }
106     if (isModule_) {
107         result->Add("isModule", isModule_.value());
108     }
109     if (length_) {
110         result->Add("length", length_.value());
111     }
112     if (codeOffset_) {
113         result->Add("codeOffset", codeOffset_.value());
114     }
115     if (scriptLanguage_) {
116         result->Add("scriptLanguage", scriptLanguage_->c_str());
117     }
118     if (embedderName_) {
119         result->Add("embedderName", embedderName_->c_str());
120     }
121 
122     std::unique_ptr<PtJson> object = PtJson::CreateObject();
123     object->Add("method", GetName().c_str());
124     object->Add("params", result);
125 
126     return object;
127 }
128 
ToJson() const129 std::unique_ptr<PtJson> ScriptParsed::ToJson() const
130 {
131     std::unique_ptr<PtJson> result = PtJson::CreateObject();
132 
133     result->Add("scriptId", std::to_string(scriptId_).c_str());
134     result->Add("url", url_.c_str());
135     result->Add("startLine", startLine_);
136     result->Add("startColumn", startColumn_);
137     result->Add("endLine", endLine_);
138     result->Add("endColumn", endColumn_);
139     result->Add("executionContextId", executionContextId_);
140     result->Add("hash", hash_.c_str());
141     if (isLiveEdit_) {
142         result->Add("isLiveEdit", isLiveEdit_.value());
143     }
144     if (sourceMapUrl_) {
145         result->Add("sourceMapURL", sourceMapUrl_->c_str());
146     }
147     if (hasSourceUrl_) {
148         result->Add("hasSourceURL", hasSourceUrl_.value());
149     }
150     if (isModule_) {
151         result->Add("isModule", isModule_.value());
152     }
153     if (length_) {
154         result->Add("length", length_.value());
155     }
156     if (codeOffset_) {
157         result->Add("codeOffset", codeOffset_.value());
158     }
159     if (scriptLanguage_) {
160         result->Add("scriptLanguage", scriptLanguage_->c_str());
161     }
162     if (embedderName_) {
163         result->Add("embedderName", embedderName_->c_str());
164     }
165 
166     std::unique_ptr<PtJson> object = PtJson::CreateObject();
167     object->Add("method", GetName().c_str());
168     object->Add("params", result);
169 
170     return object;
171 }
172 
ToJson() const173 std::unique_ptr<PtJson> AddHeapSnapshotChunk::ToJson() const
174 {
175     std::unique_ptr<PtJson> result = PtJson::CreateObject();
176 
177     result->Add("chunk", chunk_.c_str());
178 
179     std::unique_ptr<PtJson> object = PtJson::CreateObject();
180     object->Add("method", GetName().c_str());
181     object->Add("params", result);
182 
183     return object;
184 }
185 
ToJson() const186 std::unique_ptr<PtJson> ConsoleProfileFinished::ToJson() const
187 {
188     std::unique_ptr<PtJson> result = PtJson::CreateObject();
189 
190     result->Add("id", id_.c_str());
191     ASSERT(location_ != nullptr);
192     result->Add("location", location_->ToJson());
193     ASSERT(profile_ != nullptr);
194     result->Add("profile", profile_->ToJson());
195     if (title_) {
196         result->Add("title", title_->c_str());
197     }
198 
199     std::unique_ptr<PtJson> object = PtJson::CreateObject();
200     object->Add("method", GetName().c_str());
201     object->Add("params", result);
202 
203     return object;
204 }
205 
ToJson() const206 std::unique_ptr<PtJson> ConsoleProfileStarted::ToJson() const
207 {
208     std::unique_ptr<PtJson> result = PtJson::CreateObject();
209 
210     result->Add("id", id_.c_str());
211     ASSERT(location_ != nullptr);
212     result->Add("location", location_->ToJson());
213     if (title_) {
214         result->Add("title", title_->c_str());
215     }
216 
217     std::unique_ptr<PtJson> object = PtJson::CreateObject();
218     object->Add("method", GetName().c_str());
219     object->Add("params", result);
220 
221     return object;
222 }
223 
ToJson() const224 std::unique_ptr<PtJson> PreciseCoverageDeltaUpdate::ToJson() const
225 {
226     std::unique_ptr<PtJson> result = PtJson::CreateObject();
227 
228     result->Add("timestamp", timestamp_);
229     result->Add("occasion", occasion_.c_str());
230     std::unique_ptr<PtJson> array = PtJson::CreateArray();
231     size_t len = result_.size();
232     for (size_t i = 0; i < len; i++) {
233         ASSERT(result_[i] != nullptr);
234         std::unique_ptr<PtJson> res = result_[i]->ToJson();
235         array->Push(res);
236     }
237     result->Add("result", array);
238 
239     std::unique_ptr<PtJson> object = PtJson::CreateObject();
240     object->Add("method", GetName().c_str());
241     object->Add("params", result);
242 
243     return object;
244 }
245 
ToJson() const246 std::unique_ptr<PtJson> HeapStatsUpdate::ToJson() const
247 {
248     std::unique_ptr<PtJson> result = PtJson::CreateObject();
249 
250     std::unique_ptr<PtJson> array = PtJson::CreateArray();
251     size_t len = statsUpdate_.size();
252     for (size_t i = 0; i < len; i++) {
253         array->Push(statsUpdate_[i]);
254     }
255     result->Add("statsUpdate", array);
256 
257     std::unique_ptr<PtJson> object = PtJson::CreateObject();
258     object->Add("method", GetName().c_str());
259     object->Add("params", result);
260 
261     return object;
262 }
263 
ToJson() const264 std::unique_ptr<PtJson> LastSeenObjectId::ToJson() const
265 {
266     std::unique_ptr<PtJson> result = PtJson::CreateObject();
267 
268     result->Add("lastSeenObjectId", lastSeenObjectId_);
269     result->Add("timestamp", timestamp_);
270 
271     std::unique_ptr<PtJson> object = PtJson::CreateObject();
272     object->Add("method", GetName().c_str());
273     object->Add("params", result);
274 
275     return object;
276 }
277 
ToJson() const278 std::unique_ptr<PtJson> ReportHeapSnapshotProgress::ToJson() const
279 {
280     std::unique_ptr<PtJson> result = PtJson::CreateObject();
281 
282     result->Add("done", done_);
283     result->Add("total", total_);
284     if (finished_) {
285         result->Add("finished", finished_.value());
286     }
287 
288     std::unique_ptr<PtJson> object = PtJson::CreateObject();
289     object->Add("method", GetName().c_str());
290     object->Add("params", result);
291 
292     return object;
293 }
294 
ToJson() const295 std::unique_ptr<PtJson> BufferUsage::ToJson() const
296 {
297     std::unique_ptr<PtJson> result = PtJson::CreateObject();
298 
299     if (percentFull_) {
300         result->Add("percentFull", percentFull_.value());
301     }
302     if (eventCount_) {
303         result->Add("eventCount", eventCount_.value());
304     }
305     if (value_) {
306         result->Add("value", value_.value());
307     }
308 
309     std::unique_ptr<PtJson> object = PtJson::CreateObject();
310     object->Add("method", GetName().c_str());
311     object->Add("params", result);
312 
313     return object;
314 }
315 
ToJson() const316 std::unique_ptr<PtJson> DataCollected::ToJson() const
317 {
318     std::unique_ptr<PtJson> result = PtJson::CreateObject();
319 
320     std::unique_ptr<PtJson> array = PtJson::CreateArray();
321     size_t len = value_.size();
322     for (size_t i = 0; i < len; i++) {
323         array->Push(value_[i]);
324     }
325     result->Add("value", array);
326 
327     std::unique_ptr<PtJson> object = PtJson::CreateObject();
328     object->Add("method", GetName().c_str());
329     object->Add("params", result);
330 
331     return object;
332 }
333 
ToJson() const334 std::unique_ptr<PtJson> TracingComplete::ToJson() const
335 {
336     std::unique_ptr<PtJson> result = PtJson::CreateObject();
337 
338     result->Add("dataLossOccurred", dataLossOccurred_);
339     if (traceFormat_) {
340         result->Add("traceFormat", traceFormat_.value()->c_str());
341     }
342     if (streamCompression_) {
343         result->Add("streamCompression", streamCompression_.value()->c_str());
344     }
345 
346     std::unique_ptr<PtJson> object = PtJson::CreateObject();
347     object->Add("method", GetName().c_str());
348     object->Add("params", result);
349 
350     return object;
351 }
352 }  // namespace panda::ecmascript::tooling
353