@@ -14,18 +14,26 @@ using v8::Local;
1414using v8::Object;
1515using v8::Value;
1616
17+ static void ThrowEventError (v8::Isolate* isolate, const std::string& message) {
18+ isolate->ThrowException (v8::Exception::Error (
19+ v8::String::NewFromUtf8 (isolate, message.c_str ()).ToLocalChecked ()));
20+ }
21+
1722std::unique_ptr<protocol::DOMStorage::StorageId> createStorageIdFromObject (
1823 Local<Context> context, Local<Object> storage_id_obj) {
1924 protocol::String security_origin;
25+ Isolate* isolate = Isolate::GetCurrent ();
2026 if (!ObjectGetProtocolString (context, storage_id_obj, " securityOrigin" )
2127 .To (&security_origin)) {
28+ ThrowEventError (isolate, " Missing securityOrigin in storageId" );
2229 return {};
2330 }
2431 bool is_local_storage =
2532 ObjectGetBool (context, storage_id_obj, " isLocalStorage" ).FromMaybe (false );
2633 protocol::String storageKey;
2734 if (!ObjectGetProtocolString (context, storage_id_obj, " storageKey" )
2835 .To (&storageKey)) {
36+ ThrowEventError (isolate, " Missing storageKey in storageId" );
2937 return {};
3038 }
3139
@@ -119,8 +127,10 @@ protocol::DispatchResponse DOMStorageAgent::clear(
119127
120128void DOMStorageAgent::domStorageItemAdded (Local<Context> context,
121129 Local<Object> params) {
130+ Isolate* isolate = env_->isolate ();
122131 Local<Object> storage_id_obj;
123132 if (!ObjectGetObject (context, params, " storageId" ).ToLocal (&storage_id_obj)) {
133+ ThrowEventError (isolate, " Missing storageId in event" );
124134 return ;
125135 }
126136
@@ -132,19 +142,23 @@ void DOMStorageAgent::domStorageItemAdded(Local<Context> context,
132142
133143 protocol::String key;
134144 if (!ObjectGetProtocolString (context, params, " key" ).To (&key)) {
145+ ThrowEventError (isolate, " Missing key in event" );
135146 return ;
136147 }
137148 protocol::String new_value;
138149 if (!ObjectGetProtocolString (context, params, " newValue" ).To (&new_value)) {
150+ ThrowEventError (isolate, " Missing newValue in event" );
139151 return ;
140152 }
141153 frontend_->domStorageItemAdded (std::move (storage_id), key, new_value);
142154}
143155
144156void DOMStorageAgent::domStorageItemRemoved (Local<Context> context,
145157 Local<Object> params) {
158+ Isolate* isolate = env_->isolate ();
146159 Local<Object> storage_id_obj;
147160 if (!ObjectGetObject (context, params, " storageId" ).ToLocal (&storage_id_obj)) {
161+ ThrowEventError (isolate, " Missing storageId in event" );
148162 return ;
149163 }
150164 std::unique_ptr<protocol::DOMStorage::StorageId> storage_id =
@@ -156,15 +170,18 @@ void DOMStorageAgent::domStorageItemRemoved(Local<Context> context,
156170
157171 protocol::String key;
158172 if (!ObjectGetProtocolString (context, params, " key" ).To (&key)) {
173+ ThrowEventError (isolate, " Missing key in event" );
159174 return ;
160175 }
161176 frontend_->domStorageItemRemoved (std::move (storage_id), key);
162177}
163178
164179void DOMStorageAgent::domStorageItemUpdated (Local<Context> context,
165180 Local<Object> params) {
181+ Isolate* isolate = env_->isolate ();
166182 Local<Object> storage_id_obj;
167183 if (!ObjectGetObject (context, params, " storageId" ).ToLocal (&storage_id_obj)) {
184+ ThrowEventError (isolate, " Missing storageId in event" );
168185 return ;
169186 }
170187
@@ -177,14 +194,17 @@ void DOMStorageAgent::domStorageItemUpdated(Local<Context> context,
177194
178195 protocol::String key;
179196 if (!ObjectGetProtocolString (context, params, " key" ).To (&key)) {
197+ ThrowEventError (isolate, " Missing key in event" );
180198 return ;
181199 }
182200 protocol::String old_value;
183201 if (!ObjectGetProtocolString (context, params, " oldValue" ).To (&old_value)) {
202+ ThrowEventError (isolate, " Missing oldValue in event" );
184203 return ;
185204 }
186205 protocol::String new_value;
187206 if (!ObjectGetProtocolString (context, params, " newValue" ).To (&new_value)) {
207+ ThrowEventError (isolate, " Missing newValue in event" );
188208 return ;
189209 }
190210 frontend_->domStorageItemUpdated (
@@ -193,8 +213,10 @@ void DOMStorageAgent::domStorageItemUpdated(Local<Context> context,
193213
194214void DOMStorageAgent::domStorageItemsCleared (Local<Context> context,
195215 Local<Object> params) {
216+ Isolate* isolate = env_->isolate ();
196217 Local<Object> storage_id_obj;
197218 if (!ObjectGetObject (context, params, " storageId" ).ToLocal (&storage_id_obj)) {
219+ ThrowEventError (isolate, " Missing storageId in event" );
198220 return ;
199221 }
200222 std::unique_ptr<protocol::DOMStorage::StorageId> storage_id =
@@ -212,27 +234,32 @@ void DOMStorageAgent::registerStorage(Local<Context> context,
212234 HandleScope handle_scope (isolate);
213235 bool is_local_storage;
214236 if (!ObjectGetBool (context, params, " isLocalStorage" ).To (&is_local_storage)) {
237+ ThrowEventError (isolate, " Missing isLocalStorage in event" );
215238 return ;
216239 }
217240 Local<Object> storage_map_obj;
218241 if (!ObjectGetObject (context, params, " storageMap" )
219242 .ToLocal (&storage_map_obj)) {
243+ ThrowEventError (isolate, " Missing storageMap in event" );
220244 return ;
221245 }
222246 std::unordered_map<std::string, std::string>& storage_map =
223247 is_local_storage ? local_storage_map_ : session_storage_map_;
224248 Local<Array> property_names;
225249 if (!storage_map_obj->GetOwnPropertyNames (context).ToLocal (&property_names)) {
250+ ThrowEventError (isolate, " Failed to get property names from storageMap" );
226251 return ;
227252 }
228253 uint32_t length = property_names->Length ();
229254 for (uint32_t i = 0 ; i < length; ++i) {
230255 Local<Value> key_value;
231256 if (!property_names->Get (context, i).ToLocal (&key_value)) {
257+ ThrowEventError (isolate, " Failed to get key from storageMap" );
232258 return ;
233259 }
234260 Local<Value> value_value;
235261 if (!storage_map_obj->Get (context, key_value).ToLocal (&value_value)) {
262+ ThrowEventError (isolate, " Failed to get value from storageMap" );
236263 return ;
237264 }
238265 node::Utf8Value key_utf8 (isolate, key_value);
0 commit comments