-
-
Notifications
You must be signed in to change notification settings - Fork 807
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
WebDriver: Partial implementation of Element Clear endpoint #1356
base: master
Are you sure you want to change the base?
Conversation
Hello! One or more of the commit messages in this PR do not match the Ladybird code submission policy, please check the |
a89bd17
to
d5d139e
Compare
eec3817
to
f5df7cf
Compare
Web::DOM::Element* element = TRY(get_known_connected_element(element_id)); | ||
if (!element) { | ||
return Web::WebDriver::Error::from_code(Web::WebDriver::ErrorCode::NoSuchElement, "Element not found"); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not a reviewer, but I would suggest that you either implement the whole line or keep FIXME.
The code below is untested, but something like it is what the spec expects.
Web::DOM::Element* element = TRY(get_known_connected_element(element_id)); | |
if (!element) { | |
return Web::WebDriver::Error::from_code(Web::WebDriver::ErrorCode::NoSuchElement, "Element not found"); | |
} | |
Web::DOM::Element* element = TRY(get_known_connected_element(element_id)); | |
if (!element) { | |
return Web::WebDriver::Error::from_code(Web::WebDriver::ErrorCode::NoSuchElement, "Element not found"); | |
} | |
auto inner_html = TRY(element->inner_html()); | |
if (inner_html.is_empty()) { | |
return ""sv | |
} | |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We don't need to check the element for null. Take a look at the implementation of get_known_connected_element
- it only returns non-null pointers, and already returns a NoSuchElement
if the element was null.
(It returns a pointer instead of a reference because ErrorOr<>
cannot hold references. We could update it to return NonnullGCPtr
instead, but that's a separate issue.)
So, this is just:
auto* element = TRY(get_known_connected_element(element_id));
// 1. If element's innerHTML IDL attribute is an empty string do nothing and return.
if (TRY(element->inner_html()).is_empty())
return JsonValue {};
(Not sure TRY
will work exactly here, since inner_html
return a DOM exception, but that's the gist of it).
Web::DOM::Element* element = TRY(get_known_connected_element(element_id)); | ||
if (!element) { | ||
return Web::WebDriver::Error::from_code(Web::WebDriver::ErrorCode::NoSuchElement, "Element not found"); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We don't need to check the element for null. Take a look at the implementation of get_known_connected_element
- it only returns non-null pointers, and already returns a NoSuchElement
if the element was null.
(It returns a pointer instead of a reference because ErrorOr<>
cannot hold references. We could update it to return NonnullGCPtr
instead, but that's a separate issue.)
So, this is just:
auto* element = TRY(get_known_connected_element(element_id));
// 1. If element's innerHTML IDL attribute is an empty string do nothing and return.
if (TRY(element->inner_html()).is_empty())
return JsonValue {};
(Not sure TRY
will work exactly here, since inner_html
return a DOM exception, but that's the gist of it).
{ | ||
dbgln("FIXME: WebDriverConnection::element_clear()"); | ||
|
||
// FIXME: 1. If element's innerHTML IDL attribute is an empty string do nothing and return. | ||
// 1. If element's innerHTML IDL attribute is an empty string do nothing and return. | ||
Web::DOM::Element* element = TRY(get_known_connected_element(element_id)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This isn't really how this should be implemented. The steps starting here are "to clear a content editable element" and seem like they're meant to be implemented as a subroutine, which we can do with a lambda. So something like:
auto clear_content_editable_element = [&](auto& element) {
// 1. If element's innerHTML IDL attribute is an empty string do nothing and return.
if (TRY(element->inner_html()).is_empty())
return JsonValue {};
// and so on...
};
Then, the implementation of element_clear
really begins at "the remote end" steps, invoking this subroutine as appropriate in step 11.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi! Thanks for the code review. It makes more sense to make clear_content_editable_element
as a lambda function :~) I've incorporated your reviews into the new push
f5df7cf
to
9657310
Compare
- Implemented part 1, 2, and 3 of the Element Clear endpoint. - Reordered Web::WebDriver::Error entries alphabetically.
9657310
to
95328ad
Compare
This PR addresses issue #1040 :~)
Overview: