From c58837599d0eb7fefc2fe7e14dc86609c28db56b Mon Sep 17 00:00:00 2001 From: Ms2ger Date: Sat, 28 Jun 2014 14:51:54 +0200 Subject: [PATCH] Implement Location.search. --- src/components/script/dom/location.rs | 18 ++++++++++++++---- .../script/dom/webidls/URLUtils.webidl | 1 + 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/src/components/script/dom/location.rs b/src/components/script/dom/location.rs index 7afb87bf970..8e1f826a66e 100644 --- a/src/components/script/dom/location.rs +++ b/src/components/script/dom/location.rs @@ -6,13 +6,13 @@ use dom::bindings::codegen::Bindings::LocationBinding; use dom::bindings::js::{JSRef, Temporary}; use dom::bindings::utils::{Reflectable, Reflector, reflect_dom_object}; use dom::window::Window; +use page::Page; + use servo_util::str::DOMString; -use page::Page; -use std::rc::Rc; - use serialize::{Encoder, Encodable}; - +use std::rc::Rc; +use url::query_to_str; #[deriving(Encodable)] pub struct Location { @@ -37,12 +37,22 @@ impl Location { pub trait LocationMethods { fn Href(&self) -> DOMString; + fn Search(&self) -> DOMString; } impl<'a> LocationMethods for JSRef<'a, Location> { fn Href(&self) -> DOMString { self.page.get_url().to_str() } + + fn Search(&self) -> DOMString { + let query = query_to_str(&self.page.get_url().query); + if query.as_slice() == "" { + query + } else { + "?".to_string().append(query.as_slice()) + } + } } impl Reflectable for Location { diff --git a/src/components/script/dom/webidls/URLUtils.webidl b/src/components/script/dom/webidls/URLUtils.webidl index a3dd1560e43..f2e081e8963 100644 --- a/src/components/script/dom/webidls/URLUtils.webidl +++ b/src/components/script/dom/webidls/URLUtils.webidl @@ -18,6 +18,7 @@ interface URLUtils { // attribute ScalarValueString port; // attribute ScalarValueString pathname; // attribute ScalarValueString search; + readonly attribute DOMString search; // attribute URLSearchParams searchParams; // attribute ScalarValueString hash; };