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: 99 200 49.5 %
Date: 2019-02-13 22:28:58 Branches: 23 80 28.8 %

Line Branch Exec Source
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/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
4
std::unique_ptr<protocol::DictionaryValue> WorkerInfo::toValue() const
51
{
52
4
    std::unique_ptr<protocol::DictionaryValue> result = DictionaryValue::create();
53
4
    result->setValue("workerId", ValueConversions<String>::toValue(m_workerId));
54
4
    result->setValue("type", ValueConversions<String>::toValue(m_type));
55
4
    result->setValue("title", ValueConversions<String>::toValue(m_title));
56
4
    result->setValue("url", ValueConversions<String>::toValue(m_url));
57
4
    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
4
std::unique_ptr<protocol::DictionaryValue> AttachedToWorkerNotification::toValue() const
92
{
93
4
    std::unique_ptr<protocol::DictionaryValue> result = DictionaryValue::create();
94
4
    result->setValue("sessionId", ValueConversions<String>::toValue(m_sessionId));
95
4
    result->setValue("workerInfo", ValueConversions<protocol::NodeWorker::WorkerInfo>::toValue(m_workerInfo.get()));
96
4
    result->setValue("waitingForDebugger", ValueConversions<bool>::toValue(m_waitingForDebugger));
97
4
    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
4
std::unique_ptr<protocol::DictionaryValue> DetachedFromWorkerNotification::toValue() const
126
{
127
4
    std::unique_ptr<protocol::DictionaryValue> result = DictionaryValue::create();
128
4
    result->setValue("sessionId", ValueConversions<String>::toValue(m_sessionId));
129
4
    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
92
std::unique_ptr<protocol::DictionaryValue> ReceivedMessageFromWorkerNotification::toValue() const
161
{
162
92
    std::unique_ptr<protocol::DictionaryValue> result = DictionaryValue::create();
163
92
    result->setValue("sessionId", ValueConversions<String>::toValue(m_sessionId));
164
92
    result->setValue("message", ValueConversions<String>::toValue(m_message));
165
92
    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
4
void Frontend::attachedToWorker(const String& sessionId, std::unique_ptr<protocol::NodeWorker::WorkerInfo> workerInfo, bool waitingForDebugger)
180
{
181
4
    if (!m_frontendChannel)
182
4
        return;
183
    std::unique_ptr<AttachedToWorkerNotification> messageData = AttachedToWorkerNotification::create()
184
8
        .setSessionId(sessionId)
185
12
        .setWorkerInfo(std::move(workerInfo))
186
8
        .setWaitingForDebugger(waitingForDebugger)
187
8
        .build();
188
4
    m_frontendChannel->sendProtocolNotification(InternalResponse::createNotification("NodeWorker.attachedToWorker", std::move(messageData)));
189
}
190
191
4
void Frontend::detachedFromWorker(const String& sessionId)
192
{
193
4
    if (!m_frontendChannel)
194
4
        return;
195
    std::unique_ptr<DetachedFromWorkerNotification> messageData = DetachedFromWorkerNotification::create()
196
8
        .setSessionId(sessionId)
197
4
        .build();
198
4
    m_frontendChannel->sendProtocolNotification(InternalResponse::createNotification("NodeWorker.detachedFromWorker", std::move(messageData)));
199
}
200
201
92
void Frontend::receivedMessageFromWorker(const String& sessionId, const String& message)
202
{
203
92
    if (!m_frontendChannel)
204
92
        return;
205
    std::unique_ptr<ReceivedMessageFromWorkerNotification> messageData = ReceivedMessageFromWorkerNotification::create()
206
184
        .setSessionId(sessionId)
207
92
        .setMessage(message)
208
92
        .build();
209
92
    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::sendRawNotification(const String& notification)
218
{
219
    m_frontendChannel->sendProtocolNotification(InternalRawNotification::create(notification));
220
}
221
222
// --------------------- Dispatcher.
223
224
class DispatcherImpl : public protocol::DispatcherBase {
225
public:
226
4618
    DispatcherImpl(FrontendChannel* frontendChannel, Backend* backend, bool fallThroughForNotFound)
227
        : DispatcherBase(frontendChannel)
228
        , m_backend(backend)
229
4618
        , m_fallThroughForNotFound(fallThroughForNotFound) {
230
4618
        m_dispatchMap["NodeWorker.sendMessageToWorker"] = &DispatcherImpl::sendMessageToWorker;
231
4618
        m_dispatchMap["NodeWorker.enable"] = &DispatcherImpl::enable;
232
4618
        m_dispatchMap["NodeWorker.disable"] = &DispatcherImpl::disable;
233
4618
    }
234
9218
    ~DispatcherImpl() override { }
235
    DispatchResponse::Status dispatch(int callId, const String& method, std::unique_ptr<protocol::DictionaryValue> messageObject) override;
236
4618
    HashMap<String, String>& redirects() { return m_redirects; }
237
238
protected:
239
    using CallHandler = DispatchResponse::Status (DispatcherImpl::*)(int callId, std::unique_ptr<DictionaryValue> messageObject, ErrorSupport* errors);
240
    using DispatchMap = protocol::HashMap<String, CallHandler>;
241
    DispatchMap m_dispatchMap;
242
    HashMap<String, String> m_redirects;
243
244
    DispatchResponse::Status sendMessageToWorker(int callId, std::unique_ptr<DictionaryValue> requestMessageObject, ErrorSupport*);
245
    DispatchResponse::Status enable(int callId, std::unique_ptr<DictionaryValue> requestMessageObject, ErrorSupport*);
246
    DispatchResponse::Status disable(int callId, std::unique_ptr<DictionaryValue> requestMessageObject, ErrorSupport*);
247
248
    Backend* m_backend;
249
    bool m_fallThroughForNotFound;
250
};
251
252
11
DispatchResponse::Status DispatcherImpl::dispatch(int callId, const String& method, std::unique_ptr<protocol::DictionaryValue> messageObject)
253
{
254
11
    protocol::HashMap<String, CallHandler>::iterator it = m_dispatchMap.find(method);
255
11
    if (it == m_dispatchMap.end()) {
256
        if (m_fallThroughForNotFound)
257
            return DispatchResponse::kFallThrough;
258
        reportProtocolError(callId, DispatchResponse::kMethodNotFound, "'" + method + "' wasn't found", nullptr);
259
        return DispatchResponse::kError;
260
    }
261
262
11
    protocol::ErrorSupport errors;
263
11
    return (this->*(it->second))(callId, std::move(messageObject), &errors);
264
}
265
266
267
6
DispatchResponse::Status DispatcherImpl::sendMessageToWorker(int callId, std::unique_ptr<DictionaryValue> requestMessageObject, ErrorSupport* errors)
268
{
269
    // Prepare input parameters.
270
6
    protocol::DictionaryValue* object = DictionaryValue::cast(requestMessageObject->get("params"));
271
6
    errors->push();
272

6
    protocol::Value* messageValue = object ? object->get("message") : nullptr;
273
6
    errors->setName("message");
274
6
    String in_message = ValueConversions<String>::fromValue(messageValue, errors);
275

6
    protocol::Value* sessionIdValue = object ? object->get("sessionId") : nullptr;
276
6
    errors->setName("sessionId");
277
12
    String in_sessionId = ValueConversions<String>::fromValue(sessionIdValue, errors);
278
6
    errors->pop();
279
6
    if (errors->hasErrors()) {
280
        reportProtocolError(callId, DispatchResponse::kInvalidParams, kInvalidParamsString, errors);
281
        return DispatchResponse::kError;
282
    }
283
284
12
    std::unique_ptr<DispatcherBase::WeakPtr> weak = weakPtr();
285
12
    DispatchResponse response = m_backend->sendMessageToWorker(in_message, in_sessionId);
286
6
    if (response.status() == DispatchResponse::kFallThrough)
287
        return response.status();
288
6
    if (weak->get())
289
6
        weak->get()->sendResponse(callId, response);
290
12
    return response.status();
291
}
292
293
3
DispatchResponse::Status DispatcherImpl::enable(int callId, std::unique_ptr<DictionaryValue> requestMessageObject, ErrorSupport* errors)
294
{
295
    // Prepare input parameters.
296
3
    protocol::DictionaryValue* object = DictionaryValue::cast(requestMessageObject->get("params"));
297
3
    errors->push();
298

3
    protocol::Value* waitForDebuggerOnStartValue = object ? object->get("waitForDebuggerOnStart") : nullptr;
299
3
    errors->setName("waitForDebuggerOnStart");
300
3
    bool in_waitForDebuggerOnStart = ValueConversions<bool>::fromValue(waitForDebuggerOnStartValue, errors);
301
3
    errors->pop();
302
3
    if (errors->hasErrors()) {
303
        reportProtocolError(callId, DispatchResponse::kInvalidParams, kInvalidParamsString, errors);
304
        return DispatchResponse::kError;
305
    }
306
307
3
    std::unique_ptr<DispatcherBase::WeakPtr> weak = weakPtr();
308
6
    DispatchResponse response = m_backend->enable(in_waitForDebuggerOnStart);
309
3
    if (response.status() == DispatchResponse::kFallThrough)
310
        return response.status();
311
3
    if (weak->get())
312
3
        weak->get()->sendResponse(callId, response);
313
6
    return response.status();
314
}
315
316
2
DispatchResponse::Status DispatcherImpl::disable(int callId, std::unique_ptr<DictionaryValue> requestMessageObject, ErrorSupport* errors)
317
{
318
319
2
    std::unique_ptr<DispatcherBase::WeakPtr> weak = weakPtr();
320
4
    DispatchResponse response = m_backend->disable();
321
2
    if (response.status() == DispatchResponse::kFallThrough)
322
        return response.status();
323
2
    if (weak->get())
324
2
        weak->get()->sendResponse(callId, response);
325
4
    return response.status();
326
}
327
328
// static
329
4618
void Dispatcher::wire(UberDispatcher* uber, Backend* backend)
330
{
331
4618
    std::unique_ptr<DispatcherImpl> dispatcher(new DispatcherImpl(uber->channel(), backend, uber->fallThroughForNotFound()));
332
4618
    uber->setupRedirects(dispatcher->redirects());
333
4618
    uber->registerBackend("NodeWorker", std::move(dispatcher));
334
4618
}
335
336
} // NodeWorker
337
} // namespace node
338
} // namespace inspector
339
} // namespace protocol