Share code between Navigator and WorkerNavigator

Also shares code between Location and WorkerLocation. This has been done
by introducing NavigatorInfo and UrlHelper.

Fixes #3159
This commit is contained in:
Gilles Leblanc 2014-09-20 08:51:35 -04:00
parent de67710934
commit 652d217961
7 changed files with 81 additions and 32 deletions

View file

@ -8,6 +8,7 @@ use dom::bindings::js::{JSRef, Temporary};
use dom::bindings::global::Worker;
use dom::bindings::trace::Untraceable;
use dom::bindings::utils::{Reflectable, Reflector, reflect_dom_object};
use dom::urlhelper::UrlHelper;
use dom::workerglobalscope::WorkerGlobalScope;
use servo_util::str::DOMString;
@ -38,23 +39,15 @@ impl WorkerLocation {
impl<'a> WorkerLocationMethods for JSRef<'a, WorkerLocation> {
fn Href(&self) -> DOMString {
self.url.deref().serialize()
UrlHelper::Href(self.url.deref())
}
fn Search(&self) -> DOMString {
match self.url.query {
None => "".to_string(),
Some(ref query) if query.as_slice() == "" => "".to_string(),
Some(ref query) => "?".to_string().append(query.as_slice())
}
UrlHelper::Search(self.url.deref())
}
fn Hash(&self) -> DOMString {
match self.url.fragment {
None => "".to_string(),
Some(ref hash) if hash.as_slice() == "" => "".to_string(),
Some(ref hash) => "#".to_string().append(hash.as_slice())
}
UrlHelper::Hash(self.url.deref())
}
}