Skip to content

Commit 447324d

Browse files
committed
fix test
1 parent 67bc93b commit 447324d

File tree

4 files changed

+42
-21
lines changed

4 files changed

+42
-21
lines changed

src/inspector/dom_storage_agent.cc

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -44,16 +44,14 @@ void DOMStorageAgent::Wire(protocol::UberDispatcher* dispatcher) {
4444
frontend_ =
4545
std::make_unique<protocol::DOMStorage::Frontend>(dispatcher->channel());
4646
protocol::DOMStorage::Dispatcher::wire(dispatcher, this);
47-
addEventNotifier("domStorageItemAdded",
48-
(EventNotifier)(&DOMStorageAgent::domStorageItemAdded));
47+
addEventNotifier("domStorageItemAdded", &DOMStorageAgent::domStorageItemAdded);
4948
addEventNotifier("domStorageItemRemoved",
50-
(EventNotifier)(&DOMStorageAgent::domStorageItemRemoved));
49+
&DOMStorageAgent::domStorageItemRemoved);
5150
addEventNotifier("domStorageItemUpdated",
52-
(EventNotifier)(&DOMStorageAgent::domStorageItemUpdated));
51+
&DOMStorageAgent::domStorageItemUpdated);
5352
addEventNotifier("domStorageItemsCleared",
54-
(EventNotifier)(&DOMStorageAgent::domStorageItemsCleared));
55-
addEventNotifier("registerStorage",
56-
(EventNotifier)(&DOMStorageAgent::registerStorage));
53+
&DOMStorageAgent::domStorageItemsCleared);
54+
addEventNotifier("registerStorage", &DOMStorageAgent::registerStorage);
5755
}
5856

5957
protocol::DispatchResponse DOMStorageAgent::enable() {
@@ -231,6 +229,20 @@ void DOMStorageAgent::registerStorage(Local<Context> context,
231229
}
232230
}
233231

232+
void DOMStorageAgent::emitNotification(Local<Context> context,
233+
const EventKey& event,
234+
Local<Object> params) {
235+
auto it = event_notifier_map_.find(event);
236+
if (it != event_notifier_map_.end()) {
237+
(this->*(it->second))(context, params);
238+
}
239+
}
240+
241+
void DOMStorageAgent::addEventNotifier(const EventKey& event,
242+
EventNotifier notifier) {
243+
event_notifier_map_[event] = notifier;
244+
}
245+
234246
bool DOMStorageAgent::canEmit(const std::string& domain) {
235247
return domain == "DOMStorage";
236248
}

src/inspector/dom_storage_agent.h

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,22 +2,29 @@
22
#define SRC_INSPECTOR_DOM_STORAGE_AGENT_H_
33

44
#include <string>
5+
#include <unordered_map>
56
#include "env.h"
67
#include "node/inspector/protocol/DOMStorage.h"
7-
#include "notification_emitter.h"
88
#include "v8.h"
99

1010
namespace node {
1111
namespace inspector {
1212

13-
class DOMStorageAgent : public protocol::DOMStorage::Backend,
14-
public NotificationEmitter {
13+
class DOMStorageAgent : public protocol::DOMStorage::Backend {
1514
public:
15+
using EventKey = std::string;
16+
using EventNotifier =
17+
void (DOMStorageAgent::*)(v8::Local<v8::Context> context,
18+
v8::Local<v8::Object> params);
1619
explicit DOMStorageAgent(Environment* env);
1720
~DOMStorageAgent() override;
1821

1922
void Wire(protocol::UberDispatcher* dispatcher);
2023

24+
void emitNotification(v8::Local<v8::Context> context,
25+
const EventKey& event,
26+
v8::Local<v8::Object> params);
27+
2128
protocol::DispatchResponse enable() override;
2229
protocol::DispatchResponse disable() override;
2330
protocol::DispatchResponse getDOMStorageItems(
@@ -44,16 +51,18 @@ class DOMStorageAgent : public protocol::DOMStorage::Backend,
4451
v8::Local<v8::Object> params);
4552
void registerStorage(v8::Local<v8::Context> context,
4653
v8::Local<v8::Object> params);
47-
bool canEmit(const std::string& domain) override;
54+
bool canEmit(const std::string& domain);
4855

4956
DOMStorageAgent(const DOMStorageAgent&) = delete;
5057
DOMStorageAgent& operator=(const DOMStorageAgent&) = delete;
5158

5259
private:
60+
void addEventNotifier(const EventKey& event, EventNotifier notifier);
5361
std::unique_ptr<protocol::DOMStorage::Frontend> frontend_;
54-
std::unordered_map<std::string, std::string> local_storage_map_;
55-
std::unordered_map<std::string, std::string> session_storage_map_;
56-
bool enabled_;
62+
std::unordered_map<std::string, std::string> local_storage_map_ = {};
63+
std::unordered_map<std::string, std::string> session_storage_map_ = {};
64+
std::unordered_map<EventKey, EventNotifier> event_notifier_map_ = {};
65+
bool enabled_ = false;
5766
Environment* env_;
5867
};
5968

src/inspector/notification_emitter.cc

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,15 @@ namespace inspector {
88
NotificationEmitter::NotificationEmitter() {}
99

1010
void NotificationEmitter::emitNotification(v8::Local<v8::Context> context,
11-
const std::string& event,
11+
const EventKey& event,
1212
v8::Local<v8::Object> params) {
1313
auto it = event_notifier_map_.find(event);
1414
if (it != event_notifier_map_.end()) {
15-
(this->*(it->second))(context, params);
15+
// (this->*(it->second))(context, params);
1616
}
1717
}
1818

19-
void NotificationEmitter::addEventNotifier(const protocol::String& event,
19+
void NotificationEmitter::addEventNotifier(const EventKey& event,
2020
EventNotifier notifier) {
2121
event_notifier_map_[event] = notifier;
2222
}

src/inspector/notification_emitter.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,32 +3,32 @@
33

44
#include <string>
55
#include <unordered_map>
6-
#include "node/inspector/protocol/Protocol.h"
76
#include "v8.h"
87

98
namespace node {
109
namespace inspector {
1110

1211
class NotificationEmitter {
1312
public:
13+
using EventKey = std::string;
1414
using EventNotifier = void (NotificationEmitter::*)(
1515
v8::Local<v8::Context> context, v8::Local<v8::Object>);
1616
NotificationEmitter();
1717
virtual ~NotificationEmitter() = default;
1818

1919
void emitNotification(v8::Local<v8::Context> context,
20-
const protocol::String& event,
20+
const EventKey& event,
2121
v8::Local<v8::Object> params);
2222
virtual bool canEmit(const std::string& domain) = 0;
2323

2424
NotificationEmitter(const NotificationEmitter&) = delete;
2525
NotificationEmitter& operator=(const NotificationEmitter&) = delete;
2626

2727
protected:
28-
void addEventNotifier(const protocol::String& event, EventNotifier notifier);
28+
void addEventNotifier(const EventKey& event, EventNotifier notifier);
2929

3030
private:
31-
std::unordered_map<protocol::String, EventNotifier> event_notifier_map_;
31+
std::unordered_map<EventKey, EventNotifier> event_notifier_map_ = {};
3232
};
3333

3434
} // namespace inspector

0 commit comments

Comments
 (0)