Implement WindowOrWorkerGlobalScope.origin

The test document_domain_setter.html now fails, but AFAIK the origin
comparison can never be true (document.origin is the unprefixed domain,
while the loaded iframe is from www1.…), and that test fails in all
major browsers because of security exceptions anyway.
This commit is contained in:
Anthony Ramine 2018-04-27 11:29:47 +02:00
parent 88a0265c00
commit 73b5bf201f
7 changed files with 18 additions and 21 deletions

View file

@ -9,7 +9,7 @@
[NoInterfaceObject, Exposed=(Window,Worker)]
interface WindowOrWorkerGlobalScope {
// [Replaceable] readonly attribute USVString origin;
[Replaceable] readonly attribute USVString origin;
// base64 utility methods
[Throws] DOMString btoa(DOMString data);

View file

@ -22,7 +22,7 @@ use dom::bindings::num::Finite;
use dom::bindings::refcounted::Trusted;
use dom::bindings::reflector::DomObject;
use dom::bindings::root::{Dom, DomRoot, MutNullableDom};
use dom::bindings::str::DOMString;
use dom::bindings::str::{DOMString, USVString};
use dom::bindings::structuredclone::StructuredCloneData;
use dom::bindings::trace::RootedTraceableBox;
use dom::bindings::utils::{GlobalStaticData, WindowProxyHandler};
@ -1038,6 +1038,11 @@ impl WindowMethods for Window {
fn Name(&self) -> DOMString {
self.window_proxy().get_name()
}
// https://html.spec.whatwg.org/multipage/#dom-origin
fn Origin(&self) -> USVString {
USVString(self.origin().immutable().ascii_serialization())
}
}
impl Window {

View file

@ -12,7 +12,7 @@ use dom::bindings::inheritance::Castable;
use dom::bindings::reflector::DomObject;
use dom::bindings::root::{DomRoot, MutNullableDom};
use dom::bindings::settings_stack::AutoEntryScript;
use dom::bindings::str::DOMString;
use dom::bindings::str::{DOMString, USVString};
use dom::bindings::trace::RootedTraceableBox;
use dom::crypto::Crypto;
use dom::dedicatedworkerglobalscope::DedicatedWorkerGlobalScope;
@ -328,6 +328,11 @@ impl WorkerGlobalScopeMethods for WorkerGlobalScope {
self.navigation_start_precise)
})
}
// https://html.spec.whatwg.org/multipage/#dom-origin
fn Origin(&self) -> USVString {
USVString(self.upcast::<GlobalScope>().origin().immutable().ascii_serialization())
}
}