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/NodeRuntime.cpp Lines: 36 46 78.3 %
Date: 2019-07-27 22:37:30 Branches: 9 18 50.0 %

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/NodeRuntime.h"
8
9
#include "src/node/inspector/protocol/Protocol.h"
10
11
namespace node {
12
namespace inspector {
13
namespace protocol {
14
namespace NodeRuntime {
15
16
// ------------- Enum values from types.
17
18
const char Metainfo::domainName[] = "NodeRuntime";
19
const char Metainfo::commandPrefix[] = "NodeRuntime.";
20
const char Metainfo::version[] = "1.0";
21
22
// ------------- Enum values from params.
23
24
25
// ------------- Frontend notifications.
26
27
3
void Frontend::waitingForDisconnect()
28
{
29
3
    if (!m_frontendChannel)
30
3
        return;
31
3
    m_frontendChannel->sendProtocolNotification(InternalResponse::createNotification("NodeRuntime.waitingForDisconnect"));
32
}
33
34
void Frontend::flush()
35
{
36
    m_frontendChannel->flushProtocolNotifications();
37
}
38
39
void Frontend::sendRawJSONNotification(String notification)
40
{
41
    m_frontendChannel->sendProtocolNotification(InternalRawNotification::fromJSON(std::move(notification)));
42
}
43
44
void Frontend::sendRawCBORNotification(std::vector<uint8_t> notification)
45
{
46
    m_frontendChannel->sendProtocolNotification(InternalRawNotification::fromBinary(std::move(notification)));
47
}
48
49
// --------------------- Dispatcher.
50
51
class DispatcherImpl : public protocol::DispatcherBase {
52
public:
53
5208
    DispatcherImpl(FrontendChannel* frontendChannel, Backend* backend)
54
        : DispatcherBase(frontendChannel)
55
5208
        , m_backend(backend) {
56
5208
        m_dispatchMap["NodeRuntime.notifyWhenWaitingForDisconnect"] = &DispatcherImpl::notifyWhenWaitingForDisconnect;
57
5209
    }
58
9624
    ~DispatcherImpl() override { }
59
    bool canDispatch(const String& method) override;
60
    void dispatch(int callId, const String& method, const ProtocolMessage& message, std::unique_ptr<protocol::DictionaryValue> messageObject) override;
61
5208
    std::unordered_map<String, String>& redirects() { return m_redirects; }
62
63
protected:
64
    using CallHandler = void (DispatcherImpl::*)(int callId, const String& method, const ProtocolMessage& message, std::unique_ptr<DictionaryValue> messageObject, ErrorSupport* errors);
65
    using DispatchMap = std::unordered_map<String, CallHandler>;
66
    DispatchMap m_dispatchMap;
67
    std::unordered_map<String, String> m_redirects;
68
69
    void notifyWhenWaitingForDisconnect(int callId, const String& method, const ProtocolMessage& message, std::unique_ptr<DictionaryValue> requestMessageObject, ErrorSupport*);
70
71
    Backend* m_backend;
72
};
73
74
3
bool DispatcherImpl::canDispatch(const String& method) {
75
3
    return m_dispatchMap.find(method) != m_dispatchMap.end();
76
}
77
78
3
void DispatcherImpl::dispatch(int callId, const String& method, const ProtocolMessage& message, std::unique_ptr<protocol::DictionaryValue> messageObject)
79
{
80
3
    std::unordered_map<String, CallHandler>::iterator it = m_dispatchMap.find(method);
81
    DCHECK(it != m_dispatchMap.end());
82
3
    protocol::ErrorSupport errors;
83
3
    (this->*(it->second))(callId, method, message, std::move(messageObject), &errors);
84
3
}
85
86
87
3
void DispatcherImpl::notifyWhenWaitingForDisconnect(int callId, const String& method, const ProtocolMessage& message, std::unique_ptr<DictionaryValue> requestMessageObject, ErrorSupport* errors)
88
{
89
    // Prepare input parameters.
90
3
    protocol::DictionaryValue* object = DictionaryValue::cast(requestMessageObject->get("params"));
91
3
    errors->push();
92

3
    protocol::Value* enabledValue = object ? object->get("enabled") : nullptr;
93
3
    errors->setName("enabled");
94
3
    bool in_enabled = ValueConversions<bool>::fromValue(enabledValue, errors);
95
3
    errors->pop();
96
3
    if (errors->hasErrors()) {
97
        reportProtocolError(callId, DispatchResponse::kInvalidParams, kInvalidParamsString, errors);
98
        return;
99
    }
100
101
3
    std::unique_ptr<DispatcherBase::WeakPtr> weak = weakPtr();
102
6
    DispatchResponse response = m_backend->notifyWhenWaitingForDisconnect(in_enabled);
103
3
    if (response.status() == DispatchResponse::kFallThrough) {
104
        channel()->fallThrough(callId, method, message);
105
        return;
106
    }
107
3
    if (weak->get())
108
3
        weak->get()->sendResponse(callId, response);
109
6
    return;
110
}
111
112
// static
113
5208
void Dispatcher::wire(UberDispatcher* uber, Backend* backend)
114
{
115
5208
    std::unique_ptr<DispatcherImpl> dispatcher(new DispatcherImpl(uber->channel(), backend));
116
5209
    uber->setupRedirects(dispatcher->redirects());
117
5208
    uber->registerBackend("NodeRuntime", std::move(dispatcher));
118
5209
}
119
120
} // NodeRuntime
121
} // namespace node
122
} // namespace inspector
123
} // namespace protocol