mirror of
https://github.com/servo/servo.git
synced 2025-07-23 07:13:52 +01:00
Update window.open() to return fallible result
This commit is contained in:
parent
0b05b5ed87
commit
86a5cf75aa
7 changed files with 15 additions and 137 deletions
|
@ -4685,14 +4685,10 @@ impl DocumentMethods for Document {
|
||||||
url: USVString,
|
url: USVString,
|
||||||
target: DOMString,
|
target: DOMString,
|
||||||
features: DOMString,
|
features: DOMString,
|
||||||
) -> Fallible<DomRoot<WindowProxy>> {
|
) -> Fallible<Option<DomRoot<WindowProxy>>> {
|
||||||
// WhatWG spec states this should always return a WindowProxy, but the spec for WindowProxy.open states
|
self.browsing_context()
|
||||||
// it optionally returns a WindowProxy. Assume an error if window.open returns none.
|
.ok_or(Error::InvalidAccess)?
|
||||||
// See https://github.com/whatwg/html/issues/4091
|
|
||||||
let context = self.browsing_context().ok_or(Error::InvalidAccess)?;
|
|
||||||
context
|
|
||||||
.open(url, target, features)
|
.open(url, target, features)
|
||||||
.ok_or(Error::InvalidAccess)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// https://html.spec.whatwg.org/multipage/#dom-document-write
|
// https://html.spec.whatwg.org/multipage/#dom-document-write
|
||||||
|
|
|
@ -124,7 +124,7 @@ partial /*sealed*/ interface Document {
|
||||||
[CEReactions, Throws]
|
[CEReactions, Throws]
|
||||||
Document open(optional DOMString unused1, optional DOMString unused2);
|
Document open(optional DOMString unused1, optional DOMString unused2);
|
||||||
[CEReactions, Throws]
|
[CEReactions, Throws]
|
||||||
WindowProxy open(USVString url, DOMString name, DOMString features);
|
WindowProxy? open(USVString url, DOMString name, DOMString features);
|
||||||
[CEReactions, Throws]
|
[CEReactions, Throws]
|
||||||
void close();
|
void close();
|
||||||
[CEReactions, Throws]
|
[CEReactions, Throws]
|
||||||
|
|
|
@ -40,8 +40,8 @@
|
||||||
// https://github.com/whatwg/html/issues/2115
|
// https://github.com/whatwg/html/issues/2115
|
||||||
[Replaceable] readonly attribute WindowProxy? parent;
|
[Replaceable] readonly attribute WindowProxy? parent;
|
||||||
readonly attribute Element? frameElement;
|
readonly attribute Element? frameElement;
|
||||||
WindowProxy? open(optional USVString url = "", optional DOMString target = "_blank",
|
[Throws] WindowProxy? open(optional USVString url = "", optional DOMString target = "_blank",
|
||||||
optional DOMString features = "");
|
optional DOMString features = "");
|
||||||
//getter WindowProxy (unsigned long index);
|
//getter WindowProxy (unsigned long index);
|
||||||
|
|
||||||
// https://github.com/servo/servo/issues/14453
|
// https://github.com/servo/servo/issues/14453
|
||||||
|
|
|
@ -661,7 +661,7 @@ impl WindowMethods for Window {
|
||||||
url: USVString,
|
url: USVString,
|
||||||
target: DOMString,
|
target: DOMString,
|
||||||
features: DOMString,
|
features: DOMString,
|
||||||
) -> Option<DomRoot<WindowProxy>> {
|
) -> Fallible<Option<DomRoot<WindowProxy>>> {
|
||||||
self.window_proxy().open(url, target, features)
|
self.window_proxy().open(url, target, features)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -4,7 +4,7 @@
|
||||||
|
|
||||||
use crate::dom::bindings::cell::DomRefCell;
|
use crate::dom::bindings::cell::DomRefCell;
|
||||||
use crate::dom::bindings::conversions::{root_from_handleobject, ToJSValConvertible};
|
use crate::dom::bindings::conversions::{root_from_handleobject, ToJSValConvertible};
|
||||||
use crate::dom::bindings::error::{throw_dom_exception, Error};
|
use crate::dom::bindings::error::{throw_dom_exception, Error, Fallible};
|
||||||
use crate::dom::bindings::inheritance::Castable;
|
use crate::dom::bindings::inheritance::Castable;
|
||||||
use crate::dom::bindings::proxyhandler::fill_property_descriptor;
|
use crate::dom::bindings::proxyhandler::fill_property_descriptor;
|
||||||
use crate::dom::bindings::reflector::{DomObject, Reflector};
|
use crate::dom::bindings::reflector::{DomObject, Reflector};
|
||||||
|
@ -415,7 +415,7 @@ impl WindowProxy {
|
||||||
url: USVString,
|
url: USVString,
|
||||||
target: DOMString,
|
target: DOMString,
|
||||||
features: DOMString,
|
features: DOMString,
|
||||||
) -> Option<DomRoot<WindowProxy>> {
|
) -> Fallible<Option<DomRoot<WindowProxy>>> {
|
||||||
// Step 4.
|
// Step 4.
|
||||||
let non_empty_target = match target.as_ref() {
|
let non_empty_target = match target.as_ref() {
|
||||||
"" => DOMString::from("_blank"),
|
"" => DOMString::from("_blank"),
|
||||||
|
@ -433,12 +433,12 @@ impl WindowProxy {
|
||||||
// Step 10, 11
|
// Step 10, 11
|
||||||
let (chosen, new) = match self.choose_browsing_context(non_empty_target, noopener) {
|
let (chosen, new) = match self.choose_browsing_context(non_empty_target, noopener) {
|
||||||
(Some(chosen), new) => (chosen, new),
|
(Some(chosen), new) => (chosen, new),
|
||||||
(None, _) => return None,
|
(None, _) => return Ok(None),
|
||||||
};
|
};
|
||||||
// TODO Step 12, set up browsing context features.
|
// TODO Step 12, set up browsing context features.
|
||||||
let target_document = match chosen.document() {
|
let target_document = match chosen.document() {
|
||||||
Some(target_document) => target_document,
|
Some(target_document) => target_document,
|
||||||
None => return None,
|
None => return Ok(None),
|
||||||
};
|
};
|
||||||
let target_window = target_document.window();
|
let target_window = target_document.window();
|
||||||
// Step 13, and 14.4, will have happened elsewhere,
|
// Step 13, and 14.4, will have happened elsewhere,
|
||||||
|
@ -452,7 +452,7 @@ impl WindowProxy {
|
||||||
// Step 14.1
|
// Step 14.1
|
||||||
let url = match existing_document.url().join(&url) {
|
let url = match existing_document.url().join(&url) {
|
||||||
Ok(url) => url,
|
Ok(url) => url,
|
||||||
Err(_) => return None, // TODO: throw a "SyntaxError" DOMException.
|
Err(_) => return Err(Error::Syntax),
|
||||||
};
|
};
|
||||||
// Step 14.3
|
// Step 14.3
|
||||||
let referrer = if noreferrer {
|
let referrer = if noreferrer {
|
||||||
|
@ -479,10 +479,10 @@ impl WindowProxy {
|
||||||
}
|
}
|
||||||
if noopener {
|
if noopener {
|
||||||
// Step 15 (Dis-owning has been done in create_auxiliary_browsing_context).
|
// Step 15 (Dis-owning has been done in create_auxiliary_browsing_context).
|
||||||
return None;
|
return Ok(None);
|
||||||
}
|
}
|
||||||
// Step 17.
|
// Step 17.
|
||||||
return target_document.browsing_context();
|
return Ok(target_document.browsing_context());
|
||||||
}
|
}
|
||||||
|
|
||||||
// https://html.spec.whatwg.org/multipage/#the-rules-for-choosing-a-browsing-context-given-a-browsing-context-name
|
// https://html.spec.whatwg.org/multipage/#the-rules-for-choosing-a-browsing-context-given-a-browsing-context-name
|
||||||
|
|
|
@ -1,5 +1,4 @@
|
||||||
[creating_browsing_context_test_01.html]
|
[creating_browsing_context_test_01.html]
|
||||||
expected: TIMEOUT
|
|
||||||
[first argument: absolute url]
|
[first argument: absolute url]
|
||||||
expected: TIMEOUT
|
expected: FAIL
|
||||||
|
|
||||||
|
|
|
@ -3,33 +3,12 @@
|
||||||
[Test URL parser failure consistency]
|
[Test URL parser failure consistency]
|
||||||
expected: FAIL
|
expected: FAIL
|
||||||
|
|
||||||
[window.open(): file://example:1/ should throw]
|
|
||||||
expected: FAIL
|
|
||||||
|
|
||||||
[window.open(): file://example:test/ should throw]
|
|
||||||
expected: FAIL
|
|
||||||
|
|
||||||
[window.open(): file://example%/ should throw]
|
|
||||||
expected: FAIL
|
|
||||||
|
|
||||||
[window.open(): file://[example\]/ should throw]
|
|
||||||
expected: FAIL
|
|
||||||
|
|
||||||
[window.open(): http://user:pass@/ should throw]
|
|
||||||
expected: FAIL
|
|
||||||
|
|
||||||
[window.open(): http://foo:-80/ should throw]
|
|
||||||
expected: FAIL
|
|
||||||
|
|
||||||
[XHR: http:/:@/www.example.com should throw]
|
[XHR: http:/:@/www.example.com should throw]
|
||||||
expected: FAIL
|
expected: FAIL
|
||||||
|
|
||||||
[window.open(): http:/:@/www.example.com should throw]
|
[window.open(): http:/:@/www.example.com should throw]
|
||||||
expected: FAIL
|
expected: FAIL
|
||||||
|
|
||||||
[window.open(): http://user@/www.example.com should throw]
|
|
||||||
expected: FAIL
|
|
||||||
|
|
||||||
[XHR: http:@/www.example.com should throw]
|
[XHR: http:@/www.example.com should throw]
|
||||||
expected: FAIL
|
expected: FAIL
|
||||||
|
|
||||||
|
@ -42,12 +21,6 @@
|
||||||
[window.open(): http:/@/www.example.com should throw]
|
[window.open(): http:/@/www.example.com should throw]
|
||||||
expected: FAIL
|
expected: FAIL
|
||||||
|
|
||||||
[window.open(): http://@/www.example.com should throw]
|
|
||||||
expected: FAIL
|
|
||||||
|
|
||||||
[window.open(): https:@/www.example.com should throw]
|
|
||||||
expected: FAIL
|
|
||||||
|
|
||||||
[XHR: http:a:b@/www.example.com should throw]
|
[XHR: http:a:b@/www.example.com should throw]
|
||||||
expected: FAIL
|
expected: FAIL
|
||||||
|
|
||||||
|
@ -60,9 +33,6 @@
|
||||||
[window.open(): http:/a:b@/www.example.com should throw]
|
[window.open(): http:/a:b@/www.example.com should throw]
|
||||||
expected: FAIL
|
expected: FAIL
|
||||||
|
|
||||||
[window.open(): http://a:b@/www.example.com should throw]
|
|
||||||
expected: FAIL
|
|
||||||
|
|
||||||
[XHR: http::@/www.example.com should throw]
|
[XHR: http::@/www.example.com should throw]
|
||||||
expected: FAIL
|
expected: FAIL
|
||||||
|
|
||||||
|
@ -81,27 +51,6 @@
|
||||||
[window.open(): http:/@:www.example.com should throw]
|
[window.open(): http:/@:www.example.com should throw]
|
||||||
expected: FAIL
|
expected: FAIL
|
||||||
|
|
||||||
[window.open(): http://@:www.example.com should throw]
|
|
||||||
expected: FAIL
|
|
||||||
|
|
||||||
[window.open(): https://<2F> should throw]
|
|
||||||
expected: FAIL
|
|
||||||
|
|
||||||
[window.open(): https://%EF%BF%BD should throw]
|
|
||||||
expected: FAIL
|
|
||||||
|
|
||||||
[window.open(): https://x x:12 should throw]
|
|
||||||
expected: FAIL
|
|
||||||
|
|
||||||
[window.open(): http://[www.google.com\]/ should throw]
|
|
||||||
expected: FAIL
|
|
||||||
|
|
||||||
[window.open(): sc:/// should throw]
|
|
||||||
expected: FAIL
|
|
||||||
|
|
||||||
[window.open(): sc:// / should throw]
|
|
||||||
expected: FAIL
|
|
||||||
|
|
||||||
[URL's constructor's base argument: sc://@/ should throw]
|
[URL's constructor's base argument: sc://@/ should throw]
|
||||||
expected: FAIL
|
expected: FAIL
|
||||||
|
|
||||||
|
@ -195,69 +144,6 @@
|
||||||
[window.open(): sc://:12/ should throw]
|
[window.open(): sc://:12/ should throw]
|
||||||
expected: FAIL
|
expected: FAIL
|
||||||
|
|
||||||
[window.open(): sc://[/ should throw]
|
|
||||||
expected: FAIL
|
|
||||||
|
|
||||||
[window.open(): sc://\\/ should throw]
|
|
||||||
expected: FAIL
|
|
||||||
|
|
||||||
[window.open(): sc://\]/ should throw]
|
|
||||||
expected: FAIL
|
|
||||||
|
|
||||||
[window.open(): sc://\x00/ should throw]
|
|
||||||
expected: FAIL
|
|
||||||
|
|
||||||
[window.open(): ftp://example.com%80/ should throw]
|
|
||||||
expected: FAIL
|
|
||||||
|
|
||||||
[window.open(): ftp://example.com%A0/ should throw]
|
|
||||||
expected: FAIL
|
|
||||||
|
|
||||||
[window.open(): https://example.com%80/ should throw]
|
|
||||||
expected: FAIL
|
|
||||||
|
|
||||||
[window.open(): https://example.com%A0/ should throw]
|
|
||||||
expected: FAIL
|
|
||||||
|
|
||||||
[window.open(): https://0x100000000/test should throw]
|
|
||||||
expected: FAIL
|
|
||||||
|
|
||||||
[window.open(): https://256.0.0.1/test should throw]
|
|
||||||
expected: FAIL
|
|
||||||
|
|
||||||
[window.open(): https://[0::0::0\] should throw]
|
|
||||||
expected: FAIL
|
|
||||||
|
|
||||||
[window.open(): https://[0:.0\] should throw]
|
|
||||||
expected: FAIL
|
|
||||||
|
|
||||||
[window.open(): https://[0:0:\] should throw]
|
|
||||||
expected: FAIL
|
|
||||||
|
|
||||||
[window.open(): https://[0:1:2:3:4:5:6:7.0.0.0.1\] should throw]
|
|
||||||
expected: FAIL
|
|
||||||
|
|
||||||
[window.open(): https://[0:1.00.0.0.0\] should throw]
|
|
||||||
expected: FAIL
|
|
||||||
|
|
||||||
[window.open(): https://[0:1.290.0.0.0\] should throw]
|
|
||||||
expected: FAIL
|
|
||||||
|
|
||||||
[window.open(): https://[0:1.23.23\] should throw]
|
|
||||||
expected: FAIL
|
|
||||||
|
|
||||||
[window.open(): http://? should throw]
|
|
||||||
expected: FAIL
|
|
||||||
|
|
||||||
[window.open(): http://# should throw]
|
|
||||||
expected: FAIL
|
|
||||||
|
|
||||||
[window.open(): non-special://[:80/ should throw]
|
|
||||||
expected: FAIL
|
|
||||||
|
|
||||||
[window.open(): http://[::127.0.0.0.1\] should throw]
|
|
||||||
expected: FAIL
|
|
||||||
|
|
||||||
[XHR: a should throw]
|
[XHR: a should throw]
|
||||||
expected: FAIL
|
expected: FAIL
|
||||||
|
|
||||||
|
@ -276,6 +162,3 @@
|
||||||
[window.open(): a// should throw]
|
[window.open(): a// should throw]
|
||||||
expected: FAIL
|
expected: FAIL
|
||||||
|
|
||||||
[window.open(): https://<2F> should throw]
|
|
||||||
expected: FAIL
|
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue