• 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     result->Add("nativeAddress", reinterpret_cast<int64_t>(GetNativeAddress()));
81     result->Add("isStepInto", GetIntoStatus());
82     std::unique_ptr<PtJson> nativePointerArray = PtJson::CreateArray();
83     size_t nativePointerLength = nativePointer_.size();
84     for (size_t i = 0; i < nativePointerLength; ++i) {
85         nativePointerArray->Push(reinterpret_cast<int64_t>(nativePointer_[i]));
86     }
87     result->Add("nativePointer", nativePointerArray);
88 
89     std::unique_ptr<PtJson> callFrameArray = PtJson::CreateArray();
90     size_t callFrameLength = callFrames_.size();
91     for (size_t i = 0; i < callFrameLength; ++i) {
92         ASSERT(callFrames_[i] != nullptr);
93         callFrameArray->Push(callFrames_[i]->ToJson());
94     }
95     result->Add("callFrames", callFrameArray);
96 
97     std::unique_ptr<PtJson> object = PtJson::CreateObject();
98     object->Add("method", GetName().c_str());
99     object->Add("params", result);
100 
101     return object;
102 }
103 
ToJson() const104 std::unique_ptr<PtJson> ScriptFailedToParse::ToJson() const
105 {
106     std::unique_ptr<PtJson> result = PtJson::CreateObject();
107 
108     result->Add("scriptId", std::to_string(scriptId_).c_str());
109     result->Add("url", url_.c_str());
110     result->Add("startLine", startLine_);
111     result->Add("startColumn", startColumn_);
112     result->Add("endLine", endLine_);
113     result->Add("endColumn", endColumn_);
114     result->Add("executionContextId", executionContextId_);
115     result->Add("hash", hash_.c_str());
116     if (sourceMapUrl_) {
117         result->Add("sourceMapURL", sourceMapUrl_->c_str());
118     }
119     if (hasSourceUrl_) {
120         result->Add("hasSourceURL", hasSourceUrl_.value());
121     }
122     if (isModule_) {
123         result->Add("isModule", isModule_.value());
124     }
125     if (length_) {
126         result->Add("length", length_.value());
127     }
128     if (codeOffset_) {
129         result->Add("codeOffset", codeOffset_.value());
130     }
131     if (scriptLanguage_) {
132         result->Add("scriptLanguage", scriptLanguage_->c_str());
133     }
134     if (embedderName_) {
135         result->Add("embedderName", embedderName_->c_str());
136     }
137 
138     std::unique_ptr<PtJson> object = PtJson::CreateObject();
139     object->Add("method", GetName().c_str());
140     object->Add("params", result);
141 
142     return object;
143 }
144 
ToJson() const145 std::unique_ptr<PtJson> ScriptParsed::ToJson() const
146 {
147     std::unique_ptr<PtJson> result = PtJson::CreateObject();
148 
149     result->Add("scriptId", std::to_string(scriptId_).c_str());
150     result->Add("url", url_.c_str());
151     result->Add("startLine", startLine_);
152     result->Add("startColumn", startColumn_);
153     result->Add("endLine", endLine_);
154     result->Add("endColumn", endColumn_);
155     result->Add("executionContextId", executionContextId_);
156     result->Add("hash", hash_.c_str());
157     if (isLiveEdit_) {
158         result->Add("isLiveEdit", isLiveEdit_.value());
159     }
160     if (sourceMapUrl_) {
161         result->Add("sourceMapURL", sourceMapUrl_->c_str());
162     }
163     if (hasSourceUrl_) {
164         result->Add("hasSourceURL", hasSourceUrl_.value());
165     }
166     if (isModule_) {
167         result->Add("isModule", isModule_.value());
168     }
169     if (length_) {
170         result->Add("length", length_.value());
171     }
172     if (codeOffset_) {
173         result->Add("codeOffset", codeOffset_.value());
174     }
175     if (scriptLanguage_) {
176         result->Add("scriptLanguage", scriptLanguage_->c_str());
177     }
178     if (embedderName_) {
179         result->Add("embedderName", embedderName_->c_str());
180     }
181 
182     std::unique_ptr<PtJson> object = PtJson::CreateObject();
183     object->Add("method", GetName().c_str());
184     object->Add("params", result);
185 
186     return object;
187 }
188 
ToJson() const189 std::unique_ptr<PtJson> AddHeapSnapshotChunk::ToJson() const
190 {
191     std::unique_ptr<PtJson> result = PtJson::CreateObject();
192 
193     result->Add("chunk", chunk_.c_str());
194 
195     std::unique_ptr<PtJson> object = PtJson::CreateObject();
196     object->Add("method", GetName().c_str());
197     object->Add("params", result);
198 
199     return object;
200 }
201 
ToJson() const202 std::unique_ptr<PtJson> ConsoleProfileFinished::ToJson() const
203 {
204     std::unique_ptr<PtJson> result = PtJson::CreateObject();
205 
206     result->Add("id", id_.c_str());
207     ASSERT(location_ != nullptr);
208     result->Add("location", location_->ToJson());
209     ASSERT(profile_ != nullptr);
210     result->Add("profile", profile_->ToJson());
211     if (title_) {
212         result->Add("title", title_->c_str());
213     }
214 
215     std::unique_ptr<PtJson> object = PtJson::CreateObject();
216     object->Add("method", GetName().c_str());
217     object->Add("params", result);
218 
219     return object;
220 }
221 
ToJson() const222 std::unique_ptr<PtJson> ConsoleProfileStarted::ToJson() const
223 {
224     std::unique_ptr<PtJson> result = PtJson::CreateObject();
225 
226     result->Add("id", id_.c_str());
227     ASSERT(location_ != nullptr);
228     result->Add("location", location_->ToJson());
229     if (title_) {
230         result->Add("title", title_->c_str());
231     }
232 
233     std::unique_ptr<PtJson> object = PtJson::CreateObject();
234     object->Add("method", GetName().c_str());
235     object->Add("params", result);
236 
237     return object;
238 }
239 
ToJson() const240 std::unique_ptr<PtJson> PreciseCoverageDeltaUpdate::ToJson() const
241 {
242     std::unique_ptr<PtJson> result = PtJson::CreateObject();
243 
244     result->Add("timestamp", timestamp_);
245     result->Add("occasion", occasion_.c_str());
246     std::unique_ptr<PtJson> array = PtJson::CreateArray();
247     size_t len = result_.size();
248     for (size_t i = 0; i < len; i++) {
249         ASSERT(result_[i] != nullptr);
250         std::unique_ptr<PtJson> res = result_[i]->ToJson();
251         array->Push(res);
252     }
253     result->Add("result", array);
254 
255     std::unique_ptr<PtJson> object = PtJson::CreateObject();
256     object->Add("method", GetName().c_str());
257     object->Add("params", result);
258 
259     return object;
260 }
261 
ToJson() const262 std::unique_ptr<PtJson> HeapStatsUpdate::ToJson() const
263 {
264     std::unique_ptr<PtJson> result = PtJson::CreateObject();
265 
266     std::unique_ptr<PtJson> array = PtJson::CreateArray();
267     size_t len = statsUpdate_.size();
268     for (size_t i = 0; i < len; i++) {
269         array->Push(statsUpdate_[i]);
270     }
271     result->Add("statsUpdate", array);
272 
273     std::unique_ptr<PtJson> object = PtJson::CreateObject();
274     object->Add("method", GetName().c_str());
275     object->Add("params", result);
276 
277     return object;
278 }
279 
ToJson() const280 std::unique_ptr<PtJson> LastSeenObjectId::ToJson() const
281 {
282     std::unique_ptr<PtJson> result = PtJson::CreateObject();
283 
284     result->Add("lastSeenObjectId", lastSeenObjectId_);
285     result->Add("timestamp", timestamp_);
286 
287     std::unique_ptr<PtJson> object = PtJson::CreateObject();
288     object->Add("method", GetName().c_str());
289     object->Add("params", result);
290 
291     return object;
292 }
293 
ToJson() const294 std::unique_ptr<PtJson> ReportHeapSnapshotProgress::ToJson() const
295 {
296     std::unique_ptr<PtJson> result = PtJson::CreateObject();
297 
298     result->Add("done", done_);
299     result->Add("total", total_);
300     if (finished_) {
301         result->Add("finished", finished_.value());
302     }
303 
304     std::unique_ptr<PtJson> object = PtJson::CreateObject();
305     object->Add("method", GetName().c_str());
306     object->Add("params", result);
307 
308     return object;
309 }
310 
ToJson() const311 std::unique_ptr<PtJson> BufferUsage::ToJson() const
312 {
313     std::unique_ptr<PtJson> result = PtJson::CreateObject();
314 
315     if (percentFull_) {
316         result->Add("percentFull", percentFull_.value());
317     }
318     if (eventCount_) {
319         result->Add("eventCount", eventCount_.value());
320     }
321     if (value_) {
322         result->Add("value", value_.value());
323     }
324 
325     std::unique_ptr<PtJson> object = PtJson::CreateObject();
326     object->Add("method", GetName().c_str());
327     object->Add("params", result);
328 
329     return object;
330 }
331 
ToJson() const332 std::unique_ptr<PtJson> DataCollected::ToJson() const
333 {
334     std::unique_ptr<PtJson> result = PtJson::CreateObject();
335 
336     std::unique_ptr<PtJson> array = PtJson::CreateArray();
337     size_t len = value_.size();
338     for (size_t i = 0; i < len; i++) {
339         array->Push(value_[i]);
340     }
341     result->Add("value", array);
342 
343     std::unique_ptr<PtJson> object = PtJson::CreateObject();
344     object->Add("method", GetName().c_str());
345     object->Add("params", result);
346 
347     return object;
348 }
349 
ToJson() const350 std::unique_ptr<PtJson> TracingComplete::ToJson() const
351 {
352     std::unique_ptr<PtJson> result = PtJson::CreateObject();
353 
354     result->Add("dataLossOccurred", dataLossOccurred_);
355     if (traceFormat_) {
356         result->Add("traceFormat", traceFormat_.value()->c_str());
357     }
358     if (streamCompression_) {
359         result->Add("streamCompression", streamCompression_.value()->c_str());
360     }
361 
362     std::unique_ptr<PtJson> object = PtJson::CreateObject();
363     object->Add("method", GetName().c_str());
364     object->Add("params", result);
365 
366     return object;
367 }
368 }  // namespace panda::ecmascript::tooling
369