mirror of
https://github.com/servo/servo.git
synced 2025-08-06 06:00:15 +01:00
Make DOMString a newtype around String, rather than a typedef.
This should make it somewhat easier to experiment with alternative representations in the future. To reduce churn, this commit leaves the String field public, though. Also, this will allow us to use the default String type to represent the IDL USVString type, which explicitly forbids unpaired surrogates, ans as such is a better match to the Rust String type.
This commit is contained in:
parent
e6aa976462
commit
6b75078503
83 changed files with 393 additions and 297 deletions
|
@ -24,6 +24,7 @@ use page::Page;
|
|||
use script_task::get_page;
|
||||
use std::rc::Rc;
|
||||
use url::Url;
|
||||
use util::str::DOMString;
|
||||
|
||||
fn find_node_by_unique_id(page: &Rc<Page>, pipeline: PipelineId, node_id: String) -> Option<Root<Node>> {
|
||||
let page = get_page(&*page, pipeline);
|
||||
|
@ -48,9 +49,8 @@ pub fn jsval_to_webdriver(cx: *mut JSContext, val: HandleValue) -> WebDriverJSRe
|
|||
Ok(WebDriverJSValue::Number(FromJSValConvertible::from_jsval(cx, val, ()).unwrap()))
|
||||
} else if val.get().is_string() {
|
||||
//FIXME: use jsstring_to_str when jsval grows to_jsstring
|
||||
Ok(
|
||||
WebDriverJSValue::String(
|
||||
FromJSValConvertible::from_jsval(cx, val, StringificationBehavior::Default).unwrap()))
|
||||
let string: DOMString = FromJSValConvertible::from_jsval(cx, val, StringificationBehavior::Default).unwrap();
|
||||
Ok(WebDriverJSValue::String(string.0))
|
||||
} else if val.get().is_null() {
|
||||
Ok(WebDriverJSValue::Null)
|
||||
} else {
|
||||
|
@ -115,7 +115,7 @@ pub fn handle_get_frame_id(page: &Rc<Page>,
|
|||
|
||||
pub fn handle_find_element_css(page: &Rc<Page>, _pipeline: PipelineId, selector: String,
|
||||
reply: IpcSender<Result<Option<String>, ()>>) {
|
||||
reply.send(match page.document().QuerySelector(selector) {
|
||||
reply.send(match page.document().QuerySelector(DOMString(selector)) {
|
||||
Ok(node) => {
|
||||
Ok(node.map(|x| x.upcast::<Node>().get_unique_id()))
|
||||
}
|
||||
|
@ -127,7 +127,7 @@ pub fn handle_find_elements_css(page: &Rc<Page>,
|
|||
_pipeline: PipelineId,
|
||||
selector: String,
|
||||
reply: IpcSender<Result<Vec<String>, ()>>) {
|
||||
reply.send(match page.document().QuerySelectorAll(selector) {
|
||||
reply.send(match page.document().QuerySelectorAll(DOMString(selector)) {
|
||||
Ok(ref nodes) => {
|
||||
let mut result = Vec::with_capacity(nodes.Length() as usize);
|
||||
for i in 0..nodes.Length() {
|
||||
|
@ -151,7 +151,7 @@ pub fn handle_get_active_element(page: &Rc<Page>,
|
|||
}
|
||||
|
||||
pub fn handle_get_title(page: &Rc<Page>, _pipeline: PipelineId, reply: IpcSender<String>) {
|
||||
reply.send(page.document().Title()).unwrap();
|
||||
reply.send(page.document().Title().0).unwrap();
|
||||
}
|
||||
|
||||
pub fn handle_get_text(page: &Rc<Page>,
|
||||
|
@ -160,7 +160,7 @@ pub fn handle_get_text(page: &Rc<Page>,
|
|||
reply: IpcSender<Result<String, ()>>) {
|
||||
reply.send(match find_node_by_unique_id(&*page, pipeline, node_id) {
|
||||
Some(ref node) => {
|
||||
Ok(node.GetTextContent().unwrap_or("".to_owned()))
|
||||
Ok(node.GetTextContent().map(|x| x.0).unwrap_or("".to_owned()))
|
||||
},
|
||||
None => Err(())
|
||||
}).unwrap();
|
||||
|
@ -172,7 +172,7 @@ pub fn handle_get_name(page: &Rc<Page>,
|
|||
reply: IpcSender<Result<String, ()>>) {
|
||||
reply.send(match find_node_by_unique_id(&*page, pipeline, node_id) {
|
||||
Some(node) => {
|
||||
Ok(node.downcast::<Element>().unwrap().TagName())
|
||||
Ok(node.downcast::<Element>().unwrap().TagName().0)
|
||||
},
|
||||
None => Err(())
|
||||
}).unwrap();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue