Line data Source code
1 : // This file is generated by TypeBuilder_cpp.template.
2 :
3 : // Copyright (c) 2016 The Chromium Authors. All rights reserved.
4 : // Use of this source code is governed by a BSD-style license that can be
5 : // found in the LICENSE file.
6 :
7 : #include "src/inspector/protocol/Profiler.h"
8 :
9 : #include "src/inspector/protocol/Protocol.h"
10 :
11 : namespace v8_inspector {
12 : namespace protocol {
13 : namespace Profiler {
14 :
15 : // ------------- Enum values from types.
16 :
17 : const char Metainfo::domainName[] = "Profiler";
18 : const char Metainfo::commandPrefix[] = "Profiler.";
19 : const char Metainfo::version[] = "1.3";
20 :
21 0 : std::unique_ptr<ProfileNode> ProfileNode::fromValue(protocol::Value* value, ErrorSupport* errors)
22 : {
23 0 : if (!value || value->type() != protocol::Value::TypeObject) {
24 0 : errors->addError("object expected");
25 : return nullptr;
26 : }
27 :
28 0 : std::unique_ptr<ProfileNode> result(new ProfileNode());
29 : protocol::DictionaryValue* object = DictionaryValue::cast(value);
30 0 : errors->push();
31 0 : protocol::Value* idValue = object->get("id");
32 0 : errors->setName("id");
33 0 : result->m_id = ValueConversions<int>::fromValue(idValue, errors);
34 0 : protocol::Value* callFrameValue = object->get("callFrame");
35 0 : errors->setName("callFrame");
36 0 : result->m_callFrame = ValueConversions<protocol::Runtime::CallFrame>::fromValue(callFrameValue, errors);
37 0 : protocol::Value* hitCountValue = object->get("hitCount");
38 0 : if (hitCountValue) {
39 0 : errors->setName("hitCount");
40 0 : result->m_hitCount = ValueConversions<int>::fromValue(hitCountValue, errors);
41 : }
42 0 : protocol::Value* childrenValue = object->get("children");
43 0 : if (childrenValue) {
44 0 : errors->setName("children");
45 0 : result->m_children = ValueConversions<protocol::Array<int>>::fromValue(childrenValue, errors);
46 : }
47 0 : protocol::Value* deoptReasonValue = object->get("deoptReason");
48 0 : if (deoptReasonValue) {
49 0 : errors->setName("deoptReason");
50 0 : result->m_deoptReason = ValueConversions<String>::fromValue(deoptReasonValue, errors);
51 : }
52 0 : protocol::Value* positionTicksValue = object->get("positionTicks");
53 0 : if (positionTicksValue) {
54 0 : errors->setName("positionTicks");
55 0 : result->m_positionTicks = ValueConversions<protocol::Array<protocol::Profiler::PositionTickInfo>>::fromValue(positionTicksValue, errors);
56 : }
57 0 : errors->pop();
58 0 : if (errors->hasErrors())
59 : return nullptr;
60 : return result;
61 : }
62 :
63 104 : std::unique_ptr<protocol::DictionaryValue> ProfileNode::toValue() const
64 : {
65 104 : std::unique_ptr<protocol::DictionaryValue> result = DictionaryValue::create();
66 520 : result->setValue("id", ValueConversions<int>::toValue(m_id));
67 416 : result->setValue("callFrame", ValueConversions<protocol::Runtime::CallFrame>::toValue(m_callFrame.get()));
68 104 : if (m_hitCount.isJust())
69 416 : result->setValue("hitCount", ValueConversions<int>::toValue(m_hitCount.fromJust()));
70 104 : if (m_children.isJust())
71 212 : result->setValue("children", ValueConversions<protocol::Array<int>>::toValue(m_children.fromJust()));
72 104 : if (m_deoptReason.isJust())
73 0 : result->setValue("deoptReason", ValueConversions<String>::toValue(m_deoptReason.fromJust()));
74 104 : if (m_positionTicks.isJust())
75 16 : result->setValue("positionTicks", ValueConversions<protocol::Array<protocol::Profiler::PositionTickInfo>>::toValue(m_positionTicks.fromJust()));
76 104 : return result;
77 : }
78 :
79 0 : std::unique_ptr<ProfileNode> ProfileNode::clone() const
80 : {
81 0 : ErrorSupport errors;
82 0 : return fromValue(toValue().get(), &errors);
83 : }
84 :
85 0 : std::unique_ptr<Profile> Profile::fromValue(protocol::Value* value, ErrorSupport* errors)
86 : {
87 0 : if (!value || value->type() != protocol::Value::TypeObject) {
88 0 : errors->addError("object expected");
89 : return nullptr;
90 : }
91 :
92 0 : std::unique_ptr<Profile> result(new Profile());
93 : protocol::DictionaryValue* object = DictionaryValue::cast(value);
94 0 : errors->push();
95 0 : protocol::Value* nodesValue = object->get("nodes");
96 0 : errors->setName("nodes");
97 0 : result->m_nodes = ValueConversions<protocol::Array<protocol::Profiler::ProfileNode>>::fromValue(nodesValue, errors);
98 0 : protocol::Value* startTimeValue = object->get("startTime");
99 0 : errors->setName("startTime");
100 0 : result->m_startTime = ValueConversions<double>::fromValue(startTimeValue, errors);
101 0 : protocol::Value* endTimeValue = object->get("endTime");
102 0 : errors->setName("endTime");
103 0 : result->m_endTime = ValueConversions<double>::fromValue(endTimeValue, errors);
104 0 : protocol::Value* samplesValue = object->get("samples");
105 0 : if (samplesValue) {
106 0 : errors->setName("samples");
107 0 : result->m_samples = ValueConversions<protocol::Array<int>>::fromValue(samplesValue, errors);
108 : }
109 0 : protocol::Value* timeDeltasValue = object->get("timeDeltas");
110 0 : if (timeDeltasValue) {
111 0 : errors->setName("timeDeltas");
112 0 : result->m_timeDeltas = ValueConversions<protocol::Array<int>>::fromValue(timeDeltasValue, errors);
113 : }
114 0 : errors->pop();
115 0 : if (errors->hasErrors())
116 : return nullptr;
117 : return result;
118 : }
119 :
120 45 : std::unique_ptr<protocol::DictionaryValue> Profile::toValue() const
121 : {
122 45 : std::unique_ptr<protocol::DictionaryValue> result = DictionaryValue::create();
123 180 : result->setValue("nodes", ValueConversions<protocol::Array<protocol::Profiler::ProfileNode>>::toValue(m_nodes.get()));
124 225 : result->setValue("startTime", ValueConversions<double>::toValue(m_startTime));
125 225 : result->setValue("endTime", ValueConversions<double>::toValue(m_endTime));
126 45 : if (m_samples.isJust())
127 180 : result->setValue("samples", ValueConversions<protocol::Array<int>>::toValue(m_samples.fromJust()));
128 45 : if (m_timeDeltas.isJust())
129 180 : result->setValue("timeDeltas", ValueConversions<protocol::Array<int>>::toValue(m_timeDeltas.fromJust()));
130 45 : return result;
131 : }
132 :
133 0 : std::unique_ptr<Profile> Profile::clone() const
134 : {
135 0 : ErrorSupport errors;
136 0 : return fromValue(toValue().get(), &errors);
137 : }
138 :
139 0 : std::unique_ptr<PositionTickInfo> PositionTickInfo::fromValue(protocol::Value* value, ErrorSupport* errors)
140 : {
141 0 : if (!value || value->type() != protocol::Value::TypeObject) {
142 0 : errors->addError("object expected");
143 : return nullptr;
144 : }
145 :
146 0 : std::unique_ptr<PositionTickInfo> result(new PositionTickInfo());
147 : protocol::DictionaryValue* object = DictionaryValue::cast(value);
148 0 : errors->push();
149 0 : protocol::Value* lineValue = object->get("line");
150 0 : errors->setName("line");
151 0 : result->m_line = ValueConversions<int>::fromValue(lineValue, errors);
152 0 : protocol::Value* ticksValue = object->get("ticks");
153 0 : errors->setName("ticks");
154 0 : result->m_ticks = ValueConversions<int>::fromValue(ticksValue, errors);
155 0 : errors->pop();
156 0 : if (errors->hasErrors())
157 : return nullptr;
158 : return result;
159 : }
160 :
161 4 : std::unique_ptr<protocol::DictionaryValue> PositionTickInfo::toValue() const
162 : {
163 4 : std::unique_ptr<protocol::DictionaryValue> result = DictionaryValue::create();
164 20 : result->setValue("line", ValueConversions<int>::toValue(m_line));
165 20 : result->setValue("ticks", ValueConversions<int>::toValue(m_ticks));
166 4 : return result;
167 : }
168 :
169 0 : std::unique_ptr<PositionTickInfo> PositionTickInfo::clone() const
170 : {
171 0 : ErrorSupport errors;
172 0 : return fromValue(toValue().get(), &errors);
173 : }
174 :
175 0 : std::unique_ptr<CoverageRange> CoverageRange::fromValue(protocol::Value* value, ErrorSupport* errors)
176 : {
177 0 : if (!value || value->type() != protocol::Value::TypeObject) {
178 0 : errors->addError("object expected");
179 : return nullptr;
180 : }
181 :
182 0 : std::unique_ptr<CoverageRange> result(new CoverageRange());
183 : protocol::DictionaryValue* object = DictionaryValue::cast(value);
184 0 : errors->push();
185 0 : protocol::Value* startOffsetValue = object->get("startOffset");
186 0 : errors->setName("startOffset");
187 0 : result->m_startOffset = ValueConversions<int>::fromValue(startOffsetValue, errors);
188 0 : protocol::Value* endOffsetValue = object->get("endOffset");
189 0 : errors->setName("endOffset");
190 0 : result->m_endOffset = ValueConversions<int>::fromValue(endOffsetValue, errors);
191 0 : protocol::Value* countValue = object->get("count");
192 0 : errors->setName("count");
193 0 : result->m_count = ValueConversions<int>::fromValue(countValue, errors);
194 0 : errors->pop();
195 0 : if (errors->hasErrors())
196 : return nullptr;
197 : return result;
198 : }
199 :
200 412 : std::unique_ptr<protocol::DictionaryValue> CoverageRange::toValue() const
201 : {
202 412 : std::unique_ptr<protocol::DictionaryValue> result = DictionaryValue::create();
203 2060 : result->setValue("startOffset", ValueConversions<int>::toValue(m_startOffset));
204 2060 : result->setValue("endOffset", ValueConversions<int>::toValue(m_endOffset));
205 2060 : result->setValue("count", ValueConversions<int>::toValue(m_count));
206 412 : return result;
207 : }
208 :
209 0 : std::unique_ptr<CoverageRange> CoverageRange::clone() const
210 : {
211 0 : ErrorSupport errors;
212 0 : return fromValue(toValue().get(), &errors);
213 : }
214 :
215 0 : std::unique_ptr<FunctionCoverage> FunctionCoverage::fromValue(protocol::Value* value, ErrorSupport* errors)
216 : {
217 0 : if (!value || value->type() != protocol::Value::TypeObject) {
218 0 : errors->addError("object expected");
219 : return nullptr;
220 : }
221 :
222 0 : std::unique_ptr<FunctionCoverage> result(new FunctionCoverage());
223 : protocol::DictionaryValue* object = DictionaryValue::cast(value);
224 0 : errors->push();
225 0 : protocol::Value* functionNameValue = object->get("functionName");
226 0 : errors->setName("functionName");
227 0 : result->m_functionName = ValueConversions<String>::fromValue(functionNameValue, errors);
228 0 : protocol::Value* rangesValue = object->get("ranges");
229 0 : errors->setName("ranges");
230 0 : result->m_ranges = ValueConversions<protocol::Array<protocol::Profiler::CoverageRange>>::fromValue(rangesValue, errors);
231 0 : protocol::Value* isBlockCoverageValue = object->get("isBlockCoverage");
232 0 : errors->setName("isBlockCoverage");
233 0 : result->m_isBlockCoverage = ValueConversions<bool>::fromValue(isBlockCoverageValue, errors);
234 0 : errors->pop();
235 0 : if (errors->hasErrors())
236 : return nullptr;
237 : return result;
238 : }
239 :
240 380 : std::unique_ptr<protocol::DictionaryValue> FunctionCoverage::toValue() const
241 : {
242 380 : std::unique_ptr<protocol::DictionaryValue> result = DictionaryValue::create();
243 1900 : result->setValue("functionName", ValueConversions<String>::toValue(m_functionName));
244 1520 : result->setValue("ranges", ValueConversions<protocol::Array<protocol::Profiler::CoverageRange>>::toValue(m_ranges.get()));
245 1900 : result->setValue("isBlockCoverage", ValueConversions<bool>::toValue(m_isBlockCoverage));
246 380 : return result;
247 : }
248 :
249 0 : std::unique_ptr<FunctionCoverage> FunctionCoverage::clone() const
250 : {
251 0 : ErrorSupport errors;
252 0 : return fromValue(toValue().get(), &errors);
253 : }
254 :
255 0 : std::unique_ptr<ScriptCoverage> ScriptCoverage::fromValue(protocol::Value* value, ErrorSupport* errors)
256 : {
257 0 : if (!value || value->type() != protocol::Value::TypeObject) {
258 0 : errors->addError("object expected");
259 : return nullptr;
260 : }
261 :
262 0 : std::unique_ptr<ScriptCoverage> result(new ScriptCoverage());
263 : protocol::DictionaryValue* object = DictionaryValue::cast(value);
264 0 : errors->push();
265 0 : protocol::Value* scriptIdValue = object->get("scriptId");
266 0 : errors->setName("scriptId");
267 0 : result->m_scriptId = ValueConversions<String>::fromValue(scriptIdValue, errors);
268 0 : protocol::Value* urlValue = object->get("url");
269 0 : errors->setName("url");
270 0 : result->m_url = ValueConversions<String>::fromValue(urlValue, errors);
271 0 : protocol::Value* functionsValue = object->get("functions");
272 0 : errors->setName("functions");
273 0 : result->m_functions = ValueConversions<protocol::Array<protocol::Profiler::FunctionCoverage>>::fromValue(functionsValue, errors);
274 0 : errors->pop();
275 0 : if (errors->hasErrors())
276 : return nullptr;
277 : return result;
278 : }
279 :
280 160 : std::unique_ptr<protocol::DictionaryValue> ScriptCoverage::toValue() const
281 : {
282 160 : std::unique_ptr<protocol::DictionaryValue> result = DictionaryValue::create();
283 800 : result->setValue("scriptId", ValueConversions<String>::toValue(m_scriptId));
284 800 : result->setValue("url", ValueConversions<String>::toValue(m_url));
285 640 : result->setValue("functions", ValueConversions<protocol::Array<protocol::Profiler::FunctionCoverage>>::toValue(m_functions.get()));
286 160 : return result;
287 : }
288 :
289 0 : std::unique_ptr<ScriptCoverage> ScriptCoverage::clone() const
290 : {
291 0 : ErrorSupport errors;
292 0 : return fromValue(toValue().get(), &errors);
293 : }
294 :
295 0 : std::unique_ptr<TypeObject> TypeObject::fromValue(protocol::Value* value, ErrorSupport* errors)
296 : {
297 0 : if (!value || value->type() != protocol::Value::TypeObject) {
298 0 : errors->addError("object expected");
299 : return nullptr;
300 : }
301 :
302 0 : std::unique_ptr<TypeObject> result(new TypeObject());
303 : protocol::DictionaryValue* object = DictionaryValue::cast(value);
304 0 : errors->push();
305 0 : protocol::Value* nameValue = object->get("name");
306 0 : errors->setName("name");
307 0 : result->m_name = ValueConversions<String>::fromValue(nameValue, errors);
308 0 : errors->pop();
309 0 : if (errors->hasErrors())
310 : return nullptr;
311 : return result;
312 : }
313 :
314 196 : std::unique_ptr<protocol::DictionaryValue> TypeObject::toValue() const
315 : {
316 196 : std::unique_ptr<protocol::DictionaryValue> result = DictionaryValue::create();
317 980 : result->setValue("name", ValueConversions<String>::toValue(m_name));
318 196 : return result;
319 : }
320 :
321 0 : std::unique_ptr<TypeObject> TypeObject::clone() const
322 : {
323 0 : ErrorSupport errors;
324 0 : return fromValue(toValue().get(), &errors);
325 : }
326 :
327 0 : std::unique_ptr<TypeProfileEntry> TypeProfileEntry::fromValue(protocol::Value* value, ErrorSupport* errors)
328 : {
329 0 : if (!value || value->type() != protocol::Value::TypeObject) {
330 0 : errors->addError("object expected");
331 : return nullptr;
332 : }
333 :
334 0 : std::unique_ptr<TypeProfileEntry> result(new TypeProfileEntry());
335 : protocol::DictionaryValue* object = DictionaryValue::cast(value);
336 0 : errors->push();
337 0 : protocol::Value* offsetValue = object->get("offset");
338 0 : errors->setName("offset");
339 0 : result->m_offset = ValueConversions<int>::fromValue(offsetValue, errors);
340 0 : protocol::Value* typesValue = object->get("types");
341 0 : errors->setName("types");
342 0 : result->m_types = ValueConversions<protocol::Array<protocol::Profiler::TypeObject>>::fromValue(typesValue, errors);
343 0 : errors->pop();
344 0 : if (errors->hasErrors())
345 : return nullptr;
346 : return result;
347 : }
348 :
349 148 : std::unique_ptr<protocol::DictionaryValue> TypeProfileEntry::toValue() const
350 : {
351 148 : std::unique_ptr<protocol::DictionaryValue> result = DictionaryValue::create();
352 740 : result->setValue("offset", ValueConversions<int>::toValue(m_offset));
353 592 : result->setValue("types", ValueConversions<protocol::Array<protocol::Profiler::TypeObject>>::toValue(m_types.get()));
354 148 : return result;
355 : }
356 :
357 0 : std::unique_ptr<TypeProfileEntry> TypeProfileEntry::clone() const
358 : {
359 0 : ErrorSupport errors;
360 0 : return fromValue(toValue().get(), &errors);
361 : }
362 :
363 0 : std::unique_ptr<ScriptTypeProfile> ScriptTypeProfile::fromValue(protocol::Value* value, ErrorSupport* errors)
364 : {
365 0 : if (!value || value->type() != protocol::Value::TypeObject) {
366 0 : errors->addError("object expected");
367 : return nullptr;
368 : }
369 :
370 0 : std::unique_ptr<ScriptTypeProfile> result(new ScriptTypeProfile());
371 : protocol::DictionaryValue* object = DictionaryValue::cast(value);
372 0 : errors->push();
373 0 : protocol::Value* scriptIdValue = object->get("scriptId");
374 0 : errors->setName("scriptId");
375 0 : result->m_scriptId = ValueConversions<String>::fromValue(scriptIdValue, errors);
376 0 : protocol::Value* urlValue = object->get("url");
377 0 : errors->setName("url");
378 0 : result->m_url = ValueConversions<String>::fromValue(urlValue, errors);
379 0 : protocol::Value* entriesValue = object->get("entries");
380 0 : errors->setName("entries");
381 0 : result->m_entries = ValueConversions<protocol::Array<protocol::Profiler::TypeProfileEntry>>::fromValue(entriesValue, errors);
382 0 : errors->pop();
383 0 : if (errors->hasErrors())
384 : return nullptr;
385 : return result;
386 : }
387 :
388 32 : std::unique_ptr<protocol::DictionaryValue> ScriptTypeProfile::toValue() const
389 : {
390 32 : std::unique_ptr<protocol::DictionaryValue> result = DictionaryValue::create();
391 160 : result->setValue("scriptId", ValueConversions<String>::toValue(m_scriptId));
392 160 : result->setValue("url", ValueConversions<String>::toValue(m_url));
393 128 : result->setValue("entries", ValueConversions<protocol::Array<protocol::Profiler::TypeProfileEntry>>::toValue(m_entries.get()));
394 32 : return result;
395 : }
396 :
397 0 : std::unique_ptr<ScriptTypeProfile> ScriptTypeProfile::clone() const
398 : {
399 0 : ErrorSupport errors;
400 0 : return fromValue(toValue().get(), &errors);
401 : }
402 :
403 0 : std::unique_ptr<ConsoleProfileFinishedNotification> ConsoleProfileFinishedNotification::fromValue(protocol::Value* value, ErrorSupport* errors)
404 : {
405 0 : if (!value || value->type() != protocol::Value::TypeObject) {
406 0 : errors->addError("object expected");
407 : return nullptr;
408 : }
409 :
410 0 : std::unique_ptr<ConsoleProfileFinishedNotification> result(new ConsoleProfileFinishedNotification());
411 : protocol::DictionaryValue* object = DictionaryValue::cast(value);
412 0 : errors->push();
413 0 : protocol::Value* idValue = object->get("id");
414 0 : errors->setName("id");
415 0 : result->m_id = ValueConversions<String>::fromValue(idValue, errors);
416 0 : protocol::Value* locationValue = object->get("location");
417 0 : errors->setName("location");
418 0 : result->m_location = ValueConversions<protocol::Debugger::Location>::fromValue(locationValue, errors);
419 0 : protocol::Value* profileValue = object->get("profile");
420 0 : errors->setName("profile");
421 0 : result->m_profile = ValueConversions<protocol::Profiler::Profile>::fromValue(profileValue, errors);
422 0 : protocol::Value* titleValue = object->get("title");
423 0 : if (titleValue) {
424 0 : errors->setName("title");
425 0 : result->m_title = ValueConversions<String>::fromValue(titleValue, errors);
426 : }
427 0 : errors->pop();
428 0 : if (errors->hasErrors())
429 : return nullptr;
430 : return result;
431 : }
432 :
433 35 : std::unique_ptr<protocol::DictionaryValue> ConsoleProfileFinishedNotification::toValue() const
434 : {
435 35 : std::unique_ptr<protocol::DictionaryValue> result = DictionaryValue::create();
436 175 : result->setValue("id", ValueConversions<String>::toValue(m_id));
437 140 : result->setValue("location", ValueConversions<protocol::Debugger::Location>::toValue(m_location.get()));
438 140 : result->setValue("profile", ValueConversions<protocol::Profiler::Profile>::toValue(m_profile.get()));
439 35 : if (m_title.isJust())
440 175 : result->setValue("title", ValueConversions<String>::toValue(m_title.fromJust()));
441 35 : return result;
442 : }
443 :
444 0 : std::unique_ptr<ConsoleProfileFinishedNotification> ConsoleProfileFinishedNotification::clone() const
445 : {
446 0 : ErrorSupport errors;
447 0 : return fromValue(toValue().get(), &errors);
448 : }
449 :
450 0 : std::unique_ptr<ConsoleProfileStartedNotification> ConsoleProfileStartedNotification::fromValue(protocol::Value* value, ErrorSupport* errors)
451 : {
452 0 : if (!value || value->type() != protocol::Value::TypeObject) {
453 0 : errors->addError("object expected");
454 : return nullptr;
455 : }
456 :
457 0 : std::unique_ptr<ConsoleProfileStartedNotification> result(new ConsoleProfileStartedNotification());
458 : protocol::DictionaryValue* object = DictionaryValue::cast(value);
459 0 : errors->push();
460 0 : protocol::Value* idValue = object->get("id");
461 0 : errors->setName("id");
462 0 : result->m_id = ValueConversions<String>::fromValue(idValue, errors);
463 0 : protocol::Value* locationValue = object->get("location");
464 0 : errors->setName("location");
465 0 : result->m_location = ValueConversions<protocol::Debugger::Location>::fromValue(locationValue, errors);
466 0 : protocol::Value* titleValue = object->get("title");
467 0 : if (titleValue) {
468 0 : errors->setName("title");
469 0 : result->m_title = ValueConversions<String>::fromValue(titleValue, errors);
470 : }
471 0 : errors->pop();
472 0 : if (errors->hasErrors())
473 : return nullptr;
474 : return result;
475 : }
476 :
477 40 : std::unique_ptr<protocol::DictionaryValue> ConsoleProfileStartedNotification::toValue() const
478 : {
479 40 : std::unique_ptr<protocol::DictionaryValue> result = DictionaryValue::create();
480 200 : result->setValue("id", ValueConversions<String>::toValue(m_id));
481 160 : result->setValue("location", ValueConversions<protocol::Debugger::Location>::toValue(m_location.get()));
482 40 : if (m_title.isJust())
483 200 : result->setValue("title", ValueConversions<String>::toValue(m_title.fromJust()));
484 40 : return result;
485 : }
486 :
487 0 : std::unique_ptr<ConsoleProfileStartedNotification> ConsoleProfileStartedNotification::clone() const
488 : {
489 0 : ErrorSupport errors;
490 0 : return fromValue(toValue().get(), &errors);
491 : }
492 :
493 : // ------------- Enum values from params.
494 :
495 :
496 : // ------------- Frontend notifications.
497 :
498 35 : void Frontend::consoleProfileFinished(const String& id, std::unique_ptr<protocol::Debugger::Location> location, std::unique_ptr<protocol::Profiler::Profile> profile, Maybe<String> title)
499 : {
500 35 : if (!m_frontendChannel)
501 35 : return;
502 : std::unique_ptr<ConsoleProfileFinishedNotification> messageData = ConsoleProfileFinishedNotification::create()
503 35 : .setId(id)
504 : .setLocation(std::move(location))
505 : .setProfile(std::move(profile))
506 : .build();
507 35 : if (title.isJust())
508 70 : messageData->setTitle(std::move(title).takeJust());
509 245 : m_frontendChannel->sendProtocolNotification(InternalResponse::createNotification("Profiler.consoleProfileFinished", std::move(messageData)));
510 : }
511 :
512 40 : void Frontend::consoleProfileStarted(const String& id, std::unique_ptr<protocol::Debugger::Location> location, Maybe<String> title)
513 : {
514 40 : if (!m_frontendChannel)
515 40 : return;
516 : std::unique_ptr<ConsoleProfileStartedNotification> messageData = ConsoleProfileStartedNotification::create()
517 40 : .setId(id)
518 : .setLocation(std::move(location))
519 : .build();
520 40 : if (title.isJust())
521 80 : messageData->setTitle(std::move(title).takeJust());
522 280 : m_frontendChannel->sendProtocolNotification(InternalResponse::createNotification("Profiler.consoleProfileStarted", std::move(messageData)));
523 : }
524 :
525 0 : void Frontend::flush()
526 : {
527 0 : m_frontendChannel->flushProtocolNotifications();
528 0 : }
529 :
530 0 : void Frontend::sendRawNotification(String notification)
531 : {
532 0 : m_frontendChannel->sendProtocolNotification(InternalRawNotification::fromJSON(std::move(notification)));
533 0 : }
534 :
535 0 : void Frontend::sendRawNotification(std::vector<uint8_t> notification)
536 : {
537 0 : m_frontendChannel->sendProtocolNotification(InternalRawNotification::fromBinary(std::move(notification)));
538 0 : }
539 :
540 : // --------------------- Dispatcher.
541 :
542 : class DispatcherImpl : public protocol::DispatcherBase {
543 : public:
544 3832 : DispatcherImpl(FrontendChannel* frontendChannel, Backend* backend)
545 : : DispatcherBase(frontendChannel)
546 11496 : , m_backend(backend) {
547 11496 : m_dispatchMap["Profiler.disable"] = &DispatcherImpl::disable;
548 11496 : m_dispatchMap["Profiler.enable"] = &DispatcherImpl::enable;
549 11496 : m_dispatchMap["Profiler.getBestEffortCoverage"] = &DispatcherImpl::getBestEffortCoverage;
550 11496 : m_dispatchMap["Profiler.setSamplingInterval"] = &DispatcherImpl::setSamplingInterval;
551 11496 : m_dispatchMap["Profiler.start"] = &DispatcherImpl::start;
552 11496 : m_dispatchMap["Profiler.startPreciseCoverage"] = &DispatcherImpl::startPreciseCoverage;
553 11496 : m_dispatchMap["Profiler.startTypeProfile"] = &DispatcherImpl::startTypeProfile;
554 11496 : m_dispatchMap["Profiler.stop"] = &DispatcherImpl::stop;
555 11496 : m_dispatchMap["Profiler.stopPreciseCoverage"] = &DispatcherImpl::stopPreciseCoverage;
556 11496 : m_dispatchMap["Profiler.stopTypeProfile"] = &DispatcherImpl::stopTypeProfile;
557 11496 : m_dispatchMap["Profiler.takePreciseCoverage"] = &DispatcherImpl::takePreciseCoverage;
558 11496 : m_dispatchMap["Profiler.takeTypeProfile"] = &DispatcherImpl::takeTypeProfile;
559 3832 : }
560 11496 : ~DispatcherImpl() override { }
561 : bool canDispatch(const String& method) override;
562 : void dispatch(int callId, const String& method, const ProtocolMessage& message, std::unique_ptr<protocol::DictionaryValue> messageObject) override;
563 : std::unordered_map<String, String>& redirects() { return m_redirects; }
564 :
565 : protected:
566 : using CallHandler = void (DispatcherImpl::*)(int callId, const String& method, const ProtocolMessage& message, std::unique_ptr<DictionaryValue> messageObject, ErrorSupport* errors);
567 : using DispatchMap = std::unordered_map<String, CallHandler>;
568 : DispatchMap m_dispatchMap;
569 : std::unordered_map<String, String> m_redirects;
570 :
571 : void disable(int callId, const String& method, const ProtocolMessage& message, std::unique_ptr<DictionaryValue> requestMessageObject, ErrorSupport*);
572 : void enable(int callId, const String& method, const ProtocolMessage& message, std::unique_ptr<DictionaryValue> requestMessageObject, ErrorSupport*);
573 : void getBestEffortCoverage(int callId, const String& method, const ProtocolMessage& message, std::unique_ptr<DictionaryValue> requestMessageObject, ErrorSupport*);
574 : void setSamplingInterval(int callId, const String& method, const ProtocolMessage& message, std::unique_ptr<DictionaryValue> requestMessageObject, ErrorSupport*);
575 : void start(int callId, const String& method, const ProtocolMessage& message, std::unique_ptr<DictionaryValue> requestMessageObject, ErrorSupport*);
576 : void startPreciseCoverage(int callId, const String& method, const ProtocolMessage& message, std::unique_ptr<DictionaryValue> requestMessageObject, ErrorSupport*);
577 : void startTypeProfile(int callId, const String& method, const ProtocolMessage& message, std::unique_ptr<DictionaryValue> requestMessageObject, ErrorSupport*);
578 : void stop(int callId, const String& method, const ProtocolMessage& message, std::unique_ptr<DictionaryValue> requestMessageObject, ErrorSupport*);
579 : void stopPreciseCoverage(int callId, const String& method, const ProtocolMessage& message, std::unique_ptr<DictionaryValue> requestMessageObject, ErrorSupport*);
580 : void stopTypeProfile(int callId, const String& method, const ProtocolMessage& message, std::unique_ptr<DictionaryValue> requestMessageObject, ErrorSupport*);
581 : void takePreciseCoverage(int callId, const String& method, const ProtocolMessage& message, std::unique_ptr<DictionaryValue> requestMessageObject, ErrorSupport*);
582 : void takeTypeProfile(int callId, const String& method, const ProtocolMessage& message, std::unique_ptr<DictionaryValue> requestMessageObject, ErrorSupport*);
583 :
584 : Backend* m_backend;
585 : };
586 :
587 760 : bool DispatcherImpl::canDispatch(const String& method) {
588 760 : return m_dispatchMap.find(method) != m_dispatchMap.end();
589 : }
590 :
591 756 : void DispatcherImpl::dispatch(int callId, const String& method, const ProtocolMessage& message, std::unique_ptr<protocol::DictionaryValue> messageObject)
592 : {
593 : std::unordered_map<String, CallHandler>::iterator it = m_dispatchMap.find(method);
594 : DCHECK(it != m_dispatchMap.end());
595 756 : protocol::ErrorSupport errors;
596 2268 : (this->*(it->second))(callId, method, message, std::move(messageObject), &errors);
597 756 : }
598 :
599 :
600 134 : void DispatcherImpl::disable(int callId, const String& method, const ProtocolMessage& message, std::unique_ptr<DictionaryValue> requestMessageObject, ErrorSupport* errors)
601 : {
602 :
603 134 : std::unique_ptr<DispatcherBase::WeakPtr> weak = weakPtr();
604 134 : DispatchResponse response = m_backend->disable();
605 134 : if (response.status() == DispatchResponse::kFallThrough) {
606 0 : channel()->fallThrough(callId, method, message);
607 0 : return;
608 : }
609 134 : if (weak->get())
610 134 : weak->get()->sendResponse(callId, response);
611 : return;
612 : }
613 :
614 154 : void DispatcherImpl::enable(int callId, const String& method, const ProtocolMessage& message, std::unique_ptr<DictionaryValue> requestMessageObject, ErrorSupport* errors)
615 : {
616 :
617 154 : std::unique_ptr<DispatcherBase::WeakPtr> weak = weakPtr();
618 154 : DispatchResponse response = m_backend->enable();
619 154 : if (response.status() == DispatchResponse::kFallThrough) {
620 0 : channel()->fallThrough(callId, method, message);
621 0 : return;
622 : }
623 154 : if (weak->get())
624 154 : weak->get()->sendResponse(callId, response);
625 : return;
626 : }
627 :
628 48 : void DispatcherImpl::getBestEffortCoverage(int callId, const String& method, const ProtocolMessage& message, std::unique_ptr<DictionaryValue> requestMessageObject, ErrorSupport* errors)
629 : {
630 : // Declare output parameters.
631 48 : std::unique_ptr<protocol::Array<protocol::Profiler::ScriptCoverage>> out_result;
632 :
633 48 : std::unique_ptr<DispatcherBase::WeakPtr> weak = weakPtr();
634 48 : DispatchResponse response = m_backend->getBestEffortCoverage(&out_result);
635 48 : if (response.status() == DispatchResponse::kFallThrough) {
636 0 : channel()->fallThrough(callId, method, message);
637 0 : return;
638 : }
639 48 : std::unique_ptr<protocol::DictionaryValue> result = DictionaryValue::create();
640 48 : if (response.status() == DispatchResponse::kSuccess) {
641 192 : result->setValue("result", ValueConversions<protocol::Array<protocol::Profiler::ScriptCoverage>>::toValue(out_result.get()));
642 : }
643 48 : if (weak->get())
644 96 : weak->get()->sendResponse(callId, response, std::move(result));
645 : return;
646 : }
647 :
648 0 : void DispatcherImpl::setSamplingInterval(int callId, const String& method, const ProtocolMessage& message, std::unique_ptr<DictionaryValue> requestMessageObject, ErrorSupport* errors)
649 : {
650 : // Prepare input parameters.
651 0 : protocol::DictionaryValue* object = DictionaryValue::cast(requestMessageObject->get("params"));
652 0 : errors->push();
653 0 : protocol::Value* intervalValue = object ? object->get("interval") : nullptr;
654 0 : errors->setName("interval");
655 0 : int in_interval = ValueConversions<int>::fromValue(intervalValue, errors);
656 0 : errors->pop();
657 0 : if (errors->hasErrors()) {
658 0 : reportProtocolError(callId, DispatchResponse::kInvalidParams, kInvalidParamsString, errors);
659 0 : return;
660 : }
661 :
662 0 : std::unique_ptr<DispatcherBase::WeakPtr> weak = weakPtr();
663 0 : DispatchResponse response = m_backend->setSamplingInterval(in_interval);
664 0 : if (response.status() == DispatchResponse::kFallThrough) {
665 0 : channel()->fallThrough(callId, method, message);
666 0 : return;
667 : }
668 0 : if (weak->get())
669 0 : weak->get()->sendResponse(callId, response);
670 : return;
671 : }
672 :
673 20 : void DispatcherImpl::start(int callId, const String& method, const ProtocolMessage& message, std::unique_ptr<DictionaryValue> requestMessageObject, ErrorSupport* errors)
674 : {
675 :
676 20 : std::unique_ptr<DispatcherBase::WeakPtr> weak = weakPtr();
677 20 : DispatchResponse response = m_backend->start();
678 20 : if (response.status() == DispatchResponse::kFallThrough) {
679 0 : channel()->fallThrough(callId, method, message);
680 0 : return;
681 : }
682 20 : if (weak->get())
683 20 : weak->get()->sendResponse(callId, response);
684 : return;
685 : }
686 :
687 68 : void DispatcherImpl::startPreciseCoverage(int callId, const String& method, const ProtocolMessage& message, std::unique_ptr<DictionaryValue> requestMessageObject, ErrorSupport* errors)
688 : {
689 : // Prepare input parameters.
690 204 : protocol::DictionaryValue* object = DictionaryValue::cast(requestMessageObject->get("params"));
691 68 : errors->push();
692 136 : protocol::Value* callCountValue = object ? object->get("callCount") : nullptr;
693 : Maybe<bool> in_callCount;
694 68 : if (callCountValue) {
695 44 : errors->setName("callCount");
696 44 : in_callCount = ValueConversions<bool>::fromValue(callCountValue, errors);
697 : }
698 136 : protocol::Value* detailedValue = object ? object->get("detailed") : nullptr;
699 : Maybe<bool> in_detailed;
700 68 : if (detailedValue) {
701 68 : errors->setName("detailed");
702 68 : in_detailed = ValueConversions<bool>::fromValue(detailedValue, errors);
703 : }
704 68 : errors->pop();
705 68 : if (errors->hasErrors()) {
706 0 : reportProtocolError(callId, DispatchResponse::kInvalidParams, kInvalidParamsString, errors);
707 0 : return;
708 : }
709 :
710 68 : std::unique_ptr<DispatcherBase::WeakPtr> weak = weakPtr();
711 136 : DispatchResponse response = m_backend->startPreciseCoverage(std::move(in_callCount), std::move(in_detailed));
712 68 : if (response.status() == DispatchResponse::kFallThrough) {
713 0 : channel()->fallThrough(callId, method, message);
714 0 : return;
715 : }
716 68 : if (weak->get())
717 68 : weak->get()->sendResponse(callId, response);
718 : return;
719 : }
720 :
721 52 : void DispatcherImpl::startTypeProfile(int callId, const String& method, const ProtocolMessage& message, std::unique_ptr<DictionaryValue> requestMessageObject, ErrorSupport* errors)
722 : {
723 :
724 52 : std::unique_ptr<DispatcherBase::WeakPtr> weak = weakPtr();
725 52 : DispatchResponse response = m_backend->startTypeProfile();
726 52 : if (response.status() == DispatchResponse::kFallThrough) {
727 0 : channel()->fallThrough(callId, method, message);
728 0 : return;
729 : }
730 52 : if (weak->get())
731 52 : weak->get()->sendResponse(callId, response);
732 : return;
733 : }
734 :
735 20 : void DispatcherImpl::stop(int callId, const String& method, const ProtocolMessage& message, std::unique_ptr<DictionaryValue> requestMessageObject, ErrorSupport* errors)
736 : {
737 : // Declare output parameters.
738 20 : std::unique_ptr<protocol::Profiler::Profile> out_profile;
739 :
740 20 : std::unique_ptr<DispatcherBase::WeakPtr> weak = weakPtr();
741 20 : DispatchResponse response = m_backend->stop(&out_profile);
742 20 : if (response.status() == DispatchResponse::kFallThrough) {
743 0 : channel()->fallThrough(callId, method, message);
744 0 : return;
745 : }
746 20 : std::unique_ptr<protocol::DictionaryValue> result = DictionaryValue::create();
747 20 : if (response.status() == DispatchResponse::kSuccess) {
748 40 : result->setValue("profile", ValueConversions<protocol::Profiler::Profile>::toValue(out_profile.get()));
749 : }
750 20 : if (weak->get())
751 40 : weak->get()->sendResponse(callId, response, std::move(result));
752 : return;
753 : }
754 :
755 68 : void DispatcherImpl::stopPreciseCoverage(int callId, const String& method, const ProtocolMessage& message, std::unique_ptr<DictionaryValue> requestMessageObject, ErrorSupport* errors)
756 : {
757 :
758 68 : std::unique_ptr<DispatcherBase::WeakPtr> weak = weakPtr();
759 68 : DispatchResponse response = m_backend->stopPreciseCoverage();
760 68 : if (response.status() == DispatchResponse::kFallThrough) {
761 0 : channel()->fallThrough(callId, method, message);
762 0 : return;
763 : }
764 68 : if (weak->get())
765 68 : weak->get()->sendResponse(callId, response);
766 : return;
767 : }
768 :
769 48 : void DispatcherImpl::stopTypeProfile(int callId, const String& method, const ProtocolMessage& message, std::unique_ptr<DictionaryValue> requestMessageObject, ErrorSupport* errors)
770 : {
771 :
772 48 : std::unique_ptr<DispatcherBase::WeakPtr> weak = weakPtr();
773 48 : DispatchResponse response = m_backend->stopTypeProfile();
774 48 : if (response.status() == DispatchResponse::kFallThrough) {
775 0 : channel()->fallThrough(callId, method, message);
776 0 : return;
777 : }
778 48 : if (weak->get())
779 48 : weak->get()->sendResponse(callId, response);
780 : return;
781 : }
782 :
783 96 : void DispatcherImpl::takePreciseCoverage(int callId, const String& method, const ProtocolMessage& message, std::unique_ptr<DictionaryValue> requestMessageObject, ErrorSupport* errors)
784 : {
785 : // Declare output parameters.
786 96 : std::unique_ptr<protocol::Array<protocol::Profiler::ScriptCoverage>> out_result;
787 :
788 96 : std::unique_ptr<DispatcherBase::WeakPtr> weak = weakPtr();
789 96 : DispatchResponse response = m_backend->takePreciseCoverage(&out_result);
790 96 : if (response.status() == DispatchResponse::kFallThrough) {
791 0 : channel()->fallThrough(callId, method, message);
792 0 : return;
793 : }
794 96 : std::unique_ptr<protocol::DictionaryValue> result = DictionaryValue::create();
795 96 : if (response.status() == DispatchResponse::kSuccess) {
796 352 : result->setValue("result", ValueConversions<protocol::Array<protocol::Profiler::ScriptCoverage>>::toValue(out_result.get()));
797 : }
798 96 : if (weak->get())
799 192 : weak->get()->sendResponse(callId, response, std::move(result));
800 : return;
801 : }
802 :
803 48 : void DispatcherImpl::takeTypeProfile(int callId, const String& method, const ProtocolMessage& message, std::unique_ptr<DictionaryValue> requestMessageObject, ErrorSupport* errors)
804 : {
805 : // Declare output parameters.
806 48 : std::unique_ptr<protocol::Array<protocol::Profiler::ScriptTypeProfile>> out_result;
807 :
808 48 : std::unique_ptr<DispatcherBase::WeakPtr> weak = weakPtr();
809 48 : DispatchResponse response = m_backend->takeTypeProfile(&out_result);
810 48 : if (response.status() == DispatchResponse::kFallThrough) {
811 0 : channel()->fallThrough(callId, method, message);
812 0 : return;
813 : }
814 48 : std::unique_ptr<protocol::DictionaryValue> result = DictionaryValue::create();
815 48 : if (response.status() == DispatchResponse::kSuccess) {
816 160 : result->setValue("result", ValueConversions<protocol::Array<protocol::Profiler::ScriptTypeProfile>>::toValue(out_result.get()));
817 : }
818 48 : if (weak->get())
819 96 : weak->get()->sendResponse(callId, response, std::move(result));
820 : return;
821 : }
822 :
823 : // static
824 3832 : void Dispatcher::wire(UberDispatcher* uber, Backend* backend)
825 : {
826 3832 : std::unique_ptr<DispatcherImpl> dispatcher(new DispatcherImpl(uber->channel(), backend));
827 3832 : uber->setupRedirects(dispatcher->redirects());
828 11496 : uber->registerBackend("Profiler", std::move(dispatcher));
829 3832 : }
830 :
831 : } // Profiler
832 : } // namespace v8_inspector
833 : } // namespace protocol
|