Skip to content

Commit 89354d2

Browse files
committed
organize code
1 parent a115284 commit 89354d2

File tree

6 files changed

+42
-39
lines changed

6 files changed

+42
-39
lines changed

src/inspector/dom_storage_agent.cc

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
11
#include "dom_storage_agent.h"
2-
3-
#include "crdtp/dispatch.h"
42
#include "env-inl.h"
53
#include "inspector/inspector_object_utils.h"
64
#include "v8-isolate.h"
@@ -9,13 +7,15 @@ namespace node {
97
namespace inspector {
108

119
using v8::Array;
10+
using v8::Context;
1211
using v8::HandleScope;
12+
using v8::Isolate;
1313
using v8::Local;
1414
using v8::Object;
1515
using v8::Value;
1616

1717
std::unique_ptr<protocol::DOMStorage::StorageId> createStorageIdFromObject(
18-
v8::Local<v8::Context> context, v8::Local<v8::Object> storage_id_obj) {
18+
Local<Context> context, Local<Object> storage_id_obj) {
1919
protocol::String security_origin;
2020
if (!ObjectGetProtocolString(context, storage_id_obj, "securityOrigin")
2121
.To(&security_origin)) {
@@ -44,16 +44,16 @@ 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-
event_notifier_map_["domStorageItemAdded"] =
48-
(EventNotifier)(&DOMStorageAgent::domStorageItemAdded);
49-
event_notifier_map_["domStorageItemRemoved"] =
50-
(EventNotifier)(&DOMStorageAgent::domStorageItemRemoved);
51-
event_notifier_map_["domStorageItemUpdated"] =
52-
(EventNotifier)(&DOMStorageAgent::domStorageItemUpdated);
53-
event_notifier_map_["domStorageItemsCleared"] =
54-
(EventNotifier)(&DOMStorageAgent::domStorageItemsCleared);
55-
event_notifier_map_["registerStorage"] =
56-
(EventNotifier)(&DOMStorageAgent::registerStorage);
47+
addEventNotifier("domStorageItemAdded",
48+
(EventNotifier)(&DOMStorageAgent::domStorageItemAdded));
49+
addEventNotifier("domStorageItemRemoved",
50+
(EventNotifier)(&DOMStorageAgent::domStorageItemRemoved));
51+
addEventNotifier("domStorageItemUpdated",
52+
(EventNotifier)(&DOMStorageAgent::domStorageItemUpdated));
53+
addEventNotifier("domStorageItemsCleared",
54+
(EventNotifier)(&DOMStorageAgent::domStorageItemsCleared));
55+
addEventNotifier("registerStorage",
56+
(EventNotifier)(&DOMStorageAgent::registerStorage));
5757
}
5858

5959
protocol::DispatchResponse DOMStorageAgent::enable() {
@@ -107,8 +107,8 @@ protocol::DispatchResponse DOMStorageAgent::clear(
107107
return protocol::DispatchResponse::ServerError("Not implemented");
108108
}
109109

110-
void DOMStorageAgent::domStorageItemAdded(v8::Local<v8::Context> context,
111-
v8::Local<v8::Object> params) {
110+
void DOMStorageAgent::domStorageItemAdded(Local<Context> context,
111+
Local<Object> params) {
112112
Local<Object> storage_id_obj;
113113
if (!ObjectGetObject(context, params, "storageId").ToLocal(&storage_id_obj)) {
114114
return;
@@ -131,8 +131,8 @@ void DOMStorageAgent::domStorageItemAdded(v8::Local<v8::Context> context,
131131
frontend_->domStorageItemAdded(std::move(storage_id), key, new_value);
132132
}
133133

134-
void DOMStorageAgent::domStorageItemRemoved(v8::Local<v8::Context> context,
135-
v8::Local<v8::Object> params) {
134+
void DOMStorageAgent::domStorageItemRemoved(Local<Context> context,
135+
Local<Object> params) {
136136
Local<Object> storage_id_obj;
137137
if (!ObjectGetObject(context, params, "storageId").ToLocal(&storage_id_obj)) {
138138
return;
@@ -151,8 +151,8 @@ void DOMStorageAgent::domStorageItemRemoved(v8::Local<v8::Context> context,
151151
frontend_->domStorageItemRemoved(std::move(storage_id), key);
152152
}
153153

154-
void DOMStorageAgent::domStorageItemUpdated(v8::Local<v8::Context> context,
155-
v8::Local<v8::Object> params) {
154+
void DOMStorageAgent::domStorageItemUpdated(Local<Context> context,
155+
Local<Object> params) {
156156
Local<Object> storage_id_obj;
157157
if (!ObjectGetObject(context, params, "storageId").ToLocal(&storage_id_obj)) {
158158
return;
@@ -181,8 +181,8 @@ void DOMStorageAgent::domStorageItemUpdated(v8::Local<v8::Context> context,
181181
std::move(storage_id), key, old_value, new_value);
182182
}
183183

184-
void DOMStorageAgent::domStorageItemsCleared(v8::Local<v8::Context> context,
185-
v8::Local<v8::Object> params) {
184+
void DOMStorageAgent::domStorageItemsCleared(Local<Context> context,
185+
Local<Object> params) {
186186
Local<Object> storage_id_obj;
187187
if (!ObjectGetObject(context, params, "storageId").ToLocal(&storage_id_obj)) {
188188
return;
@@ -196,9 +196,9 @@ void DOMStorageAgent::domStorageItemsCleared(v8::Local<v8::Context> context,
196196
frontend_->domStorageItemsCleared(std::move(storage_id));
197197
}
198198

199-
void DOMStorageAgent::registerStorage(v8::Local<v8::Context> context,
200-
v8::Local<v8::Object> params) {
201-
v8::Isolate* isolate = env_->isolate();
199+
void DOMStorageAgent::registerStorage(Local<Context> context,
200+
Local<Object> params) {
201+
Isolate* isolate = env_->isolate();
202202
HandleScope handle_scope(isolate);
203203
bool is_local_storage;
204204
if (!ObjectGetBool(context, params, "isLocalStorage").To(&is_local_storage)) {

src/inspector/inspector_object_utils.cc

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
#include "inspector/protocol_helper.h"
33
#include "util-inl.h"
44

5+
using v8::Boolean;
56
using v8::Context;
67
using v8::EscapableHandleScope;
78
using v8::HandleScope;
@@ -14,20 +15,21 @@ using v8::MaybeLocal;
1415
using v8::Nothing;
1516
using v8::Number;
1617
using v8::Object;
18+
using v8::String;
1719
using v8::Value;
1820

1921
namespace node {
2022
namespace inspector {
2123
// Get a protocol string property from the object.
2224
Maybe<protocol::String> ObjectGetProtocolString(Local<Context> context,
2325
Local<Object> object,
24-
Local<v8::String> property) {
26+
Local<String> property) {
2527
HandleScope handle_scope(Isolate::GetCurrent());
2628
Local<Value> value;
2729
if (!object->Get(context, property).ToLocal(&value) || !value->IsString()) {
2830
return Nothing<protocol::String>();
2931
}
30-
Local<v8::String> str = value.As<v8::String>();
32+
Local<String> str = value.As<String>();
3133
return Just(ToProtocolString(Isolate::GetCurrent(), str));
3234
}
3335

@@ -79,21 +81,21 @@ Maybe<bool> ObjectGetBool(Local<Context> context,
7981
!value->IsBoolean()) {
8082
return Nothing<bool>();
8183
}
82-
return Just(value.As<v8::Boolean>()->Value());
84+
return Just(value.As<Boolean>()->Value());
8385
}
8486

8587
// Get an object property from the object.
86-
MaybeLocal<v8::Object> ObjectGetObject(Local<Context> context,
87-
Local<Object> object,
88-
const char* property) {
88+
MaybeLocal<Object> ObjectGetObject(Local<Context> context,
89+
Local<Object> object,
90+
const char* property) {
8991
EscapableHandleScope handle_scope(Isolate::GetCurrent());
9092
Local<Value> value;
9193
if (!object->Get(context, OneByteString(Isolate::GetCurrent(), property))
9294
.ToLocal(&value) ||
9395
!value->IsObject()) {
9496
return {};
9597
}
96-
return handle_scope.Escape(value.As<v8::Object>());
98+
return handle_scope.Escape(value.As<Object>());
9799
}
98100

99101
} // namespace inspector

src/inspector/notification_emitter.cc

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,5 +16,9 @@ void NotificationEmitter::emitNotification(v8::Local<v8::Context> context,
1616
}
1717
}
1818

19+
void NotificationEmitter::addEventNotifier(const protocol::String& event,
20+
EventNotifier notifier) {
21+
event_notifier_map_[event] = notifier;
22+
}
1923
} // namespace inspector
2024
} // namespace node

src/inspector/notification_emitter.h

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ namespace inspector {
1111

1212
class NotificationEmitter {
1313
public:
14+
using EventNotifier = void (NotificationEmitter::*)(
15+
v8::Local<v8::Context> context, v8::Local<v8::Object>);
1416
NotificationEmitter();
1517
virtual ~NotificationEmitter() = default;
1618

@@ -23,8 +25,9 @@ class NotificationEmitter {
2325
NotificationEmitter& operator=(const NotificationEmitter&) = delete;
2426

2527
protected:
26-
using EventNotifier = void (NotificationEmitter::*)(
27-
v8::Local<v8::Context> context, v8::Local<v8::Object>);
28+
void addEventNotifier(const protocol::String& event, EventNotifier notifier);
29+
30+
private:
2831
std::unordered_map<protocol::String, EventNotifier> event_notifier_map_;
2932
};
3033

src/inspector/storage_agent.cc

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,7 @@
11
#include "inspector/storage_agent.h"
22
#include <string>
33
#include "env-inl.h"
4-
#include "inspector/protocol_helper.h"
54
#include "node_url.h"
6-
#include "util-inl.h"
7-
#include "v8-isolate.h"
8-
#include "v8-local-handle.h"
95

106
namespace node {
117
namespace inspector {

src/inspector/storage_agent.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
#ifndef SRC_INSPECTOR_STORAGE_AGENT_H_
22
#define SRC_INSPECTOR_STORAGE_AGENT_H_
33

4-
#include <string>
54
#include "env.h"
6-
#include "inspector/notification_emitter.h"
75
#include "node/inspector/protocol/Storage.h"
86

97
namespace node {

0 commit comments

Comments
 (0)