Implement WorkerGlobalScope.location.

This commit is contained in:
Ms2ger 2014-08-13 12:20:07 +02:00
parent fe3b62e9b4
commit e7dd281979
25 changed files with 114 additions and 93 deletions

View file

@ -0,0 +1,23 @@
/* -*- Mode: IDL; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
// http://url.spec.whatwg.org/#urlutilsreadonly
[NoInterfaceObject/*,
Exposed=(Window,Worker)*/]
interface URLUtilsReadOnly {
//stringifier readonly attribute ScalarValueString href;
readonly attribute DOMString href;
//readonly attribute ScalarValueString origin;
//readonly attribute ScalarValueString protocol;
//readonly attribute ScalarValueString host;
//readonly attribute ScalarValueString hostname;
//readonly attribute ScalarValueString port;
//readonly attribute ScalarValueString pathname;
//readonly attribute ScalarValueString search;
readonly attribute DOMString search;
//readonly attribute ScalarValueString hash;
readonly attribute DOMString hash;
};

View file

@ -6,7 +6,7 @@
//[Exposed=Worker]
interface WorkerGlobalScope : EventTarget {
readonly attribute WorkerGlobalScope self;
//readonly attribute WorkerLocation location;
readonly attribute WorkerLocation location;
//void close();
// attribute OnErrorEventHandler onerror;

View file

@ -0,0 +1,9 @@
/* -*- Mode: IDL; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
// http://www.whatwg.org/html/#worker-locations
//[Exposed=Worker]
interface WorkerLocation { };
WorkerLocation implements URLUtilsReadOnly;

View file

@ -9,6 +9,7 @@ use dom::bindings::js::{JS, JSRef, Temporary, OptionalSettable};
use dom::bindings::utils::{Reflectable, Reflector};
use dom::console::Console;
use dom::eventtarget::{EventTarget, WorkerGlobalScopeTypeId};
use dom::workerlocation::WorkerLocation;
use dom::workernavigator::WorkerNavigator;
use script_task::ScriptChan;
@ -33,6 +34,7 @@ pub struct WorkerGlobalScope {
js_context: Untraceable<Rc<Cx>>,
resource_task: Untraceable<ResourceTask>,
script_chan: ScriptChan,
location: Cell<Option<JS<WorkerLocation>>>,
navigator: Cell<Option<JS<WorkerNavigator>>>,
console: Cell<Option<JS<Console>>>,
}
@ -49,6 +51,7 @@ impl WorkerGlobalScope {
js_context: Untraceable::new(cx),
resource_task: Untraceable::new(resource_task),
script_chan: script_chan,
location: Cell::new(None),
navigator: Cell::new(None),
console: Cell::new(None),
}
@ -76,6 +79,14 @@ impl<'a> WorkerGlobalScopeMethods for JSRef<'a, WorkerGlobalScope> {
Temporary::from_rooted(self)
}
fn Location(&self) -> Temporary<WorkerLocation> {
if self.location.get().is_none() {
let location = WorkerLocation::new(self, self.worker_url.clone());
self.location.assign(Some(location));
}
Temporary::new(self.location.get().get_ref().clone())
}
fn Navigator(&self) -> Temporary<WorkerNavigator> {
if self.navigator.get().is_none() {
let navigator = WorkerNavigator::new(self);

View file

@ -0,0 +1,64 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
use dom::bindings::codegen::Bindings::WorkerLocationBinding;
use dom::bindings::codegen::Bindings::WorkerLocationBinding::WorkerLocationMethods;
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::workerglobalscope::WorkerGlobalScope;
use servo_util::str::DOMString;
use url::Url;
#[deriving(Encodable)]
pub struct WorkerLocation {
reflector_: Reflector,
url: Untraceable<Url>,
}
impl WorkerLocation {
pub fn new_inherited(url: Url) -> WorkerLocation {
WorkerLocation {
reflector_: Reflector::new(),
url: Untraceable::new(url),
}
}
pub fn new(global: &JSRef<WorkerGlobalScope>, url: Url) -> Temporary<WorkerLocation> {
reflect_dom_object(box WorkerLocation::new_inherited(url),
&Worker(*global),
WorkerLocationBinding::Wrap)
}
}
impl<'a> WorkerLocationMethods for JSRef<'a, WorkerLocation> {
fn Href(&self) -> DOMString {
self.url.serialize()
}
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())
}
}
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())
}
}
}
impl Reflectable for WorkerLocation {
fn reflector<'a>(&'a self) -> &'a Reflector {
&self.reflector_
}
}

View file

@ -191,6 +191,7 @@ pub mod dom {
pub mod window;
pub mod worker;
pub mod workerglobalscope;
pub mod workerlocation;
pub mod workernavigator;
pub mod xmlhttprequest;
pub mod xmlhttprequesteventtarget;

View file

@ -163,6 +163,7 @@ var interfaceNamesInGlobalScope = [
"Window",
"Worker",
"WorkerGlobalScope", // #2823
"WorkerLocation", // #2823
"WorkerNavigator", // #2823
"XMLHttpRequest",
"XMLHttpRequestUpload",

View file

@ -1,6 +1,5 @@
[WorkerLocation.htm]
type: testharness
expected: TIMEOUT
[Test Description: A WorkerLocation object represents an absolute URL set at its creation.]
expected: NOTRUN
expected: FAIL

View file

@ -1,6 +0,0 @@
[WorkerLocation_hash.htm]
type: testharness
expected: TIMEOUT
[Test Description: WorkerLocation.hash returns the current fragment identifier in the underlying URL.]
expected: NOTRUN

View file

@ -1,6 +0,0 @@
[WorkerLocation_hash_encoding.htm]
type: testharness
expected: TIMEOUT
[Test Description: WorkerLocation.hash returns \'#question%3f\' from input \'http://example.com/carrot#question%3f\']
expected: NOTRUN

View file

@ -1,6 +0,0 @@
[WorkerLocation_hash_nonexist.htm]
type: testharness
expected: TIMEOUT
[Test Description: WorkerLocation hash attribute returns an empty string when there is no &lt;query&gt; component in input URL.]
expected: NOTRUN

View file

@ -1,6 +0,0 @@
[WorkerLocation_host.htm]
type: testharness
expected: TIMEOUT
[Test Description: WorkerLocation host attribute returns the current host and port (if it\'s not the default port) in the underlying URL. The port part, if omitted, will be assumed to be the current scheme\'s default port.]
expected: NOTRUN

View file

@ -1,6 +0,0 @@
[WorkerLocation_hostname.htm]
type: testharness
expected: TIMEOUT
[Test Description: WorkerLocation hostname attribute returns the current host in the underlying URL.]
expected: NOTRUN

View file

@ -1,6 +0,0 @@
[WorkerLocation_href.htm]
type: testharness
expected: TIMEOUT
[Test Description: WorkerLocation href attribute must return the absolute URL that the WorkerLocation object represents.]
expected: NOTRUN

View file

@ -1,6 +1,5 @@
[WorkerLocation_port.htm]
type: testharness
expected: TIMEOUT
[Test Description: WorkerLocation port attribute returns the current port in the underlying URL.]
expected: NOTRUN
expected: FAIL

View file

@ -1,6 +0,0 @@
[WorkerLocation_protocol.htm]
type: testharness
expected: TIMEOUT
[Test Description: WorkerLocation protocol attribute returns the current scheme of the underlying URL.]
expected: NOTRUN

View file

@ -1,6 +0,0 @@
[WorkerLocation_search.htm]
type: testharness
expected: TIMEOUT
[Test Description: WorkerLocation search attribute returns the current query component in the underlying URL.]
expected: NOTRUN

View file

@ -1,6 +0,0 @@
[WorkerLocation_search_empty.htm]
type: testharness
expected: TIMEOUT
[Test Description: WorkerLocation.search Getter Condition: input is a hierarchical URL, and contained a &lt;query&gt; component (possibly an empty one).]
expected: NOTRUN

View file

@ -1,6 +0,0 @@
[WorkerLocation_search_fragment.htm]
type: testharness
expected: TIMEOUT
[Test Description: WorkerLocation.search - The (empty) &lt;fragment&gt; component is not part of the &lt;query&gt; component for input URL \'http://example.com/?test#\']
expected: NOTRUN

View file

@ -1,6 +0,0 @@
[WorkerLocation_search_nonexist.htm]
type: testharness
expected: TIMEOUT
[Test Description: WorkerLocation.search returns an empty string when there is no &lt;query&gt; component in input URL.]
expected: NOTRUN

View file

@ -1,6 +0,0 @@
[members.html]
type: testharness
expected: TIMEOUT
[members of WorkerLocation]
expected: TIMEOUT

View file

@ -1,6 +0,0 @@
[returns-same-object.html]
type: testharness
expected: TIMEOUT
[location === location]
expected: TIMEOUT

View file

@ -1,6 +1,5 @@
[setting-members.html]
type: testharness
expected: TIMEOUT
[setting members of WorkerLocation]
expected: TIMEOUT
expected: FAIL

View file

@ -1,6 +1,5 @@
[worker-separate-file.html]
type: testharness
expected: TIMEOUT
[location with a worker in separate file]
expected: TIMEOUT
expected: FAIL

View file

@ -1,6 +0,0 @@
[003.html]
type: testharness
expected: TIMEOUT
[creating 3 nested dedicated workers]
expected: TIMEOUT