@@ -17,18 +17,26 @@ using v8::Local;
1717using v8::Object;
1818using v8::Value;
1919
20+ static void ThrowEventError (v8::Isolate* isolate, const std::string& message) {
21+ isolate->ThrowException (v8::Exception::TypeError (
22+ v8::String::NewFromUtf8 (isolate, message.c_str ()).ToLocalChecked ()));
23+ }
24+
2025std::unique_ptr<protocol::DOMStorage::StorageId> createStorageIdFromObject (
2126 Local<Context> context, Local<Object> storage_id_obj) {
2227 protocol::String security_origin;
28+ Isolate* isolate = Isolate::GetCurrent ();
2329 if (!ObjectGetProtocolString (context, storage_id_obj, " securityOrigin" )
2430 .To (&security_origin)) {
31+ ThrowEventError (isolate, " Missing securityOrigin in storageId" );
2532 return {};
2633 }
2734 bool is_local_storage =
2835 ObjectGetBool (context, storage_id_obj, " isLocalStorage" ).FromMaybe (false );
2936 protocol::String storageKey;
3037 if (!ObjectGetProtocolString (context, storage_id_obj, " storageKey" )
3138 .To (&storageKey)) {
39+ ThrowEventError (isolate, " Missing storageKey in storageId" );
3240 return {};
3341 }
3442
@@ -135,8 +143,10 @@ protocol::DispatchResponse DOMStorageAgent::clear(
135143
136144void DOMStorageAgent::domStorageItemAdded (Local<Context> context,
137145 Local<Object> params) {
146+ Isolate* isolate = env_->isolate ();
138147 Local<Object> storage_id_obj;
139148 if (!ObjectGetObject (context, params, " storageId" ).ToLocal (&storage_id_obj)) {
149+ ThrowEventError (isolate, " Missing storageId in event" );
140150 return ;
141151 }
142152
@@ -148,19 +158,23 @@ void DOMStorageAgent::domStorageItemAdded(Local<Context> context,
148158
149159 protocol::String key;
150160 if (!ObjectGetProtocolString (context, params, " key" ).To (&key)) {
161+ ThrowEventError (isolate, " Missing key in event" );
151162 return ;
152163 }
153164 protocol::String new_value;
154165 if (!ObjectGetProtocolString (context, params, " newValue" ).To (&new_value)) {
166+ ThrowEventError (isolate, " Missing newValue in event" );
155167 return ;
156168 }
157169 frontend_->domStorageItemAdded (std::move (storage_id), key, new_value);
158170}
159171
160172void DOMStorageAgent::domStorageItemRemoved (Local<Context> context,
161173 Local<Object> params) {
174+ Isolate* isolate = env_->isolate ();
162175 Local<Object> storage_id_obj;
163176 if (!ObjectGetObject (context, params, " storageId" ).ToLocal (&storage_id_obj)) {
177+ ThrowEventError (isolate, " Missing storageId in event" );
164178 return ;
165179 }
166180 std::unique_ptr<protocol::DOMStorage::StorageId> storage_id =
@@ -172,15 +186,18 @@ void DOMStorageAgent::domStorageItemRemoved(Local<Context> context,
172186
173187 protocol::String key;
174188 if (!ObjectGetProtocolString (context, params, " key" ).To (&key)) {
189+ ThrowEventError (isolate, " Missing key in event" );
175190 return ;
176191 }
177192 frontend_->domStorageItemRemoved (std::move (storage_id), key);
178193}
179194
180195void DOMStorageAgent::domStorageItemUpdated (Local<Context> context,
181196 Local<Object> params) {
197+ Isolate* isolate = env_->isolate ();
182198 Local<Object> storage_id_obj;
183199 if (!ObjectGetObject (context, params, " storageId" ).ToLocal (&storage_id_obj)) {
200+ ThrowEventError (isolate, " Missing storageId in event" );
184201 return ;
185202 }
186203
@@ -193,14 +210,17 @@ void DOMStorageAgent::domStorageItemUpdated(Local<Context> context,
193210
194211 protocol::String key;
195212 if (!ObjectGetProtocolString (context, params, " key" ).To (&key)) {
213+ ThrowEventError (isolate, " Missing key in event" );
196214 return ;
197215 }
198216 protocol::String old_value;
199217 if (!ObjectGetProtocolString (context, params, " oldValue" ).To (&old_value)) {
218+ ThrowEventError (isolate, " Missing oldValue in event" );
200219 return ;
201220 }
202221 protocol::String new_value;
203222 if (!ObjectGetProtocolString (context, params, " newValue" ).To (&new_value)) {
223+ ThrowEventError (isolate, " Missing newValue in event" );
204224 return ;
205225 }
206226 frontend_->domStorageItemUpdated (
@@ -209,8 +229,10 @@ void DOMStorageAgent::domStorageItemUpdated(Local<Context> context,
209229
210230void DOMStorageAgent::domStorageItemsCleared (Local<Context> context,
211231 Local<Object> params) {
232+ Isolate* isolate = env_->isolate ();
212233 Local<Object> storage_id_obj;
213234 if (!ObjectGetObject (context, params, " storageId" ).ToLocal (&storage_id_obj)) {
235+ ThrowEventError (isolate, " Missing storageId in event" );
214236 return ;
215237 }
216238 std::unique_ptr<protocol::DOMStorage::StorageId> storage_id =
@@ -228,27 +250,32 @@ void DOMStorageAgent::registerStorage(Local<Context> context,
228250 HandleScope handle_scope (isolate);
229251 bool is_local_storage;
230252 if (!ObjectGetBool (context, params, " isLocalStorage" ).To (&is_local_storage)) {
253+ ThrowEventError (isolate, " Missing isLocalStorage in event" );
231254 return ;
232255 }
233256 Local<Object> storage_map_obj;
234257 if (!ObjectGetObject (context, params, " storageMap" )
235258 .ToLocal (&storage_map_obj)) {
259+ ThrowEventError (isolate, " Missing storageMap in event" );
236260 return ;
237261 }
238262 StorageMap& storage_map =
239263 is_local_storage ? local_storage_map_ : session_storage_map_;
240264 Local<Array> property_names;
241265 if (!storage_map_obj->GetOwnPropertyNames (context).ToLocal (&property_names)) {
266+ ThrowEventError (isolate, " Failed to get property names from storageMap" );
242267 return ;
243268 }
244269 uint32_t length = property_names->Length ();
245270 for (uint32_t i = 0 ; i < length; ++i) {
246271 Local<Value> key_value;
247272 if (!property_names->Get (context, i).ToLocal (&key_value)) {
273+ ThrowEventError (isolate, " Failed to get key from storageMap" );
248274 return ;
249275 }
250276 Local<Value> value_value;
251277 if (!storage_map_obj->Get (context, key_value).ToLocal (&value_value)) {
278+ ThrowEventError (isolate, " Failed to get value from storageMap" );
252279 return ;
253280 }
254281 node::TwoByteValue key_utf16 (isolate, key_value);
0 commit comments