Auto merge of #23745 - georgeroman:implement_get_element_property_wd_command, r=jdm

Implement GetElementProperty wd command

<!-- Please describe your changes on the following line: -->

---
<!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `___` with appropriate data: -->
- [X] `./mach build -d` does not report any errors
- [X] `./mach test-tidy` does not report any errors

<!-- Either: -->
- [X] There are tests for these changes

<!-- Also, please make sure that "Allow edits from maintainers" checkbox is checked, so that we can help you if you get stuck somewhere along the way.-->

<!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. -->

<!-- Reviewable:start -->
---
This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/23745)
<!-- Reviewable:end -->
This commit is contained in:
bors-servo 2019-07-23 21:24:57 -04:00 committed by GitHub
commit 7ffe65e672
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 119 additions and 23 deletions

View file

@ -12,9 +12,11 @@ use crate::dom::bindings::codegen::Bindings::NodeBinding::NodeMethods;
use crate::dom::bindings::codegen::Bindings::WindowBinding::WindowMethods;
use crate::dom::bindings::codegen::Bindings::XMLSerializerBinding::XMLSerializerMethods;
use crate::dom::bindings::conversions::{
ConversionResult, FromJSValConvertible, StringificationBehavior,
get_property_jsval, ConversionResult, FromJSValConvertible, StringificationBehavior,
};
use crate::dom::bindings::error::throw_dom_exception;
use crate::dom::bindings::inheritance::Castable;
use crate::dom::bindings::reflector::DomObject;
use crate::dom::bindings::root::DomRoot;
use crate::dom::bindings::str::DOMString;
use crate::dom::element::Element;
@ -710,6 +712,43 @@ pub fn handle_get_attribute(
.unwrap();
}
#[allow(unsafe_code)]
pub fn handle_get_property(
documents: &Documents,
pipeline: PipelineId,
node_id: String,
name: String,
reply: IpcSender<Result<WebDriverJSValue, ()>>,
) {
reply
.send(match find_node_by_unique_id(documents, pipeline, node_id) {
Some(node) => {
let cx = documents.find_document(pipeline).unwrap().window().get_cx();
rooted!(in(cx) let mut property = UndefinedValue());
match unsafe {
get_property_jsval(
cx,
node.reflector().get_jsobject(),
&name,
property.handle_mut(),
)
} {
Ok(_) => match unsafe { jsval_to_webdriver(cx, property.handle()) } {
Ok(property) => Ok(property),
Err(_) => Ok(WebDriverJSValue::Undefined),
},
Err(error) => {
unsafe { throw_dom_exception(cx, &node.reflector().global(), error) };
Ok(WebDriverJSValue::Undefined)
},
}
},
None => Err(()),
})
.unwrap();
}
pub fn handle_get_css(
documents: &Documents,
pipeline: PipelineId,