From 05bef140bfe39ee49147230169800ce3b23704eb Mon Sep 17 00:00:00 2001 From: csmoe Date: Tue, 7 May 2019 16:11:45 +0800 Subject: Implement worker origin member of WorkerLocation --- components/script/dom/webidls/WorkerLocation.webidl | 2 +- components/script/dom/workerlocation.rs | 13 ++++++++++++- 2 files changed, 13 insertions(+), 2 deletions(-) (limited to 'components/script') diff --git a/components/script/dom/webidls/WorkerLocation.webidl b/components/script/dom/webidls/WorkerLocation.webidl index 4a22c5e82e3..faaf10932bc 100644 --- a/components/script/dom/webidls/WorkerLocation.webidl +++ b/components/script/dom/webidls/WorkerLocation.webidl @@ -6,7 +6,7 @@ [Exposed=Worker] interface WorkerLocation { /*stringifier*/ readonly attribute USVString href; - // readonly attribute USVString origin; + readonly attribute USVString origin; readonly attribute USVString protocol; readonly attribute USVString host; readonly attribute USVString hostname; diff --git a/components/script/dom/workerlocation.rs b/components/script/dom/workerlocation.rs index 8d988fafea8..483cb69c084 100644 --- a/components/script/dom/workerlocation.rs +++ b/components/script/dom/workerlocation.rs @@ -10,7 +10,7 @@ use crate::dom::bindings::str::{DOMString, USVString}; use crate::dom::urlhelper::UrlHelper; use crate::dom::workerglobalscope::WorkerGlobalScope; use dom_struct::dom_struct; -use servo_url::ServoUrl; +use servo_url::{ImmutableOrigin, ServoUrl}; // https://html.spec.whatwg.org/multipage/#worker-locations #[dom_struct] @@ -34,6 +34,12 @@ impl WorkerLocation { WorkerLocationBinding::Wrap, ) } + + // https://html.spec.whatwg.org/multipage/#dom-workerlocation-origin + #[allow(dead_code)] + pub fn origin(&self) -> ImmutableOrigin { + self.url.origin() + } } impl WorkerLocationMethods for WorkerLocation { @@ -57,6 +63,11 @@ impl WorkerLocationMethods for WorkerLocation { UrlHelper::Href(&self.url) } + // https://html.spec.whatwg.org/multipage/#dom-workerlocation-origin + fn Origin(&self) -> USVString { + UrlHelper::Origin(&self.url) + } + // https://html.spec.whatwg.org/multipage/#dom-workerlocation-pathname fn Pathname(&self) -> USVString { UrlHelper::Pathname(&self.url) -- cgit v1.2.3