| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -17,18 +17,26 @@ using v8::Local; | |||
| 17 | 17 | using v8::Object; | |
| 18 | 18 | using v8::Value; | |
| 19 | 19 | ||
| 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 | + | ||
| 20 | 25 | std::unique_ptr<protocol::DOMStorage::StorageId> createStorageIdFromObject( | |
| 21 | 26 | Local<Context> context, Local<Object> storage_id_obj) { | |
| 22 | 27 | protocol::String security_origin; | |
| 28 | + Isolate* isolate = Isolate::GetCurrent(); | ||
| 23 | 29 | if (!ObjectGetProtocolString(context, storage_id_obj, "securityOrigin") | |
| 24 | 30 | .To(&security_origin)) { | |
| 31 | + ThrowEventError(isolate, "Missing securityOrigin in storageId"); | ||
| 25 | 32 | return {}; | |
| 26 | 33 | } | |
| 27 | 34 | bool is_local_storage = | |
| 28 | 35 | ObjectGetBool(context, storage_id_obj, "isLocalStorage").FromMaybe(false); | |
| 29 | 36 | protocol::String storageKey; | |
| 30 | 37 | if (!ObjectGetProtocolString(context, storage_id_obj, "storageKey") | |
| 31 | 38 | .To(&storageKey)) { | |
| 39 | + ThrowEventError(isolate, "Missing storageKey in storageId"); | ||
| 32 | 40 | return {}; | |
| 33 | 41 | } | |
| 34 | 42 | ||
@@ -135,8 +143,10 @@ protocol::DispatchResponse DOMStorageAgent::clear( | |||
| 135 | 143 | ||
| 136 | 144 | void DOMStorageAgent::domStorageItemAdded(Local<Context> context, | |
| 137 | 145 | Local<Object> params) { | |
| 146 | + Isolate* isolate = env_->isolate(); | ||
| 138 | 147 | Local<Object> storage_id_obj; | |
| 139 | 148 | if (!ObjectGetObject(context, params, "storageId").ToLocal(&storage_id_obj)) { | |
| 149 | + ThrowEventError(isolate, "Missing storageId in event"); | ||
| 140 | 150 | return; | |
| 141 | 151 | } | |
| 142 | 152 | ||
@@ -148,19 +158,23 @@ void DOMStorageAgent::domStorageItemAdded(Local<Context> context, | |||
| 148 | 158 | ||
| 149 | 159 | protocol::String key; | |
| 150 | 160 | if (!ObjectGetProtocolString(context, params, "key").To(&key)) { | |
| 161 | + ThrowEventError(isolate, "Missing key in event"); | ||
| 151 | 162 | return; | |
| 152 | 163 | } | |
| 153 | 164 | protocol::String new_value; | |
| 154 | 165 | if (!ObjectGetProtocolString(context, params, "newValue").To(&new_value)) { | |
| 166 | + ThrowEventError(isolate, "Missing newValue in event"); | ||
| 155 | 167 | return; | |
| 156 | 168 | } | |
| 157 | 169 | frontend_->domStorageItemAdded(std::move(storage_id), key, new_value); | |
| 158 | 170 | } | |
| 159 | 171 | ||
| 160 | 172 | void DOMStorageAgent::domStorageItemRemoved(Local<Context> context, | |
| 161 | 173 | Local<Object> params) { | |
| 174 | + Isolate* isolate = env_->isolate(); | ||
| 162 | 175 | Local<Object> storage_id_obj; | |
| 163 | 176 | if (!ObjectGetObject(context, params, "storageId").ToLocal(&storage_id_obj)) { | |
| 177 | + ThrowEventError(isolate, "Missing storageId in event"); | ||
| 164 | 178 | return; | |
| 165 | 179 | } | |
| 166 | 180 | std::unique_ptr<protocol::DOMStorage::StorageId> storage_id = | |
@@ -172,15 +186,18 @@ void DOMStorageAgent::domStorageItemRemoved(Local<Context> context, | |||
| 172 | 186 | ||
| 173 | 187 | protocol::String key; | |
| 174 | 188 | if (!ObjectGetProtocolString(context, params, "key").To(&key)) { | |
| 189 | + ThrowEventError(isolate, "Missing key in event"); | ||
| 175 | 190 | return; | |
| 176 | 191 | } | |
| 177 | 192 | frontend_->domStorageItemRemoved(std::move(storage_id), key); | |
| 178 | 193 | } | |
| 179 | 194 | ||
| 180 | 195 | void DOMStorageAgent::domStorageItemUpdated(Local<Context> context, | |
| 181 | 196 | Local<Object> params) { | |
| 197 | + Isolate* isolate = env_->isolate(); | ||
| 182 | 198 | Local<Object> storage_id_obj; | |
| 183 | 199 | if (!ObjectGetObject(context, params, "storageId").ToLocal(&storage_id_obj)) { | |
| 200 | + ThrowEventError(isolate, "Missing storageId in event"); | ||
| 184 | 201 | return; | |
| 185 | 202 | } | |
| 186 | 203 | ||
@@ -193,14 +210,17 @@ void DOMStorageAgent::domStorageItemUpdated(Local<Context> context, | |||
| 193 | 210 | ||
| 194 | 211 | protocol::String key; | |
| 195 | 212 | if (!ObjectGetProtocolString(context, params, "key").To(&key)) { | |
| 213 | + ThrowEventError(isolate, "Missing key in event"); | ||
| 196 | 214 | return; | |
| 197 | 215 | } | |
| 198 | 216 | protocol::String old_value; | |
| 199 | 217 | if (!ObjectGetProtocolString(context, params, "oldValue").To(&old_value)) { | |
| 218 | + ThrowEventError(isolate, "Missing oldValue in event"); | ||
| 200 | 219 | return; | |
| 201 | 220 | } | |
| 202 | 221 | protocol::String new_value; | |
| 203 | 222 | if (!ObjectGetProtocolString(context, params, "newValue").To(&new_value)) { | |
| 223 | + ThrowEventError(isolate, "Missing newValue in event"); | ||
| 204 | 224 | return; | |
| 205 | 225 | } | |
| 206 | 226 | frontend_->domStorageItemUpdated( | |
@@ -209,8 +229,10 @@ void DOMStorageAgent::domStorageItemUpdated(Local<Context> context, | |||
| 209 | 229 | ||
| 210 | 230 | void DOMStorageAgent::domStorageItemsCleared(Local<Context> context, | |
| 211 | 231 | Local<Object> params) { | |
| 232 | + Isolate* isolate = env_->isolate(); | ||
| 212 | 233 | Local<Object> storage_id_obj; | |
| 213 | 234 | if (!ObjectGetObject(context, params, "storageId").ToLocal(&storage_id_obj)) { | |
| 235 | + ThrowEventError(isolate, "Missing storageId in event"); | ||
| 214 | 236 | return; | |
| 215 | 237 | } | |
| 216 | 238 | std::unique_ptr<protocol::DOMStorage::StorageId> storage_id = | |
@@ -228,27 +250,32 @@ void DOMStorageAgent::registerStorage(Local<Context> context, | |||
| 228 | 250 | HandleScope handle_scope(isolate); | |
| 229 | 251 | bool is_local_storage; | |
| 230 | 252 | if (!ObjectGetBool(context, params, "isLocalStorage").To(&is_local_storage)) { | |
| 253 | + ThrowEventError(isolate, "Missing isLocalStorage in event"); | ||
| 231 | 254 | return; | |
| 232 | 255 | } | |
| 233 | 256 | Local<Object> storage_map_obj; | |
| 234 | 257 | if (!ObjectGetObject(context, params, "storageMap") | |
| 235 | 258 | .ToLocal(&storage_map_obj)) { | |
| 259 | + ThrowEventError(isolate, "Missing storageMap in event"); | ||
| 236 | 260 | return; | |
| 237 | 261 | } | |
| 238 | 262 | StorageMap& storage_map = | |
| 239 | 263 | is_local_storage ? local_storage_map_ : session_storage_map_; | |
| 240 | 264 | Local<Array> property_names; | |
| 241 | 265 | if (!storage_map_obj->GetOwnPropertyNames(context).ToLocal(&property_names)) { | |
| 266 | + ThrowEventError(isolate, "Failed to get property names from storageMap"); | ||
| 242 | 267 | return; | |
| 243 | 268 | } | |
| 244 | 269 | uint32_t length = property_names->Length(); | |
| 245 | 270 | for (uint32_t i = 0; i < length; ++i) { | |
| 246 | 271 | Local<Value> key_value; | |
| 247 | 272 | if (!property_names->Get(context, i).ToLocal(&key_value)) { | |
| 273 | + ThrowEventError(isolate, "Failed to get key from storageMap"); | ||
| 248 | 274 | return; | |
| 249 | 275 | } | |
| 250 | 276 | Local<Value> value_value; | |
| 251 | 277 | if (!storage_map_obj->Get(context, key_value).ToLocal(&value_value)) { | |
| 278 | + ThrowEventError(isolate, "Failed to get value from storageMap"); | ||
| 252 | 279 | return; | |
| 253 | 280 | } | |
| 254 | 281 | node::TwoByteValue key_utf16(isolate, key_value); | |
| Back | FazBrowse Home | New Git URL |
0 commit comments