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)] [NoInterfaceObject, Exposed=(Window,Worker)]
interface WindowOrWorkerGlobalScope { interface WindowOrWorkerGlobalScope {
// [Replaceable] readonly attribute USVString origin; [Replaceable] readonly attribute USVString origin;
// base64 utility methods // base64 utility methods
[Throws] DOMString btoa(DOMString data); [Throws] DOMString btoa(DOMString data);

View file

@ -22,7 +22,7 @@ use dom::bindings::num::Finite;
use dom::bindings::refcounted::Trusted; use dom::bindings::refcounted::Trusted;
use dom::bindings::reflector::DomObject; use dom::bindings::reflector::DomObject;
use dom::bindings::root::{Dom, DomRoot, MutNullableDom}; 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::structuredclone::StructuredCloneData;
use dom::bindings::trace::RootedTraceableBox; use dom::bindings::trace::RootedTraceableBox;
use dom::bindings::utils::{GlobalStaticData, WindowProxyHandler}; use dom::bindings::utils::{GlobalStaticData, WindowProxyHandler};
@ -1038,6 +1038,11 @@ impl WindowMethods for Window {
fn Name(&self) -> DOMString { fn Name(&self) -> DOMString {
self.window_proxy().get_name() 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 { impl Window {

View file

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

View file

@ -0,0 +1,4 @@
[document_domain_setter.html]
[same-origin-domain iframe]
expected: FAIL

View file

@ -4973,9 +4973,6 @@
[Window interface: attribute onmessageerror] [Window interface: attribute onmessageerror]
expected: FAIL expected: FAIL
[Window interface: attribute origin]
expected: FAIL
[Window interface: operation createImageBitmap(ImageBitmapSource, ImageBitmapOptions)] [Window interface: operation createImageBitmap(ImageBitmapSource, ImageBitmapOptions)]
expected: FAIL expected: FAIL
@ -5075,9 +5072,6 @@
[Window interface: window must inherit property "onmessageerror" with the proper type] [Window interface: window must inherit property "onmessageerror" with the proper type]
expected: FAIL expected: FAIL
[Window interface: window must inherit property "origin" with the proper type]
expected: FAIL
[Window interface: window must inherit property "createImageBitmap(ImageBitmapSource, ImageBitmapOptions)" with the proper type] [Window interface: window must inherit property "createImageBitmap(ImageBitmapSource, ImageBitmapOptions)" with the proper type]
expected: FAIL expected: FAIL

View file

@ -1,11 +0,0 @@
[self-origin.any.worker.html]
type: testharness
[self.origin should be correct]
expected: FAIL
[self-origin.any.html]
type: testharness
[self.origin should be correct]
expected: FAIL

View file

@ -260,7 +260,7 @@
expected: FAIL expected: FAIL
[WorkerGlobalScope interface: attribute origin] [WorkerGlobalScope interface: attribute origin]
expected: FAIL expected: TIMEOUT
[WorkerGlobalScope interface: operation createImageBitmap(ImageBitmapSource, ImageBitmapOptions)] [WorkerGlobalScope interface: operation createImageBitmap(ImageBitmapSource, ImageBitmapOptions)]
expected: FAIL expected: FAIL