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/HeapProfiler.h"
8 :
9 : #include "src/inspector/protocol/Protocol.h"
10 :
11 : namespace v8_inspector {
12 : namespace protocol {
13 : namespace HeapProfiler {
14 :
15 : // ------------- Enum values from types.
16 :
17 : const char Metainfo::domainName[] = "HeapProfiler";
18 : const char Metainfo::commandPrefix[] = "HeapProfiler.";
19 : const char Metainfo::version[] = "1.2";
20 :
21 0 : std::unique_ptr<SamplingHeapProfileNode> SamplingHeapProfileNode::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<SamplingHeapProfileNode> result(new SamplingHeapProfileNode());
29 : protocol::DictionaryValue* object = DictionaryValue::cast(value);
30 0 : errors->push();
31 0 : protocol::Value* callFrameValue = object->get("callFrame");
32 0 : errors->setName("callFrame");
33 0 : result->m_callFrame = ValueConversions<protocol::Runtime::CallFrame>::fromValue(callFrameValue, errors);
34 0 : protocol::Value* selfSizeValue = object->get("selfSize");
35 0 : errors->setName("selfSize");
36 0 : result->m_selfSize = ValueConversions<double>::fromValue(selfSizeValue, errors);
37 0 : protocol::Value* childrenValue = object->get("children");
38 0 : errors->setName("children");
39 0 : result->m_children = ValueConversions<protocol::Array<protocol::HeapProfiler::SamplingHeapProfileNode>>::fromValue(childrenValue, errors);
40 0 : errors->pop();
41 0 : if (errors->hasErrors())
42 : return nullptr;
43 : return result;
44 : }
45 :
46 0 : std::unique_ptr<protocol::DictionaryValue> SamplingHeapProfileNode::toValue() const
47 : {
48 0 : std::unique_ptr<protocol::DictionaryValue> result = DictionaryValue::create();
49 0 : result->setValue("callFrame", ValueConversions<protocol::Runtime::CallFrame>::toValue(m_callFrame.get()));
50 0 : result->setValue("selfSize", ValueConversions<double>::toValue(m_selfSize));
51 0 : result->setValue("children", ValueConversions<protocol::Array<protocol::HeapProfiler::SamplingHeapProfileNode>>::toValue(m_children.get()));
52 0 : return result;
53 : }
54 :
55 0 : std::unique_ptr<SamplingHeapProfileNode> SamplingHeapProfileNode::clone() const
56 : {
57 0 : ErrorSupport errors;
58 0 : return fromValue(toValue().get(), &errors);
59 : }
60 :
61 0 : std::unique_ptr<SamplingHeapProfile> SamplingHeapProfile::fromValue(protocol::Value* value, ErrorSupport* errors)
62 : {
63 0 : if (!value || value->type() != protocol::Value::TypeObject) {
64 0 : errors->addError("object expected");
65 : return nullptr;
66 : }
67 :
68 0 : std::unique_ptr<SamplingHeapProfile> result(new SamplingHeapProfile());
69 : protocol::DictionaryValue* object = DictionaryValue::cast(value);
70 0 : errors->push();
71 0 : protocol::Value* headValue = object->get("head");
72 0 : errors->setName("head");
73 0 : result->m_head = ValueConversions<protocol::HeapProfiler::SamplingHeapProfileNode>::fromValue(headValue, errors);
74 0 : errors->pop();
75 0 : if (errors->hasErrors())
76 : return nullptr;
77 : return result;
78 : }
79 :
80 0 : std::unique_ptr<protocol::DictionaryValue> SamplingHeapProfile::toValue() const
81 : {
82 0 : std::unique_ptr<protocol::DictionaryValue> result = DictionaryValue::create();
83 0 : result->setValue("head", ValueConversions<protocol::HeapProfiler::SamplingHeapProfileNode>::toValue(m_head.get()));
84 0 : return result;
85 : }
86 :
87 0 : std::unique_ptr<SamplingHeapProfile> SamplingHeapProfile::clone() const
88 : {
89 0 : ErrorSupport errors;
90 0 : return fromValue(toValue().get(), &errors);
91 : }
92 :
93 0 : std::unique_ptr<AddHeapSnapshotChunkNotification> AddHeapSnapshotChunkNotification::fromValue(protocol::Value* value, ErrorSupport* errors)
94 : {
95 0 : if (!value || value->type() != protocol::Value::TypeObject) {
96 0 : errors->addError("object expected");
97 : return nullptr;
98 : }
99 :
100 0 : std::unique_ptr<AddHeapSnapshotChunkNotification> result(new AddHeapSnapshotChunkNotification());
101 : protocol::DictionaryValue* object = DictionaryValue::cast(value);
102 0 : errors->push();
103 0 : protocol::Value* chunkValue = object->get("chunk");
104 0 : errors->setName("chunk");
105 0 : result->m_chunk = ValueConversions<String>::fromValue(chunkValue, errors);
106 0 : errors->pop();
107 0 : if (errors->hasErrors())
108 : return nullptr;
109 : return result;
110 : }
111 :
112 240 : std::unique_ptr<protocol::DictionaryValue> AddHeapSnapshotChunkNotification::toValue() const
113 : {
114 240 : std::unique_ptr<protocol::DictionaryValue> result = DictionaryValue::create();
115 1200 : result->setValue("chunk", ValueConversions<String>::toValue(m_chunk));
116 240 : return result;
117 : }
118 :
119 0 : std::unique_ptr<AddHeapSnapshotChunkNotification> AddHeapSnapshotChunkNotification::clone() const
120 : {
121 0 : ErrorSupport errors;
122 0 : return fromValue(toValue().get(), &errors);
123 : }
124 :
125 0 : std::unique_ptr<ReportHeapSnapshotProgressNotification> ReportHeapSnapshotProgressNotification::fromValue(protocol::Value* value, ErrorSupport* errors)
126 : {
127 0 : if (!value || value->type() != protocol::Value::TypeObject) {
128 0 : errors->addError("object expected");
129 : return nullptr;
130 : }
131 :
132 0 : std::unique_ptr<ReportHeapSnapshotProgressNotification> result(new ReportHeapSnapshotProgressNotification());
133 : protocol::DictionaryValue* object = DictionaryValue::cast(value);
134 0 : errors->push();
135 0 : protocol::Value* doneValue = object->get("done");
136 0 : errors->setName("done");
137 0 : result->m_done = ValueConversions<int>::fromValue(doneValue, errors);
138 0 : protocol::Value* totalValue = object->get("total");
139 0 : errors->setName("total");
140 0 : result->m_total = ValueConversions<int>::fromValue(totalValue, errors);
141 0 : protocol::Value* finishedValue = object->get("finished");
142 0 : if (finishedValue) {
143 0 : errors->setName("finished");
144 0 : result->m_finished = ValueConversions<bool>::fromValue(finishedValue, errors);
145 : }
146 0 : errors->pop();
147 0 : if (errors->hasErrors())
148 : return nullptr;
149 : return result;
150 : }
151 :
152 0 : std::unique_ptr<protocol::DictionaryValue> ReportHeapSnapshotProgressNotification::toValue() const
153 : {
154 0 : std::unique_ptr<protocol::DictionaryValue> result = DictionaryValue::create();
155 0 : result->setValue("done", ValueConversions<int>::toValue(m_done));
156 0 : result->setValue("total", ValueConversions<int>::toValue(m_total));
157 0 : if (m_finished.isJust())
158 0 : result->setValue("finished", ValueConversions<bool>::toValue(m_finished.fromJust()));
159 0 : return result;
160 : }
161 :
162 0 : std::unique_ptr<ReportHeapSnapshotProgressNotification> ReportHeapSnapshotProgressNotification::clone() const
163 : {
164 0 : ErrorSupport errors;
165 0 : return fromValue(toValue().get(), &errors);
166 : }
167 :
168 0 : std::unique_ptr<LastSeenObjectIdNotification> LastSeenObjectIdNotification::fromValue(protocol::Value* value, ErrorSupport* errors)
169 : {
170 0 : if (!value || value->type() != protocol::Value::TypeObject) {
171 0 : errors->addError("object expected");
172 : return nullptr;
173 : }
174 :
175 0 : std::unique_ptr<LastSeenObjectIdNotification> result(new LastSeenObjectIdNotification());
176 : protocol::DictionaryValue* object = DictionaryValue::cast(value);
177 0 : errors->push();
178 0 : protocol::Value* lastSeenObjectIdValue = object->get("lastSeenObjectId");
179 0 : errors->setName("lastSeenObjectId");
180 0 : result->m_lastSeenObjectId = ValueConversions<int>::fromValue(lastSeenObjectIdValue, errors);
181 0 : protocol::Value* timestampValue = object->get("timestamp");
182 0 : errors->setName("timestamp");
183 0 : result->m_timestamp = ValueConversions<double>::fromValue(timestampValue, errors);
184 0 : errors->pop();
185 0 : if (errors->hasErrors())
186 : return nullptr;
187 : return result;
188 : }
189 :
190 0 : std::unique_ptr<protocol::DictionaryValue> LastSeenObjectIdNotification::toValue() const
191 : {
192 0 : std::unique_ptr<protocol::DictionaryValue> result = DictionaryValue::create();
193 0 : result->setValue("lastSeenObjectId", ValueConversions<int>::toValue(m_lastSeenObjectId));
194 0 : result->setValue("timestamp", ValueConversions<double>::toValue(m_timestamp));
195 0 : return result;
196 : }
197 :
198 0 : std::unique_ptr<LastSeenObjectIdNotification> LastSeenObjectIdNotification::clone() const
199 : {
200 0 : ErrorSupport errors;
201 0 : return fromValue(toValue().get(), &errors);
202 : }
203 :
204 0 : std::unique_ptr<HeapStatsUpdateNotification> HeapStatsUpdateNotification::fromValue(protocol::Value* value, ErrorSupport* errors)
205 : {
206 0 : if (!value || value->type() != protocol::Value::TypeObject) {
207 0 : errors->addError("object expected");
208 : return nullptr;
209 : }
210 :
211 0 : std::unique_ptr<HeapStatsUpdateNotification> result(new HeapStatsUpdateNotification());
212 : protocol::DictionaryValue* object = DictionaryValue::cast(value);
213 0 : errors->push();
214 0 : protocol::Value* statsUpdateValue = object->get("statsUpdate");
215 0 : errors->setName("statsUpdate");
216 0 : result->m_statsUpdate = ValueConversions<protocol::Array<int>>::fromValue(statsUpdateValue, errors);
217 0 : errors->pop();
218 0 : if (errors->hasErrors())
219 : return nullptr;
220 : return result;
221 : }
222 :
223 0 : std::unique_ptr<protocol::DictionaryValue> HeapStatsUpdateNotification::toValue() const
224 : {
225 0 : std::unique_ptr<protocol::DictionaryValue> result = DictionaryValue::create();
226 0 : result->setValue("statsUpdate", ValueConversions<protocol::Array<int>>::toValue(m_statsUpdate.get()));
227 0 : return result;
228 : }
229 :
230 0 : std::unique_ptr<HeapStatsUpdateNotification> HeapStatsUpdateNotification::clone() const
231 : {
232 0 : ErrorSupport errors;
233 0 : return fromValue(toValue().get(), &errors);
234 : }
235 :
236 : // ------------- Enum values from params.
237 :
238 :
239 : // ------------- Frontend notifications.
240 :
241 240 : void Frontend::addHeapSnapshotChunk(const String& chunk)
242 : {
243 240 : if (!m_frontendChannel)
244 240 : return;
245 : std::unique_ptr<AddHeapSnapshotChunkNotification> messageData = AddHeapSnapshotChunkNotification::create()
246 240 : .setChunk(chunk)
247 : .build();
248 1680 : m_frontendChannel->sendProtocolNotification(InternalResponse::createNotification("HeapProfiler.addHeapSnapshotChunk", std::move(messageData)));
249 : }
250 :
251 0 : void Frontend::resetProfiles()
252 : {
253 0 : if (!m_frontendChannel)
254 0 : return;
255 0 : m_frontendChannel->sendProtocolNotification(InternalResponse::createNotification("HeapProfiler.resetProfiles"));
256 : }
257 :
258 0 : void Frontend::reportHeapSnapshotProgress(int done, int total, Maybe<bool> finished)
259 : {
260 0 : if (!m_frontendChannel)
261 0 : return;
262 : std::unique_ptr<ReportHeapSnapshotProgressNotification> messageData = ReportHeapSnapshotProgressNotification::create()
263 0 : .setDone(done)
264 : .setTotal(total)
265 : .build();
266 0 : if (finished.isJust())
267 0 : messageData->setFinished(std::move(finished).takeJust());
268 0 : m_frontendChannel->sendProtocolNotification(InternalResponse::createNotification("HeapProfiler.reportHeapSnapshotProgress", std::move(messageData)));
269 : }
270 :
271 0 : void Frontend::lastSeenObjectId(int lastSeenObjectId, double timestamp)
272 : {
273 0 : if (!m_frontendChannel)
274 0 : return;
275 : std::unique_ptr<LastSeenObjectIdNotification> messageData = LastSeenObjectIdNotification::create()
276 0 : .setLastSeenObjectId(lastSeenObjectId)
277 : .setTimestamp(timestamp)
278 : .build();
279 0 : m_frontendChannel->sendProtocolNotification(InternalResponse::createNotification("HeapProfiler.lastSeenObjectId", std::move(messageData)));
280 : }
281 :
282 0 : void Frontend::heapStatsUpdate(std::unique_ptr<protocol::Array<int>> statsUpdate)
283 : {
284 0 : if (!m_frontendChannel)
285 0 : return;
286 : std::unique_ptr<HeapStatsUpdateNotification> messageData = HeapStatsUpdateNotification::create()
287 : .setStatsUpdate(std::move(statsUpdate))
288 : .build();
289 0 : m_frontendChannel->sendProtocolNotification(InternalResponse::createNotification("HeapProfiler.heapStatsUpdate", std::move(messageData)));
290 : }
291 :
292 240 : void Frontend::flush()
293 : {
294 240 : m_frontendChannel->flushProtocolNotifications();
295 240 : }
296 :
297 0 : void Frontend::sendRawNotification(const String& notification)
298 : {
299 0 : m_frontendChannel->sendProtocolNotification(InternalRawNotification::create(notification));
300 0 : }
301 :
302 : // --------------------- Dispatcher.
303 :
304 : class DispatcherImpl : public protocol::DispatcherBase {
305 : public:
306 3406 : DispatcherImpl(FrontendChannel* frontendChannel, Backend* backend, bool fallThroughForNotFound)
307 : : DispatcherBase(frontendChannel)
308 : , m_backend(backend)
309 10218 : , m_fallThroughForNotFound(fallThroughForNotFound) {
310 10218 : m_dispatchMap["HeapProfiler.enable"] = &DispatcherImpl::enable;
311 10218 : m_dispatchMap["HeapProfiler.disable"] = &DispatcherImpl::disable;
312 10218 : m_dispatchMap["HeapProfiler.startTrackingHeapObjects"] = &DispatcherImpl::startTrackingHeapObjects;
313 10218 : m_dispatchMap["HeapProfiler.stopTrackingHeapObjects"] = &DispatcherImpl::stopTrackingHeapObjects;
314 10218 : m_dispatchMap["HeapProfiler.takeHeapSnapshot"] = &DispatcherImpl::takeHeapSnapshot;
315 10218 : m_dispatchMap["HeapProfiler.collectGarbage"] = &DispatcherImpl::collectGarbage;
316 10218 : m_dispatchMap["HeapProfiler.getObjectByHeapObjectId"] = &DispatcherImpl::getObjectByHeapObjectId;
317 10218 : m_dispatchMap["HeapProfiler.addInspectedHeapObject"] = &DispatcherImpl::addInspectedHeapObject;
318 10218 : m_dispatchMap["HeapProfiler.getHeapObjectId"] = &DispatcherImpl::getHeapObjectId;
319 10218 : m_dispatchMap["HeapProfiler.startSampling"] = &DispatcherImpl::startSampling;
320 10218 : m_dispatchMap["HeapProfiler.stopSampling"] = &DispatcherImpl::stopSampling;
321 3406 : }
322 10218 : ~DispatcherImpl() override { }
323 : DispatchResponse::Status dispatch(int callId, const String& method, std::unique_ptr<protocol::DictionaryValue> messageObject) override;
324 : HashMap<String, String>& redirects() { return m_redirects; }
325 :
326 : protected:
327 : using CallHandler = DispatchResponse::Status (DispatcherImpl::*)(int callId, std::unique_ptr<DictionaryValue> messageObject, ErrorSupport* errors);
328 : using DispatchMap = protocol::HashMap<String, CallHandler>;
329 : DispatchMap m_dispatchMap;
330 : HashMap<String, String> m_redirects;
331 :
332 : DispatchResponse::Status enable(int callId, std::unique_ptr<DictionaryValue> requestMessageObject, ErrorSupport*);
333 : DispatchResponse::Status disable(int callId, std::unique_ptr<DictionaryValue> requestMessageObject, ErrorSupport*);
334 : DispatchResponse::Status startTrackingHeapObjects(int callId, std::unique_ptr<DictionaryValue> requestMessageObject, ErrorSupport*);
335 : DispatchResponse::Status stopTrackingHeapObjects(int callId, std::unique_ptr<DictionaryValue> requestMessageObject, ErrorSupport*);
336 : DispatchResponse::Status takeHeapSnapshot(int callId, std::unique_ptr<DictionaryValue> requestMessageObject, ErrorSupport*);
337 : DispatchResponse::Status collectGarbage(int callId, std::unique_ptr<DictionaryValue> requestMessageObject, ErrorSupport*);
338 : DispatchResponse::Status getObjectByHeapObjectId(int callId, std::unique_ptr<DictionaryValue> requestMessageObject, ErrorSupport*);
339 : DispatchResponse::Status addInspectedHeapObject(int callId, std::unique_ptr<DictionaryValue> requestMessageObject, ErrorSupport*);
340 : DispatchResponse::Status getHeapObjectId(int callId, std::unique_ptr<DictionaryValue> requestMessageObject, ErrorSupport*);
341 : DispatchResponse::Status startSampling(int callId, std::unique_ptr<DictionaryValue> requestMessageObject, ErrorSupport*);
342 : DispatchResponse::Status stopSampling(int callId, std::unique_ptr<DictionaryValue> requestMessageObject, ErrorSupport*);
343 :
344 : Backend* m_backend;
345 : bool m_fallThroughForNotFound;
346 : };
347 :
348 270 : DispatchResponse::Status DispatcherImpl::dispatch(int callId, const String& method, std::unique_ptr<protocol::DictionaryValue> messageObject)
349 : {
350 : protocol::HashMap<String, CallHandler>::iterator it = m_dispatchMap.find(method);
351 270 : if (it == m_dispatchMap.end()) {
352 0 : if (m_fallThroughForNotFound)
353 : return DispatchResponse::kFallThrough;
354 0 : reportProtocolError(callId, DispatchResponse::kMethodNotFound, "'" + method + "' wasn't found", nullptr);
355 0 : return DispatchResponse::kError;
356 : }
357 :
358 270 : protocol::ErrorSupport errors;
359 810 : return (this->*(it->second))(callId, std::move(messageObject), &errors);
360 : }
361 :
362 :
363 10 : DispatchResponse::Status DispatcherImpl::enable(int callId, std::unique_ptr<DictionaryValue> requestMessageObject, ErrorSupport* errors)
364 : {
365 :
366 10 : std::unique_ptr<DispatcherBase::WeakPtr> weak = weakPtr();
367 10 : DispatchResponse response = m_backend->enable();
368 10 : if (response.status() == DispatchResponse::kFallThrough)
369 : return response.status();
370 10 : if (weak->get())
371 10 : weak->get()->sendResponse(callId, response);
372 10 : return response.status();
373 : }
374 :
375 0 : DispatchResponse::Status DispatcherImpl::disable(int callId, std::unique_ptr<DictionaryValue> requestMessageObject, ErrorSupport* errors)
376 : {
377 :
378 0 : std::unique_ptr<DispatcherBase::WeakPtr> weak = weakPtr();
379 0 : DispatchResponse response = m_backend->disable();
380 0 : if (response.status() == DispatchResponse::kFallThrough)
381 : return response.status();
382 0 : if (weak->get())
383 0 : weak->get()->sendResponse(callId, response);
384 0 : return response.status();
385 : }
386 :
387 0 : DispatchResponse::Status DispatcherImpl::startTrackingHeapObjects(int callId, std::unique_ptr<DictionaryValue> requestMessageObject, ErrorSupport* errors)
388 : {
389 : // Prepare input parameters.
390 0 : protocol::DictionaryValue* object = DictionaryValue::cast(requestMessageObject->get("params"));
391 0 : errors->push();
392 0 : protocol::Value* trackAllocationsValue = object ? object->get("trackAllocations") : nullptr;
393 : Maybe<bool> in_trackAllocations;
394 0 : if (trackAllocationsValue) {
395 0 : errors->setName("trackAllocations");
396 0 : in_trackAllocations = ValueConversions<bool>::fromValue(trackAllocationsValue, errors);
397 : }
398 0 : errors->pop();
399 0 : if (errors->hasErrors()) {
400 0 : reportProtocolError(callId, DispatchResponse::kInvalidParams, kInvalidParamsString, errors);
401 0 : return DispatchResponse::kError;
402 : }
403 :
404 0 : std::unique_ptr<DispatcherBase::WeakPtr> weak = weakPtr();
405 0 : DispatchResponse response = m_backend->startTrackingHeapObjects(std::move(in_trackAllocations));
406 0 : if (response.status() == DispatchResponse::kFallThrough)
407 : return response.status();
408 0 : if (weak->get())
409 0 : weak->get()->sendResponse(callId, response);
410 0 : return response.status();
411 : }
412 :
413 0 : DispatchResponse::Status DispatcherImpl::stopTrackingHeapObjects(int callId, std::unique_ptr<DictionaryValue> requestMessageObject, ErrorSupport* errors)
414 : {
415 : // Prepare input parameters.
416 0 : protocol::DictionaryValue* object = DictionaryValue::cast(requestMessageObject->get("params"));
417 0 : errors->push();
418 0 : protocol::Value* reportProgressValue = object ? object->get("reportProgress") : nullptr;
419 : Maybe<bool> in_reportProgress;
420 0 : if (reportProgressValue) {
421 0 : errors->setName("reportProgress");
422 0 : in_reportProgress = ValueConversions<bool>::fromValue(reportProgressValue, errors);
423 : }
424 0 : errors->pop();
425 0 : if (errors->hasErrors()) {
426 0 : reportProtocolError(callId, DispatchResponse::kInvalidParams, kInvalidParamsString, errors);
427 0 : return DispatchResponse::kError;
428 : }
429 :
430 0 : std::unique_ptr<DispatcherBase::WeakPtr> weak = weakPtr();
431 0 : DispatchResponse response = m_backend->stopTrackingHeapObjects(std::move(in_reportProgress));
432 0 : if (response.status() == DispatchResponse::kFallThrough)
433 : return response.status();
434 0 : if (weak->get())
435 0 : weak->get()->sendResponse(callId, response);
436 0 : return response.status();
437 : }
438 :
439 20 : DispatchResponse::Status DispatcherImpl::takeHeapSnapshot(int callId, std::unique_ptr<DictionaryValue> requestMessageObject, ErrorSupport* errors)
440 : {
441 : // Prepare input parameters.
442 60 : protocol::DictionaryValue* object = DictionaryValue::cast(requestMessageObject->get("params"));
443 20 : errors->push();
444 40 : protocol::Value* reportProgressValue = object ? object->get("reportProgress") : nullptr;
445 : Maybe<bool> in_reportProgress;
446 20 : if (reportProgressValue) {
447 10 : errors->setName("reportProgress");
448 10 : in_reportProgress = ValueConversions<bool>::fromValue(reportProgressValue, errors);
449 : }
450 20 : errors->pop();
451 20 : if (errors->hasErrors()) {
452 0 : reportProtocolError(callId, DispatchResponse::kInvalidParams, kInvalidParamsString, errors);
453 0 : return DispatchResponse::kError;
454 : }
455 :
456 20 : std::unique_ptr<DispatcherBase::WeakPtr> weak = weakPtr();
457 40 : DispatchResponse response = m_backend->takeHeapSnapshot(std::move(in_reportProgress));
458 20 : if (response.status() == DispatchResponse::kFallThrough)
459 : return response.status();
460 20 : if (weak->get())
461 20 : weak->get()->sendResponse(callId, response);
462 20 : return response.status();
463 : }
464 :
465 240 : DispatchResponse::Status DispatcherImpl::collectGarbage(int callId, std::unique_ptr<DictionaryValue> requestMessageObject, ErrorSupport* errors)
466 : {
467 :
468 240 : std::unique_ptr<DispatcherBase::WeakPtr> weak = weakPtr();
469 240 : DispatchResponse response = m_backend->collectGarbage();
470 240 : if (response.status() == DispatchResponse::kFallThrough)
471 : return response.status();
472 240 : if (weak->get())
473 240 : weak->get()->sendResponse(callId, response);
474 240 : return response.status();
475 : }
476 :
477 0 : DispatchResponse::Status DispatcherImpl::getObjectByHeapObjectId(int callId, std::unique_ptr<DictionaryValue> requestMessageObject, ErrorSupport* errors)
478 : {
479 : // Prepare input parameters.
480 0 : protocol::DictionaryValue* object = DictionaryValue::cast(requestMessageObject->get("params"));
481 0 : errors->push();
482 0 : protocol::Value* objectIdValue = object ? object->get("objectId") : nullptr;
483 0 : errors->setName("objectId");
484 0 : String in_objectId = ValueConversions<String>::fromValue(objectIdValue, errors);
485 0 : protocol::Value* objectGroupValue = object ? object->get("objectGroup") : nullptr;
486 : Maybe<String> in_objectGroup;
487 0 : if (objectGroupValue) {
488 0 : errors->setName("objectGroup");
489 0 : in_objectGroup = ValueConversions<String>::fromValue(objectGroupValue, errors);
490 : }
491 0 : errors->pop();
492 0 : if (errors->hasErrors()) {
493 0 : reportProtocolError(callId, DispatchResponse::kInvalidParams, kInvalidParamsString, errors);
494 0 : return DispatchResponse::kError;
495 : }
496 : // Declare output parameters.
497 0 : std::unique_ptr<protocol::Runtime::RemoteObject> out_result;
498 :
499 0 : std::unique_ptr<DispatcherBase::WeakPtr> weak = weakPtr();
500 0 : DispatchResponse response = m_backend->getObjectByHeapObjectId(in_objectId, std::move(in_objectGroup), &out_result);
501 0 : if (response.status() == DispatchResponse::kFallThrough)
502 : return response.status();
503 0 : std::unique_ptr<protocol::DictionaryValue> result = DictionaryValue::create();
504 0 : if (response.status() == DispatchResponse::kSuccess) {
505 0 : result->setValue("result", ValueConversions<protocol::Runtime::RemoteObject>::toValue(out_result.get()));
506 : }
507 0 : if (weak->get())
508 0 : weak->get()->sendResponse(callId, response, std::move(result));
509 0 : return response.status();
510 : }
511 :
512 0 : DispatchResponse::Status DispatcherImpl::addInspectedHeapObject(int callId, std::unique_ptr<DictionaryValue> requestMessageObject, ErrorSupport* errors)
513 : {
514 : // Prepare input parameters.
515 0 : protocol::DictionaryValue* object = DictionaryValue::cast(requestMessageObject->get("params"));
516 0 : errors->push();
517 0 : protocol::Value* heapObjectIdValue = object ? object->get("heapObjectId") : nullptr;
518 0 : errors->setName("heapObjectId");
519 0 : String in_heapObjectId = ValueConversions<String>::fromValue(heapObjectIdValue, errors);
520 0 : errors->pop();
521 0 : if (errors->hasErrors()) {
522 0 : reportProtocolError(callId, DispatchResponse::kInvalidParams, kInvalidParamsString, errors);
523 0 : return DispatchResponse::kError;
524 : }
525 :
526 0 : std::unique_ptr<DispatcherBase::WeakPtr> weak = weakPtr();
527 0 : DispatchResponse response = m_backend->addInspectedHeapObject(in_heapObjectId);
528 0 : if (response.status() == DispatchResponse::kFallThrough)
529 : return response.status();
530 0 : if (weak->get())
531 0 : weak->get()->sendResponse(callId, response);
532 0 : return response.status();
533 : }
534 :
535 0 : DispatchResponse::Status DispatcherImpl::getHeapObjectId(int callId, std::unique_ptr<DictionaryValue> requestMessageObject, ErrorSupport* errors)
536 : {
537 : // Prepare input parameters.
538 0 : protocol::DictionaryValue* object = DictionaryValue::cast(requestMessageObject->get("params"));
539 0 : errors->push();
540 0 : protocol::Value* objectIdValue = object ? object->get("objectId") : nullptr;
541 0 : errors->setName("objectId");
542 0 : String in_objectId = ValueConversions<String>::fromValue(objectIdValue, errors);
543 0 : errors->pop();
544 0 : if (errors->hasErrors()) {
545 0 : reportProtocolError(callId, DispatchResponse::kInvalidParams, kInvalidParamsString, errors);
546 0 : return DispatchResponse::kError;
547 : }
548 : // Declare output parameters.
549 0 : String out_heapSnapshotObjectId;
550 :
551 0 : std::unique_ptr<DispatcherBase::WeakPtr> weak = weakPtr();
552 0 : DispatchResponse response = m_backend->getHeapObjectId(in_objectId, &out_heapSnapshotObjectId);
553 0 : if (response.status() == DispatchResponse::kFallThrough)
554 : return response.status();
555 0 : std::unique_ptr<protocol::DictionaryValue> result = DictionaryValue::create();
556 0 : if (response.status() == DispatchResponse::kSuccess) {
557 0 : result->setValue("heapSnapshotObjectId", ValueConversions<String>::toValue(out_heapSnapshotObjectId));
558 : }
559 0 : if (weak->get())
560 0 : weak->get()->sendResponse(callId, response, std::move(result));
561 0 : return response.status();
562 : }
563 :
564 0 : DispatchResponse::Status DispatcherImpl::startSampling(int callId, std::unique_ptr<DictionaryValue> requestMessageObject, ErrorSupport* errors)
565 : {
566 : // Prepare input parameters.
567 0 : protocol::DictionaryValue* object = DictionaryValue::cast(requestMessageObject->get("params"));
568 0 : errors->push();
569 0 : protocol::Value* samplingIntervalValue = object ? object->get("samplingInterval") : nullptr;
570 : Maybe<double> in_samplingInterval;
571 0 : if (samplingIntervalValue) {
572 0 : errors->setName("samplingInterval");
573 0 : in_samplingInterval = ValueConversions<double>::fromValue(samplingIntervalValue, errors);
574 : }
575 0 : errors->pop();
576 0 : if (errors->hasErrors()) {
577 0 : reportProtocolError(callId, DispatchResponse::kInvalidParams, kInvalidParamsString, errors);
578 0 : return DispatchResponse::kError;
579 : }
580 :
581 0 : std::unique_ptr<DispatcherBase::WeakPtr> weak = weakPtr();
582 0 : DispatchResponse response = m_backend->startSampling(std::move(in_samplingInterval));
583 0 : if (response.status() == DispatchResponse::kFallThrough)
584 : return response.status();
585 0 : if (weak->get())
586 0 : weak->get()->sendResponse(callId, response);
587 0 : return response.status();
588 : }
589 :
590 0 : DispatchResponse::Status DispatcherImpl::stopSampling(int callId, std::unique_ptr<DictionaryValue> requestMessageObject, ErrorSupport* errors)
591 : {
592 : // Declare output parameters.
593 0 : std::unique_ptr<protocol::HeapProfiler::SamplingHeapProfile> out_profile;
594 :
595 0 : std::unique_ptr<DispatcherBase::WeakPtr> weak = weakPtr();
596 0 : DispatchResponse response = m_backend->stopSampling(&out_profile);
597 0 : if (response.status() == DispatchResponse::kFallThrough)
598 : return response.status();
599 0 : std::unique_ptr<protocol::DictionaryValue> result = DictionaryValue::create();
600 0 : if (response.status() == DispatchResponse::kSuccess) {
601 0 : result->setValue("profile", ValueConversions<protocol::HeapProfiler::SamplingHeapProfile>::toValue(out_profile.get()));
602 : }
603 0 : if (weak->get())
604 0 : weak->get()->sendResponse(callId, response, std::move(result));
605 0 : return response.status();
606 : }
607 :
608 : // static
609 3406 : void Dispatcher::wire(UberDispatcher* uber, Backend* backend)
610 : {
611 3406 : std::unique_ptr<DispatcherImpl> dispatcher(new DispatcherImpl(uber->channel(), backend, uber->fallThroughForNotFound()));
612 3406 : uber->setupRedirects(dispatcher->redirects());
613 10218 : uber->registerBackend("HeapProfiler", std::move(dispatcher));
614 3406 : }
615 :
616 : } // HeapProfiler
617 : } // namespace v8_inspector
618 : } // namespace protocol
|