GCC Code Coverage Report
Directory: ../ Exec Total Coverage
File: /home/iojs/build/workspace/node-test-commit-linux-coverage-daily/nodes/benchmark/out/Release/obj/gen/src/node/inspector/protocol/NodeWorker.cpp Lines: 116 222 52.3 %
Date: 2019-07-27 22:37:30 Branches: 28 88 31.8 %

Line Branch Exec Source
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/node/inspector/protocol/NodeWorker.h"
8
9
#include "src/node/inspector/protocol/Protocol.h"
10
11
namespace node {
12
namespace inspector {
13
namespace protocol {
14
namespace NodeWorker {
15
16
// ------------- Enum values from types.
17
18
const char Metainfo::domainName[] = "NodeWorker";
19
const char Metainfo::commandPrefix[] = "NodeWorker.";
20
const char Metainfo::version[] = "1.0";
21
22
std::unique_ptr<WorkerInfo> WorkerInfo::fromValue(protocol::Value* value, ErrorSupport* errors)
23
{
24
    if (!value || value->type() != protocol::Value::TypeObject) {
25
        errors->addError("object expected");
26
        return nullptr;
27
    }
28
29
    std::unique_ptr<WorkerInfo> result(new WorkerInfo());
30
    protocol::DictionaryValue* object = DictionaryValue::cast(value);
31
    errors->push();
32
    protocol::Value* workerIdValue = object->get("workerId");
33
    errors->setName("workerId");
34
    result->m_workerId = ValueConversions<String>::fromValue(workerIdValue, errors);
35
    protocol::Value* typeValue = object->get("type");
36
    errors->setName("type");
37
    result->m_type = ValueConversions<String>::fromValue(typeValue, errors);
38
    protocol::Value* titleValue = object->get("title");
39
    errors->setName("title");
40
    result->m_title = ValueConversions<String>::fromValue(titleValue, errors);
41
    protocol::Value* urlValue = object->get("url");
42
    errors->setName("url");
43
    result->m_url = ValueConversions<String>::fromValue(urlValue, errors);
44
    errors->pop();
45
    if (errors->hasErrors())
46
        return nullptr;
47
    return result;
48
}
49
50
7
std::unique_ptr<protocol::DictionaryValue> WorkerInfo::toValue() const
51
{
52
7
    std::unique_ptr<protocol::DictionaryValue> result = DictionaryValue::create();
53
7
    result->setValue("workerId", ValueConversions<String>::toValue(m_workerId));
54
7
    result->setValue("type", ValueConversions<String>::toValue(m_type));
55
7
    result->setValue("title", ValueConversions<String>::toValue(m_title));
56
7
    result->setValue("url", ValueConversions<String>::toValue(m_url));
57
7
    return result;
58
}
59
60
std::unique_ptr<WorkerInfo> WorkerInfo::clone() const
61
{
62
    ErrorSupport errors;
63
    return fromValue(toValue().get(), &errors);
64
}
65
66
std::unique_ptr<AttachedToWorkerNotification> AttachedToWorkerNotification::fromValue(protocol::Value* value, ErrorSupport* errors)
67
{
68
    if (!value || value->type() != protocol::Value::TypeObject) {
69
        errors->addError("object expected");
70
        return nullptr;
71
    }
72
73
    std::unique_ptr<AttachedToWorkerNotification> result(new AttachedToWorkerNotification());
74
    protocol::DictionaryValue* object = DictionaryValue::cast(value);
75
    errors->push();
76
    protocol::Value* sessionIdValue = object->get("sessionId");
77
    errors->setName("sessionId");
78
    result->m_sessionId = ValueConversions<String>::fromValue(sessionIdValue, errors);
79
    protocol::Value* workerInfoValue = object->get("workerInfo");
80
    errors->setName("workerInfo");
81
    result->m_workerInfo = ValueConversions<protocol::NodeWorker::WorkerInfo>::fromValue(workerInfoValue, errors);
82
    protocol::Value* waitingForDebuggerValue = object->get("waitingForDebugger");
83
    errors->setName("waitingForDebugger");
84
    result->m_waitingForDebugger = ValueConversions<bool>::fromValue(waitingForDebuggerValue, errors);
85
    errors->pop();
86
    if (errors->hasErrors())
87
        return nullptr;
88
    return result;
89
}
90
91
7
std::unique_ptr<protocol::DictionaryValue> AttachedToWorkerNotification::toValue() const
92
{
93
7
    std::unique_ptr<protocol::DictionaryValue> result = DictionaryValue::create();
94
7
    result->setValue("sessionId", ValueConversions<String>::toValue(m_sessionId));
95
7
    result->setValue("workerInfo", ValueConversions<protocol::NodeWorker::WorkerInfo>::toValue(m_workerInfo.get()));
96
7
    result->setValue("waitingForDebugger", ValueConversions<bool>::toValue(m_waitingForDebugger));
97
7
    return result;
98
}
99
100
std::unique_ptr<AttachedToWorkerNotification> AttachedToWorkerNotification::clone() const
101
{
102
    ErrorSupport errors;
103
    return fromValue(toValue().get(), &errors);
104
}
105
106
std::unique_ptr<DetachedFromWorkerNotification> DetachedFromWorkerNotification::fromValue(protocol::Value* value, ErrorSupport* errors)
107
{
108
    if (!value || value->type() != protocol::Value::TypeObject) {
109
        errors->addError("object expected");
110
        return nullptr;
111
    }
112
113
    std::unique_ptr<DetachedFromWorkerNotification> result(new DetachedFromWorkerNotification());
114
    protocol::DictionaryValue* object = DictionaryValue::cast(value);
115
    errors->push();
116
    protocol::Value* sessionIdValue = object->get("sessionId");
117
    errors->setName("sessionId");
118
    result->m_sessionId = ValueConversions<String>::fromValue(sessionIdValue, errors);
119
    errors->pop();
120
    if (errors->hasErrors())
121
        return nullptr;
122
    return result;
123
}
124
125
7
std::unique_ptr<protocol::DictionaryValue> DetachedFromWorkerNotification::toValue() const
126
{
127
7
    std::unique_ptr<protocol::DictionaryValue> result = DictionaryValue::create();
128
7
    result->setValue("sessionId", ValueConversions<String>::toValue(m_sessionId));
129
7
    return result;
130
}
131
132
std::unique_ptr<DetachedFromWorkerNotification> DetachedFromWorkerNotification::clone() const
133
{
134
    ErrorSupport errors;
135
    return fromValue(toValue().get(), &errors);
136
}
137
138
std::unique_ptr<ReceivedMessageFromWorkerNotification> ReceivedMessageFromWorkerNotification::fromValue(protocol::Value* value, ErrorSupport* errors)
139
{
140
    if (!value || value->type() != protocol::Value::TypeObject) {
141
        errors->addError("object expected");
142
        return nullptr;
143
    }
144
145
    std::unique_ptr<ReceivedMessageFromWorkerNotification> result(new ReceivedMessageFromWorkerNotification());
146
    protocol::DictionaryValue* object = DictionaryValue::cast(value);
147
    errors->push();
148
    protocol::Value* sessionIdValue = object->get("sessionId");
149
    errors->setName("sessionId");
150
    result->m_sessionId = ValueConversions<String>::fromValue(sessionIdValue, errors);
151
    protocol::Value* messageValue = object->get("message");
152
    errors->setName("message");
153
    result->m_message = ValueConversions<String>::fromValue(messageValue, errors);
154
    errors->pop();
155
    if (errors->hasErrors())
156
        return nullptr;
157
    return result;
158
}
159
160
164
std::unique_ptr<protocol::DictionaryValue> ReceivedMessageFromWorkerNotification::toValue() const
161
{
162
164
    std::unique_ptr<protocol::DictionaryValue> result = DictionaryValue::create();
163
164
    result->setValue("sessionId", ValueConversions<String>::toValue(m_sessionId));
164
164
    result->setValue("message", ValueConversions<String>::toValue(m_message));
165
164
    return result;
166
}
167
168
std::unique_ptr<ReceivedMessageFromWorkerNotification> ReceivedMessageFromWorkerNotification::clone() const
169
{
170
    ErrorSupport errors;
171
    return fromValue(toValue().get(), &errors);
172
}
173
174
// ------------- Enum values from params.
175
176
177
// ------------- Frontend notifications.
178
179
7
void Frontend::attachedToWorker(const String& sessionId, std::unique_ptr<protocol::NodeWorker::WorkerInfo> workerInfo, bool waitingForDebugger)
180
{
181
7
    if (!m_frontendChannel)
182
7
        return;
183
    std::unique_ptr<AttachedToWorkerNotification> messageData = AttachedToWorkerNotification::create()
184
14
        .setSessionId(sessionId)
185
21
        .setWorkerInfo(std::move(workerInfo))
186
14
        .setWaitingForDebugger(waitingForDebugger)
187
14
        .build();
188
7
    m_frontendChannel->sendProtocolNotification(InternalResponse::createNotification("NodeWorker.attachedToWorker", std::move(messageData)));
189
}
190
191
7
void Frontend::detachedFromWorker(const String& sessionId)
192
{
193
7
    if (!m_frontendChannel)
194
7
        return;
195
    std::unique_ptr<DetachedFromWorkerNotification> messageData = DetachedFromWorkerNotification::create()
196
14
        .setSessionId(sessionId)
197
7
        .build();
198
7
    m_frontendChannel->sendProtocolNotification(InternalResponse::createNotification("NodeWorker.detachedFromWorker", std::move(messageData)));
199
}
200
201
164
void Frontend::receivedMessageFromWorker(const String& sessionId, const String& message)
202
{
203
164
    if (!m_frontendChannel)
204
164
        return;
205
    std::unique_ptr<ReceivedMessageFromWorkerNotification> messageData = ReceivedMessageFromWorkerNotification::create()
206
328
        .setSessionId(sessionId)
207
164
        .setMessage(message)
208
164
        .build();
209
164
    m_frontendChannel->sendProtocolNotification(InternalResponse::createNotification("NodeWorker.receivedMessageFromWorker", std::move(messageData)));
210
}
211
212
void Frontend::flush()
213
{
214
    m_frontendChannel->flushProtocolNotifications();
215
}
216
217
void Frontend::sendRawJSONNotification(String notification)
218
{
219
    m_frontendChannel->sendProtocolNotification(InternalRawNotification::fromJSON(std::move(notification)));
220
}
221
222
void Frontend::sendRawCBORNotification(std::vector<uint8_t> notification)
223
{
224
    m_frontendChannel->sendProtocolNotification(InternalRawNotification::fromBinary(std::move(notification)));
225
}
226
227
// --------------------- Dispatcher.
228
229
class DispatcherImpl : public protocol::DispatcherBase {
230
public:
231
5208
    DispatcherImpl(FrontendChannel* frontendChannel, Backend* backend)
232
        : DispatcherBase(frontendChannel)
233
5208
        , m_backend(backend) {
234
5209
        m_dispatchMap["NodeWorker.sendMessageToWorker"] = &DispatcherImpl::sendMessageToWorker;
235
5209
        m_dispatchMap["NodeWorker.enable"] = &DispatcherImpl::enable;
236
5208
        m_dispatchMap["NodeWorker.disable"] = &DispatcherImpl::disable;
237
5209
        m_dispatchMap["NodeWorker.detach"] = &DispatcherImpl::detach;
238
5209
    }
239
9624
    ~DispatcherImpl() override { }
240
    bool canDispatch(const String& method) override;
241
    void dispatch(int callId, const String& method, const ProtocolMessage& message, std::unique_ptr<protocol::DictionaryValue> messageObject) override;
242
5208
    std::unordered_map<String, String>& redirects() { return m_redirects; }
243
244
protected:
245
    using CallHandler = void (DispatcherImpl::*)(int callId, const String& method, const ProtocolMessage& message, std::unique_ptr<DictionaryValue> messageObject, ErrorSupport* errors);
246
    using DispatchMap = std::unordered_map<String, CallHandler>;
247
    DispatchMap m_dispatchMap;
248
    std::unordered_map<String, String> m_redirects;
249
250
    void sendMessageToWorker(int callId, const String& method, const ProtocolMessage& message, std::unique_ptr<DictionaryValue> requestMessageObject, ErrorSupport*);
251
    void enable(int callId, const String& method, const ProtocolMessage& message, std::unique_ptr<DictionaryValue> requestMessageObject, ErrorSupport*);
252
    void disable(int callId, const String& method, const ProtocolMessage& message, std::unique_ptr<DictionaryValue> requestMessageObject, ErrorSupport*);
253
    void detach(int callId, const String& method, const ProtocolMessage& message, std::unique_ptr<DictionaryValue> requestMessageObject, ErrorSupport*);
254
255
    Backend* m_backend;
256
};
257
258
26
bool DispatcherImpl::canDispatch(const String& method) {
259
26
    return m_dispatchMap.find(method) != m_dispatchMap.end();
260
}
261
262
26
void DispatcherImpl::dispatch(int callId, const String& method, const ProtocolMessage& message, std::unique_ptr<protocol::DictionaryValue> messageObject)
263
{
264
26
    std::unordered_map<String, CallHandler>::iterator it = m_dispatchMap.find(method);
265
    DCHECK(it != m_dispatchMap.end());
266
26
    protocol::ErrorSupport errors;
267
26
    (this->*(it->second))(callId, method, message, std::move(messageObject), &errors);
268
26
}
269
270
271
14
void DispatcherImpl::sendMessageToWorker(int callId, const String& method, const ProtocolMessage& message, std::unique_ptr<DictionaryValue> requestMessageObject, ErrorSupport* errors)
272
{
273
    // Prepare input parameters.
274
14
    protocol::DictionaryValue* object = DictionaryValue::cast(requestMessageObject->get("params"));
275
14
    errors->push();
276

14
    protocol::Value* messageValue = object ? object->get("message") : nullptr;
277
14
    errors->setName("message");
278
14
    String in_message = ValueConversions<String>::fromValue(messageValue, errors);
279

14
    protocol::Value* sessionIdValue = object ? object->get("sessionId") : nullptr;
280
14
    errors->setName("sessionId");
281
28
    String in_sessionId = ValueConversions<String>::fromValue(sessionIdValue, errors);
282
14
    errors->pop();
283
14
    if (errors->hasErrors()) {
284
        reportProtocolError(callId, DispatchResponse::kInvalidParams, kInvalidParamsString, errors);
285
        return;
286
    }
287
288
28
    std::unique_ptr<DispatcherBase::WeakPtr> weak = weakPtr();
289
28
    DispatchResponse response = m_backend->sendMessageToWorker(in_message, in_sessionId);
290
14
    if (response.status() == DispatchResponse::kFallThrough) {
291
        channel()->fallThrough(callId, method, message);
292
        return;
293
    }
294
14
    if (weak->get())
295
14
        weak->get()->sendResponse(callId, response);
296
28
    return;
297
}
298
299
6
void DispatcherImpl::enable(int callId, const String& method, const ProtocolMessage& message, std::unique_ptr<DictionaryValue> requestMessageObject, ErrorSupport* errors)
300
{
301
    // Prepare input parameters.
302
6
    protocol::DictionaryValue* object = DictionaryValue::cast(requestMessageObject->get("params"));
303
6
    errors->push();
304

6
    protocol::Value* waitForDebuggerOnStartValue = object ? object->get("waitForDebuggerOnStart") : nullptr;
305
6
    errors->setName("waitForDebuggerOnStart");
306
6
    bool in_waitForDebuggerOnStart = ValueConversions<bool>::fromValue(waitForDebuggerOnStartValue, errors);
307
6
    errors->pop();
308
6
    if (errors->hasErrors()) {
309
        reportProtocolError(callId, DispatchResponse::kInvalidParams, kInvalidParamsString, errors);
310
        return;
311
    }
312
313
6
    std::unique_ptr<DispatcherBase::WeakPtr> weak = weakPtr();
314
12
    DispatchResponse response = m_backend->enable(in_waitForDebuggerOnStart);
315
6
    if (response.status() == DispatchResponse::kFallThrough) {
316
        channel()->fallThrough(callId, method, message);
317
        return;
318
    }
319
6
    if (weak->get())
320
6
        weak->get()->sendResponse(callId, response);
321
12
    return;
322
}
323
324
4
void DispatcherImpl::disable(int callId, const String& method, const ProtocolMessage& message, std::unique_ptr<DictionaryValue> requestMessageObject, ErrorSupport* errors)
325
{
326
327
4
    std::unique_ptr<DispatcherBase::WeakPtr> weak = weakPtr();
328
8
    DispatchResponse response = m_backend->disable();
329
4
    if (response.status() == DispatchResponse::kFallThrough) {
330
        channel()->fallThrough(callId, method, message);
331
        return;
332
    }
333
4
    if (weak->get())
334
4
        weak->get()->sendResponse(callId, response);
335
8
    return;
336
}
337
338
2
void DispatcherImpl::detach(int callId, const String& method, const ProtocolMessage& message, std::unique_ptr<DictionaryValue> requestMessageObject, ErrorSupport* errors)
339
{
340
    // Prepare input parameters.
341
2
    protocol::DictionaryValue* object = DictionaryValue::cast(requestMessageObject->get("params"));
342
2
    errors->push();
343

2
    protocol::Value* sessionIdValue = object ? object->get("sessionId") : nullptr;
344
2
    errors->setName("sessionId");
345
2
    String in_sessionId = ValueConversions<String>::fromValue(sessionIdValue, errors);
346
2
    errors->pop();
347
2
    if (errors->hasErrors()) {
348
        reportProtocolError(callId, DispatchResponse::kInvalidParams, kInvalidParamsString, errors);
349
        return;
350
    }
351
352
4
    std::unique_ptr<DispatcherBase::WeakPtr> weak = weakPtr();
353
4
    DispatchResponse response = m_backend->detach(in_sessionId);
354
2
    if (response.status() == DispatchResponse::kFallThrough) {
355
        channel()->fallThrough(callId, method, message);
356
        return;
357
    }
358
2
    if (weak->get())
359
2
        weak->get()->sendResponse(callId, response);
360
4
    return;
361
}
362
363
// static
364
5208
void Dispatcher::wire(UberDispatcher* uber, Backend* backend)
365
{
366
5208
    std::unique_ptr<DispatcherImpl> dispatcher(new DispatcherImpl(uber->channel(), backend));
367
5208
    uber->setupRedirects(dispatcher->redirects());
368
5209
    uber->registerBackend("NodeWorker", std::move(dispatcher));
369
5209
}
370
371
} // NodeWorker
372
} // namespace node
373
} // namespace inspector
374
} // namespace protocol