diff options
author | bors-servo <lbergstrom+bors@mozilla.com> | 2019-07-23 21:24:57 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-07-23 21:24:57 -0400 |
commit | 7ffe65e6726c4f179e97140a7ff679c6cb706c40 (patch) | |
tree | bc68b9a08471c4a32660e7c856fca653243ab237 /components/script | |
parent | 8f7440f36881fa60f4237d0dec8928799a6aa747 (diff) | |
parent | e34a15c5ef268149daef79376a981108545fa34d (diff) | |
download | servo-7ffe65e6726c4f179e97140a7ff679c6cb706c40.tar.gz servo-7ffe65e6726c4f179e97140a7ff679c6cb706c40.zip |
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 -->
Diffstat (limited to 'components/script')
-rw-r--r-- | components/script/dom/bindings/conversions.rs | 17 | ||||
-rw-r--r-- | components/script/script_thread.rs | 9 | ||||
-rw-r--r-- | components/script/webdriver_handlers.rs | 41 |
3 files changed, 61 insertions, 6 deletions
diff --git a/components/script/dom/bindings/conversions.rs b/components/script/dom/bindings/conversions.rs index 17f72956ca1..c84adf64dbb 100644 --- a/components/script/dom/bindings/conversions.rs +++ b/components/script/dom/bindings/conversions.rs @@ -60,7 +60,7 @@ use js::jsapi::{ }; use js::jsapi::{JS_NewStringCopyN, JS_StringHasLatin1Chars}; use js::jsval::{ObjectValue, StringValue, UndefinedValue}; -use js::rust::wrappers::{JS_GetProperty, JS_IsArrayObject}; +use js::rust::wrappers::{JS_GetProperty, JS_HasProperty, JS_IsArrayObject}; use js::rust::{get_object_class, is_dom_class, is_dom_object, maybe_wrap_value, ToString}; use js::rust::{HandleId, HandleObject, HandleValue, MutableHandleValue}; use num_traits::Float; @@ -596,11 +596,18 @@ pub unsafe fn get_property_jsval( Ok(cname) => cname, Err(_) => return Ok(()), }; - JS_GetProperty(cx, object, cname.as_ptr(), rval); - if JS_IsExceptionPending(cx) { - return Err(Error::JSFailed); + let mut found = false; + if JS_HasProperty(cx, object, cname.as_ptr(), &mut found) && found { + JS_GetProperty(cx, object, cname.as_ptr(), rval); + if JS_IsExceptionPending(cx) { + return Err(Error::JSFailed); + } + Ok(()) + } else if JS_IsExceptionPending(cx) { + Err(Error::JSFailed) + } else { + Ok(()) } - Ok(()) } /// Get a property from a JS object, and convert it to a Rust value. diff --git a/components/script/script_thread.rs b/components/script/script_thread.rs index 8193c9b7ace..0ceed35db57 100644 --- a/components/script/script_thread.rs +++ b/components/script/script_thread.rs @@ -2157,6 +2157,15 @@ impl ScriptThread { reply, ) }, + WebDriverScriptCommand::GetElementProperty(node_id, name, reply) => { + webdriver_handlers::handle_get_property( + &*documents, + pipeline_id, + node_id, + name, + reply, + ) + }, WebDriverScriptCommand::GetElementCSS(node_id, name, reply) => { webdriver_handlers::handle_get_css(&*documents, pipeline_id, node_id, name, reply) }, diff --git a/components/script/webdriver_handlers.rs b/components/script/webdriver_handlers.rs index 3871b7a6ef5..ab08c0efe7d 100644 --- a/components/script/webdriver_handlers.rs +++ b/components/script/webdriver_handlers.rs @@ -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, |