-
-
Notifications
You must be signed in to change notification settings - Fork 35.3k
inspector: return errors when CDP protocol event emission fails #62162
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
7c62581
d265030
9cd08cb
dcd9c3a
29b190c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -14,18 +14,26 @@ using v8::Local; | |
| using v8::Object; | ||
| using v8::Value; | ||
|
|
||
| static void ThrowEventError(v8::Isolate* isolate, const std::string& message) { | ||
| isolate->ThrowException(v8::Exception::Error( | ||
islandryu marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| v8::String::NewFromUtf8(isolate, message.c_str()).ToLocalChecked())); | ||
| } | ||
|
|
||
| std::unique_ptr<protocol::DOMStorage::StorageId> createStorageIdFromObject( | ||
| Local<Context> context, Local<Object> storage_id_obj) { | ||
| protocol::String security_origin; | ||
| Isolate* isolate = Isolate::GetCurrent(); | ||
| if (!ObjectGetProtocolString(context, storage_id_obj, "securityOrigin") | ||
| .To(&security_origin)) { | ||
| ThrowEventError(isolate, "Missing securityOrigin in storageId"); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. IIUC, this would throw an identical error for each session connected. Can we validate the object shape once so that the error is only thrown once? This would also prevent returning an array of errors in the JS API.
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If errors that depend on session-specific state are introduced in the future, this may need to be changed. However, since we currently only perform type checks, would it make sense to throw the error directly?
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sounds good! Either way, returning an error is probably not the pattern as it does not align with the exception convention. |
||
| return {}; | ||
| } | ||
| bool is_local_storage = | ||
| ObjectGetBool(context, storage_id_obj, "isLocalStorage").FromMaybe(false); | ||
| protocol::String storageKey; | ||
| if (!ObjectGetProtocolString(context, storage_id_obj, "storageKey") | ||
| .To(&storageKey)) { | ||
| ThrowEventError(isolate, "Missing storageKey in storageId"); | ||
| return {}; | ||
| } | ||
|
|
||
|
|
@@ -119,8 +127,10 @@ protocol::DispatchResponse DOMStorageAgent::clear( | |
|
|
||
| void DOMStorageAgent::domStorageItemAdded(Local<Context> context, | ||
| Local<Object> params) { | ||
| Isolate* isolate = env_->isolate(); | ||
| Local<Object> storage_id_obj; | ||
| if (!ObjectGetObject(context, params, "storageId").ToLocal(&storage_id_obj)) { | ||
| ThrowEventError(isolate, "Missing storageId in event"); | ||
| return; | ||
| } | ||
|
|
||
|
|
@@ -132,19 +142,23 @@ void DOMStorageAgent::domStorageItemAdded(Local<Context> context, | |
|
|
||
| protocol::String key; | ||
| if (!ObjectGetProtocolString(context, params, "key").To(&key)) { | ||
| ThrowEventError(isolate, "Missing key in event"); | ||
| return; | ||
| } | ||
| protocol::String new_value; | ||
| if (!ObjectGetProtocolString(context, params, "newValue").To(&new_value)) { | ||
| ThrowEventError(isolate, "Missing newValue in event"); | ||
| return; | ||
| } | ||
| frontend_->domStorageItemAdded(std::move(storage_id), key, new_value); | ||
| } | ||
|
|
||
| void DOMStorageAgent::domStorageItemRemoved(Local<Context> context, | ||
| Local<Object> params) { | ||
| Isolate* isolate = env_->isolate(); | ||
| Local<Object> storage_id_obj; | ||
| if (!ObjectGetObject(context, params, "storageId").ToLocal(&storage_id_obj)) { | ||
| ThrowEventError(isolate, "Missing storageId in event"); | ||
| return; | ||
| } | ||
| std::unique_ptr<protocol::DOMStorage::StorageId> storage_id = | ||
|
|
@@ -156,15 +170,18 @@ void DOMStorageAgent::domStorageItemRemoved(Local<Context> context, | |
|
|
||
| protocol::String key; | ||
| if (!ObjectGetProtocolString(context, params, "key").To(&key)) { | ||
| ThrowEventError(isolate, "Missing key in event"); | ||
| return; | ||
| } | ||
| frontend_->domStorageItemRemoved(std::move(storage_id), key); | ||
| } | ||
|
|
||
| void DOMStorageAgent::domStorageItemUpdated(Local<Context> context, | ||
| Local<Object> params) { | ||
| Isolate* isolate = env_->isolate(); | ||
| Local<Object> storage_id_obj; | ||
| if (!ObjectGetObject(context, params, "storageId").ToLocal(&storage_id_obj)) { | ||
| ThrowEventError(isolate, "Missing storageId in event"); | ||
| return; | ||
| } | ||
|
|
||
|
|
@@ -177,14 +194,17 @@ void DOMStorageAgent::domStorageItemUpdated(Local<Context> context, | |
|
|
||
| protocol::String key; | ||
| if (!ObjectGetProtocolString(context, params, "key").To(&key)) { | ||
| ThrowEventError(isolate, "Missing key in event"); | ||
| return; | ||
| } | ||
| protocol::String old_value; | ||
| if (!ObjectGetProtocolString(context, params, "oldValue").To(&old_value)) { | ||
| ThrowEventError(isolate, "Missing oldValue in event"); | ||
| return; | ||
| } | ||
| protocol::String new_value; | ||
| if (!ObjectGetProtocolString(context, params, "newValue").To(&new_value)) { | ||
| ThrowEventError(isolate, "Missing newValue in event"); | ||
| return; | ||
| } | ||
| frontend_->domStorageItemUpdated( | ||
|
|
@@ -193,8 +213,10 @@ void DOMStorageAgent::domStorageItemUpdated(Local<Context> context, | |
|
|
||
| void DOMStorageAgent::domStorageItemsCleared(Local<Context> context, | ||
| Local<Object> params) { | ||
| Isolate* isolate = env_->isolate(); | ||
| Local<Object> storage_id_obj; | ||
| if (!ObjectGetObject(context, params, "storageId").ToLocal(&storage_id_obj)) { | ||
| ThrowEventError(isolate, "Missing storageId in event"); | ||
| return; | ||
| } | ||
| std::unique_ptr<protocol::DOMStorage::StorageId> storage_id = | ||
|
|
@@ -212,27 +234,32 @@ void DOMStorageAgent::registerStorage(Local<Context> context, | |
| HandleScope handle_scope(isolate); | ||
| bool is_local_storage; | ||
| if (!ObjectGetBool(context, params, "isLocalStorage").To(&is_local_storage)) { | ||
| ThrowEventError(isolate, "Missing isLocalStorage in event"); | ||
| return; | ||
| } | ||
| Local<Object> storage_map_obj; | ||
| if (!ObjectGetObject(context, params, "storageMap") | ||
| .ToLocal(&storage_map_obj)) { | ||
| ThrowEventError(isolate, "Missing storageMap in event"); | ||
| return; | ||
| } | ||
| std::unordered_map<std::string, std::string>& storage_map = | ||
| is_local_storage ? local_storage_map_ : session_storage_map_; | ||
| Local<Array> property_names; | ||
| if (!storage_map_obj->GetOwnPropertyNames(context).ToLocal(&property_names)) { | ||
| ThrowEventError(isolate, "Failed to get property names from storageMap"); | ||
| return; | ||
| } | ||
| uint32_t length = property_names->Length(); | ||
| for (uint32_t i = 0; i < length; ++i) { | ||
| Local<Value> key_value; | ||
| if (!property_names->Get(context, i).ToLocal(&key_value)) { | ||
| ThrowEventError(isolate, "Failed to get key from storageMap"); | ||
| return; | ||
| } | ||
| Local<Value> value_value; | ||
| if (!storage_map_obj->Get(context, key_value).ToLocal(&value_value)) { | ||
| ThrowEventError(isolate, "Failed to get value from storageMap"); | ||
| return; | ||
| } | ||
| node::Utf8Value key_utf8(isolate, key_value); | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.