Line data Source code
1 : // This file is generated
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.2";
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 111 : std::unique_ptr<protocol::DictionaryValue> ProfileNode::toValue() const
64 : {
65 111 : std::unique_ptr<protocol::DictionaryValue> result = DictionaryValue::create();
66 555 : result->setValue("id", ValueConversions<int>::toValue(m_id));
67 444 : result->setValue("callFrame", ValueConversions<protocol::Runtime::CallFrame>::toValue(m_callFrame.get()));
68 111 : if (m_hitCount.isJust())
69 444 : result->setValue("hitCount", ValueConversions<int>::toValue(m_hitCount.fromJust()));
70 111 : if (m_children.isJust())
71 220 : result->setValue("children", ValueConversions<protocol::Array<int>>::toValue(m_children.fromJust()));
72 111 : if (m_deoptReason.isJust())
73 0 : result->setValue("deoptReason", ValueConversions<String>::toValue(m_deoptReason.fromJust()));
74 111 : if (m_positionTicks.isJust())
75 96 : result->setValue("positionTicks", ValueConversions<protocol::Array<protocol::Profiler::PositionTickInfo>>::toValue(m_positionTicks.fromJust()));
76 111 : 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 34 : std::unique_ptr<protocol::DictionaryValue> Profile::toValue() const
121 : {
122 34 : std::unique_ptr<protocol::DictionaryValue> result = DictionaryValue::create();
123 136 : result->setValue("nodes", ValueConversions<protocol::Array<protocol::Profiler::ProfileNode>>::toValue(m_nodes.get()));
124 170 : result->setValue("startTime", ValueConversions<double>::toValue(m_startTime));
125 170 : result->setValue("endTime", ValueConversions<double>::toValue(m_endTime));
126 34 : if (m_samples.isJust())
127 136 : result->setValue("samples", ValueConversions<protocol::Array<int>>::toValue(m_samples.fromJust()));
128 34 : if (m_timeDeltas.isJust())
129 136 : result->setValue("timeDeltas", ValueConversions<protocol::Array<int>>::toValue(m_timeDeltas.fromJust()));
130 34 : 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 24 : std::unique_ptr<protocol::DictionaryValue> PositionTickInfo::toValue() const
162 : {
163 24 : std::unique_ptr<protocol::DictionaryValue> result = DictionaryValue::create();
164 120 : result->setValue("line", ValueConversions<int>::toValue(m_line));
165 120 : result->setValue("ticks", ValueConversions<int>::toValue(m_ticks));
166 24 : 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 288 : std::unique_ptr<protocol::DictionaryValue> CoverageRange::toValue() const
201 : {
202 288 : std::unique_ptr<protocol::DictionaryValue> result = DictionaryValue::create();
203 1440 : result->setValue("startOffset", ValueConversions<int>::toValue(m_startOffset));
204 1440 : result->setValue("endOffset", ValueConversions<int>::toValue(m_endOffset));
205 1440 : result->setValue("count", ValueConversions<int>::toValue(m_count));
206 288 : 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 : errors->pop();
232 0 : if (errors->hasErrors())
233 : return nullptr;
234 : return result;
235 : }
236 :
237 288 : std::unique_ptr<protocol::DictionaryValue> FunctionCoverage::toValue() const
238 : {
239 288 : std::unique_ptr<protocol::DictionaryValue> result = DictionaryValue::create();
240 1440 : result->setValue("functionName", ValueConversions<String>::toValue(m_functionName));
241 1152 : result->setValue("ranges", ValueConversions<protocol::Array<protocol::Profiler::CoverageRange>>::toValue(m_ranges.get()));
242 288 : return result;
243 : }
244 :
245 0 : std::unique_ptr<FunctionCoverage> FunctionCoverage::clone() const
246 : {
247 0 : ErrorSupport errors;
248 0 : return fromValue(toValue().get(), &errors);
249 : }
250 :
251 0 : std::unique_ptr<ScriptCoverage> ScriptCoverage::fromValue(protocol::Value* value, ErrorSupport* errors)
252 : {
253 0 : if (!value || value->type() != protocol::Value::TypeObject) {
254 0 : errors->addError("object expected");
255 : return nullptr;
256 : }
257 :
258 0 : std::unique_ptr<ScriptCoverage> result(new ScriptCoverage());
259 : protocol::DictionaryValue* object = DictionaryValue::cast(value);
260 0 : errors->push();
261 0 : protocol::Value* scriptIdValue = object->get("scriptId");
262 0 : errors->setName("scriptId");
263 0 : result->m_scriptId = ValueConversions<String>::fromValue(scriptIdValue, errors);
264 0 : protocol::Value* urlValue = object->get("url");
265 0 : errors->setName("url");
266 0 : result->m_url = ValueConversions<String>::fromValue(urlValue, errors);
267 0 : protocol::Value* functionsValue = object->get("functions");
268 0 : errors->setName("functions");
269 0 : result->m_functions = ValueConversions<protocol::Array<protocol::Profiler::FunctionCoverage>>::fromValue(functionsValue, errors);
270 0 : errors->pop();
271 0 : if (errors->hasErrors())
272 : return nullptr;
273 : return result;
274 : }
275 :
276 120 : std::unique_ptr<protocol::DictionaryValue> ScriptCoverage::toValue() const
277 : {
278 120 : std::unique_ptr<protocol::DictionaryValue> result = DictionaryValue::create();
279 600 : result->setValue("scriptId", ValueConversions<String>::toValue(m_scriptId));
280 600 : result->setValue("url", ValueConversions<String>::toValue(m_url));
281 480 : result->setValue("functions", ValueConversions<protocol::Array<protocol::Profiler::FunctionCoverage>>::toValue(m_functions.get()));
282 120 : return result;
283 : }
284 :
285 0 : std::unique_ptr<ScriptCoverage> ScriptCoverage::clone() const
286 : {
287 0 : ErrorSupport errors;
288 0 : return fromValue(toValue().get(), &errors);
289 : }
290 :
291 0 : std::unique_ptr<ConsoleProfileStartedNotification> ConsoleProfileStartedNotification::fromValue(protocol::Value* value, ErrorSupport* errors)
292 : {
293 0 : if (!value || value->type() != protocol::Value::TypeObject) {
294 0 : errors->addError("object expected");
295 : return nullptr;
296 : }
297 :
298 0 : std::unique_ptr<ConsoleProfileStartedNotification> result(new ConsoleProfileStartedNotification());
299 : protocol::DictionaryValue* object = DictionaryValue::cast(value);
300 0 : errors->push();
301 0 : protocol::Value* idValue = object->get("id");
302 0 : errors->setName("id");
303 0 : result->m_id = ValueConversions<String>::fromValue(idValue, errors);
304 0 : protocol::Value* locationValue = object->get("location");
305 0 : errors->setName("location");
306 0 : result->m_location = ValueConversions<protocol::Debugger::Location>::fromValue(locationValue, errors);
307 0 : protocol::Value* titleValue = object->get("title");
308 0 : if (titleValue) {
309 0 : errors->setName("title");
310 0 : result->m_title = ValueConversions<String>::fromValue(titleValue, errors);
311 : }
312 0 : errors->pop();
313 0 : if (errors->hasErrors())
314 : return nullptr;
315 : return result;
316 : }
317 :
318 28 : std::unique_ptr<protocol::DictionaryValue> ConsoleProfileStartedNotification::toValue() const
319 : {
320 28 : std::unique_ptr<protocol::DictionaryValue> result = DictionaryValue::create();
321 140 : result->setValue("id", ValueConversions<String>::toValue(m_id));
322 112 : result->setValue("location", ValueConversions<protocol::Debugger::Location>::toValue(m_location.get()));
323 28 : if (m_title.isJust())
324 140 : result->setValue("title", ValueConversions<String>::toValue(m_title.fromJust()));
325 28 : return result;
326 : }
327 :
328 0 : std::unique_ptr<ConsoleProfileStartedNotification> ConsoleProfileStartedNotification::clone() const
329 : {
330 0 : ErrorSupport errors;
331 0 : return fromValue(toValue().get(), &errors);
332 : }
333 :
334 0 : std::unique_ptr<ConsoleProfileFinishedNotification> ConsoleProfileFinishedNotification::fromValue(protocol::Value* value, ErrorSupport* errors)
335 : {
336 0 : if (!value || value->type() != protocol::Value::TypeObject) {
337 0 : errors->addError("object expected");
338 : return nullptr;
339 : }
340 :
341 0 : std::unique_ptr<ConsoleProfileFinishedNotification> result(new ConsoleProfileFinishedNotification());
342 : protocol::DictionaryValue* object = DictionaryValue::cast(value);
343 0 : errors->push();
344 0 : protocol::Value* idValue = object->get("id");
345 0 : errors->setName("id");
346 0 : result->m_id = ValueConversions<String>::fromValue(idValue, errors);
347 0 : protocol::Value* locationValue = object->get("location");
348 0 : errors->setName("location");
349 0 : result->m_location = ValueConversions<protocol::Debugger::Location>::fromValue(locationValue, errors);
350 0 : protocol::Value* profileValue = object->get("profile");
351 0 : errors->setName("profile");
352 0 : result->m_profile = ValueConversions<protocol::Profiler::Profile>::fromValue(profileValue, errors);
353 0 : protocol::Value* titleValue = object->get("title");
354 0 : if (titleValue) {
355 0 : errors->setName("title");
356 0 : result->m_title = ValueConversions<String>::fromValue(titleValue, errors);
357 : }
358 0 : errors->pop();
359 0 : if (errors->hasErrors())
360 : return nullptr;
361 : return result;
362 : }
363 :
364 22 : std::unique_ptr<protocol::DictionaryValue> ConsoleProfileFinishedNotification::toValue() const
365 : {
366 22 : std::unique_ptr<protocol::DictionaryValue> result = DictionaryValue::create();
367 110 : result->setValue("id", ValueConversions<String>::toValue(m_id));
368 88 : result->setValue("location", ValueConversions<protocol::Debugger::Location>::toValue(m_location.get()));
369 88 : result->setValue("profile", ValueConversions<protocol::Profiler::Profile>::toValue(m_profile.get()));
370 22 : if (m_title.isJust())
371 110 : result->setValue("title", ValueConversions<String>::toValue(m_title.fromJust()));
372 22 : return result;
373 : }
374 :
375 0 : std::unique_ptr<ConsoleProfileFinishedNotification> ConsoleProfileFinishedNotification::clone() const
376 : {
377 0 : ErrorSupport errors;
378 0 : return fromValue(toValue().get(), &errors);
379 : }
380 :
381 : // ------------- Enum values from params.
382 :
383 :
384 : // ------------- Frontend notifications.
385 :
386 28 : void Frontend::consoleProfileStarted(const String& id, std::unique_ptr<protocol::Debugger::Location> location, Maybe<String> title)
387 : {
388 28 : if (!m_frontendChannel)
389 28 : return;
390 : std::unique_ptr<ConsoleProfileStartedNotification> messageData = ConsoleProfileStartedNotification::create()
391 28 : .setId(id)
392 : .setLocation(std::move(location))
393 : .build();
394 28 : if (title.isJust())
395 56 : messageData->setTitle(std::move(title).takeJust());
396 196 : m_frontendChannel->sendProtocolNotification(InternalResponse::createNotification("Profiler.consoleProfileStarted", std::move(messageData)));
397 : }
398 :
399 22 : void Frontend::consoleProfileFinished(const String& id, std::unique_ptr<protocol::Debugger::Location> location, std::unique_ptr<protocol::Profiler::Profile> profile, Maybe<String> title)
400 : {
401 22 : if (!m_frontendChannel)
402 22 : return;
403 : std::unique_ptr<ConsoleProfileFinishedNotification> messageData = ConsoleProfileFinishedNotification::create()
404 22 : .setId(id)
405 : .setLocation(std::move(location))
406 : .setProfile(std::move(profile))
407 : .build();
408 22 : if (title.isJust())
409 44 : messageData->setTitle(std::move(title).takeJust());
410 154 : m_frontendChannel->sendProtocolNotification(InternalResponse::createNotification("Profiler.consoleProfileFinished", std::move(messageData)));
411 : }
412 :
413 0 : void Frontend::flush()
414 : {
415 0 : m_frontendChannel->flushProtocolNotifications();
416 0 : }
417 :
418 0 : void Frontend::sendRawNotification(const String& notification)
419 : {
420 0 : m_frontendChannel->sendProtocolNotification(InternalRawNotification::create(notification));
421 0 : }
422 :
423 : // --------------------- Dispatcher.
424 :
425 : class DispatcherImpl : public protocol::DispatcherBase {
426 : public:
427 4573 : DispatcherImpl(FrontendChannel* frontendChannel, Backend* backend, bool fallThroughForNotFound)
428 : : DispatcherBase(frontendChannel)
429 : , m_backend(backend)
430 9146 : , m_fallThroughForNotFound(fallThroughForNotFound) {
431 13719 : m_dispatchMap["Profiler.enable"] = &DispatcherImpl::enable;
432 13719 : m_dispatchMap["Profiler.disable"] = &DispatcherImpl::disable;
433 13719 : m_dispatchMap["Profiler.setSamplingInterval"] = &DispatcherImpl::setSamplingInterval;
434 13719 : m_dispatchMap["Profiler.start"] = &DispatcherImpl::start;
435 13719 : m_dispatchMap["Profiler.stop"] = &DispatcherImpl::stop;
436 13719 : m_dispatchMap["Profiler.startPreciseCoverage"] = &DispatcherImpl::startPreciseCoverage;
437 13719 : m_dispatchMap["Profiler.stopPreciseCoverage"] = &DispatcherImpl::stopPreciseCoverage;
438 13719 : m_dispatchMap["Profiler.takePreciseCoverage"] = &DispatcherImpl::takePreciseCoverage;
439 13719 : m_dispatchMap["Profiler.getBestEffortCoverage"] = &DispatcherImpl::getBestEffortCoverage;
440 4573 : }
441 13719 : ~DispatcherImpl() override { }
442 : DispatchResponse::Status dispatch(int callId, const String& method, std::unique_ptr<protocol::DictionaryValue> messageObject) override;
443 :
444 : protected:
445 : using CallHandler = DispatchResponse::Status (DispatcherImpl::*)(int callId, std::unique_ptr<DictionaryValue> messageObject, ErrorSupport* errors);
446 : using DispatchMap = protocol::HashMap<String, CallHandler>;
447 : DispatchMap m_dispatchMap;
448 :
449 : DispatchResponse::Status enable(int callId, std::unique_ptr<DictionaryValue> requestMessageObject, ErrorSupport*);
450 : DispatchResponse::Status disable(int callId, std::unique_ptr<DictionaryValue> requestMessageObject, ErrorSupport*);
451 : DispatchResponse::Status setSamplingInterval(int callId, std::unique_ptr<DictionaryValue> requestMessageObject, ErrorSupport*);
452 : DispatchResponse::Status start(int callId, std::unique_ptr<DictionaryValue> requestMessageObject, ErrorSupport*);
453 : DispatchResponse::Status stop(int callId, std::unique_ptr<DictionaryValue> requestMessageObject, ErrorSupport*);
454 : DispatchResponse::Status startPreciseCoverage(int callId, std::unique_ptr<DictionaryValue> requestMessageObject, ErrorSupport*);
455 : DispatchResponse::Status stopPreciseCoverage(int callId, std::unique_ptr<DictionaryValue> requestMessageObject, ErrorSupport*);
456 : DispatchResponse::Status takePreciseCoverage(int callId, std::unique_ptr<DictionaryValue> requestMessageObject, ErrorSupport*);
457 : DispatchResponse::Status getBestEffortCoverage(int callId, std::unique_ptr<DictionaryValue> requestMessageObject, ErrorSupport*);
458 :
459 : Backend* m_backend;
460 : bool m_fallThroughForNotFound;
461 : };
462 :
463 392 : DispatchResponse::Status DispatcherImpl::dispatch(int callId, const String& method, std::unique_ptr<protocol::DictionaryValue> messageObject)
464 : {
465 : protocol::HashMap<String, CallHandler>::iterator it = m_dispatchMap.find(method);
466 392 : if (it == m_dispatchMap.end()) {
467 0 : if (m_fallThroughForNotFound)
468 : return DispatchResponse::kFallThrough;
469 0 : reportProtocolError(callId, DispatchResponse::kMethodNotFound, "'" + method + "' wasn't found", nullptr);
470 0 : return DispatchResponse::kError;
471 : }
472 :
473 392 : protocol::ErrorSupport errors;
474 1176 : return (this->*(it->second))(callId, std::move(messageObject), &errors);
475 : }
476 :
477 :
478 80 : DispatchResponse::Status DispatcherImpl::enable(int callId, std::unique_ptr<DictionaryValue> requestMessageObject, ErrorSupport* errors)
479 : {
480 :
481 80 : std::unique_ptr<DispatcherBase::WeakPtr> weak = weakPtr();
482 80 : DispatchResponse response = m_backend->enable();
483 80 : if (weak->get())
484 80 : weak->get()->sendResponse(callId, response);
485 160 : return response.status();
486 : }
487 :
488 66 : DispatchResponse::Status DispatcherImpl::disable(int callId, std::unique_ptr<DictionaryValue> requestMessageObject, ErrorSupport* errors)
489 : {
490 :
491 66 : std::unique_ptr<DispatcherBase::WeakPtr> weak = weakPtr();
492 66 : DispatchResponse response = m_backend->disable();
493 66 : if (weak->get())
494 66 : weak->get()->sendResponse(callId, response);
495 132 : return response.status();
496 : }
497 :
498 0 : DispatchResponse::Status DispatcherImpl::setSamplingInterval(int callId, std::unique_ptr<DictionaryValue> requestMessageObject, ErrorSupport* errors)
499 : {
500 : // Prepare input parameters.
501 0 : protocol::DictionaryValue* object = DictionaryValue::cast(requestMessageObject->get("params"));
502 0 : errors->push();
503 0 : protocol::Value* intervalValue = object ? object->get("interval") : nullptr;
504 0 : errors->setName("interval");
505 0 : int in_interval = ValueConversions<int>::fromValue(intervalValue, errors);
506 0 : errors->pop();
507 0 : if (errors->hasErrors()) {
508 0 : reportProtocolError(callId, DispatchResponse::kInvalidParams, kInvalidParamsString, errors);
509 0 : return DispatchResponse::kError;
510 : }
511 :
512 0 : std::unique_ptr<DispatcherBase::WeakPtr> weak = weakPtr();
513 0 : DispatchResponse response = m_backend->setSamplingInterval(in_interval);
514 0 : if (weak->get())
515 0 : weak->get()->sendResponse(callId, response);
516 0 : return response.status();
517 : }
518 :
519 24 : DispatchResponse::Status DispatcherImpl::start(int callId, std::unique_ptr<DictionaryValue> requestMessageObject, ErrorSupport* errors)
520 : {
521 :
522 24 : std::unique_ptr<DispatcherBase::WeakPtr> weak = weakPtr();
523 24 : DispatchResponse response = m_backend->start();
524 24 : if (weak->get())
525 24 : weak->get()->sendResponse(callId, response);
526 48 : return response.status();
527 : }
528 :
529 24 : DispatchResponse::Status DispatcherImpl::stop(int callId, std::unique_ptr<DictionaryValue> requestMessageObject, ErrorSupport* errors)
530 : {
531 : // Declare output parameters.
532 24 : std::unique_ptr<protocol::Profiler::Profile> out_profile;
533 :
534 24 : std::unique_ptr<DispatcherBase::WeakPtr> weak = weakPtr();
535 24 : DispatchResponse response = m_backend->stop(&out_profile);
536 24 : if (response.status() == DispatchResponse::kFallThrough)
537 : return response.status();
538 24 : std::unique_ptr<protocol::DictionaryValue> result = DictionaryValue::create();
539 24 : if (response.status() == DispatchResponse::kSuccess) {
540 48 : result->setValue("profile", ValueConversions<protocol::Profiler::Profile>::toValue(out_profile.get()));
541 : }
542 24 : if (weak->get())
543 48 : weak->get()->sendResponse(callId, response, std::move(result));
544 24 : return response.status();
545 : }
546 :
547 48 : DispatchResponse::Status DispatcherImpl::startPreciseCoverage(int callId, std::unique_ptr<DictionaryValue> requestMessageObject, ErrorSupport* errors)
548 : {
549 : // Prepare input parameters.
550 144 : protocol::DictionaryValue* object = DictionaryValue::cast(requestMessageObject->get("params"));
551 48 : errors->push();
552 96 : protocol::Value* callCountValue = object ? object->get("callCount") : nullptr;
553 : Maybe<bool> in_callCount;
554 48 : if (callCountValue) {
555 60 : errors->setName("callCount");
556 30 : in_callCount = ValueConversions<bool>::fromValue(callCountValue, errors);
557 : }
558 48 : errors->pop();
559 48 : if (errors->hasErrors()) {
560 0 : reportProtocolError(callId, DispatchResponse::kInvalidParams, kInvalidParamsString, errors);
561 0 : return DispatchResponse::kError;
562 : }
563 :
564 48 : std::unique_ptr<DispatcherBase::WeakPtr> weak = weakPtr();
565 96 : DispatchResponse response = m_backend->startPreciseCoverage(std::move(in_callCount));
566 48 : if (weak->get())
567 48 : weak->get()->sendResponse(callId, response);
568 48 : return response.status();
569 : }
570 :
571 48 : DispatchResponse::Status DispatcherImpl::stopPreciseCoverage(int callId, std::unique_ptr<DictionaryValue> requestMessageObject, ErrorSupport* errors)
572 : {
573 :
574 48 : std::unique_ptr<DispatcherBase::WeakPtr> weak = weakPtr();
575 48 : DispatchResponse response = m_backend->stopPreciseCoverage();
576 48 : if (weak->get())
577 48 : weak->get()->sendResponse(callId, response);
578 96 : return response.status();
579 : }
580 :
581 66 : DispatchResponse::Status DispatcherImpl::takePreciseCoverage(int callId, std::unique_ptr<DictionaryValue> requestMessageObject, ErrorSupport* errors)
582 : {
583 : // Declare output parameters.
584 66 : std::unique_ptr<protocol::Array<protocol::Profiler::ScriptCoverage>> out_result;
585 :
586 66 : std::unique_ptr<DispatcherBase::WeakPtr> weak = weakPtr();
587 66 : DispatchResponse response = m_backend->takePreciseCoverage(&out_result);
588 66 : if (response.status() == DispatchResponse::kFallThrough)
589 : return response.status();
590 66 : std::unique_ptr<protocol::DictionaryValue> result = DictionaryValue::create();
591 66 : if (response.status() == DispatchResponse::kSuccess) {
592 240 : result->setValue("result", ValueConversions<protocol::Array<protocol::Profiler::ScriptCoverage>>::toValue(out_result.get()));
593 : }
594 66 : if (weak->get())
595 132 : weak->get()->sendResponse(callId, response, std::move(result));
596 66 : return response.status();
597 : }
598 :
599 36 : DispatchResponse::Status DispatcherImpl::getBestEffortCoverage(int callId, std::unique_ptr<DictionaryValue> requestMessageObject, ErrorSupport* errors)
600 : {
601 : // Declare output parameters.
602 36 : std::unique_ptr<protocol::Array<protocol::Profiler::ScriptCoverage>> out_result;
603 :
604 36 : std::unique_ptr<DispatcherBase::WeakPtr> weak = weakPtr();
605 36 : DispatchResponse response = m_backend->getBestEffortCoverage(&out_result);
606 36 : if (response.status() == DispatchResponse::kFallThrough)
607 : return response.status();
608 36 : std::unique_ptr<protocol::DictionaryValue> result = DictionaryValue::create();
609 36 : if (response.status() == DispatchResponse::kSuccess) {
610 144 : result->setValue("result", ValueConversions<protocol::Array<protocol::Profiler::ScriptCoverage>>::toValue(out_result.get()));
611 : }
612 36 : if (weak->get())
613 72 : weak->get()->sendResponse(callId, response, std::move(result));
614 36 : return response.status();
615 : }
616 :
617 : // static
618 4573 : void Dispatcher::wire(UberDispatcher* dispatcher, Backend* backend)
619 : {
620 18292 : dispatcher->registerBackend("Profiler", std::unique_ptr<protocol::DispatcherBase>(new DispatcherImpl(dispatcher->channel(), backend, dispatcher->fallThroughForNotFound())));
621 4573 : }
622 :
623 : } // Profiler
624 : } // namespace v8_inspector
625 : } // namespace protocol
|