Skip to content

Commit

Permalink
Update window.open() to return fallible result
Browse files Browse the repository at this point in the history
  • Loading branch information
utsavoza committed May 4, 2020
1 parent 0b05b5e commit 86a5cf7
Show file tree
Hide file tree
Showing 7 changed files with 15 additions and 137 deletions.
10 changes: 3 additions & 7 deletions components/script/dom/document.rs
Expand Up @@ -4685,14 +4685,10 @@ impl DocumentMethods for Document {
url: USVString,
target: DOMString,
features: DOMString,
) -> Fallible<DomRoot<WindowProxy>> {
// WhatWG spec states this should always return a WindowProxy, but the spec for WindowProxy.open states
// it optionally returns a WindowProxy. Assume an error if window.open returns none.
// See https://github.com/whatwg/html/issues/4091
let context = self.browsing_context().ok_or(Error::InvalidAccess)?;
context
) -> Fallible<Option<DomRoot<WindowProxy>>> {
self.browsing_context()
.ok_or(Error::InvalidAccess)?
.open(url, target, features)
.ok_or(Error::InvalidAccess)
}

// https://html.spec.whatwg.org/multipage/#dom-document-write
Expand Down
2 changes: 1 addition & 1 deletion components/script/dom/webidls/Document.webidl
Expand Up @@ -124,7 +124,7 @@ partial /*sealed*/ interface Document {
[CEReactions, Throws]
Document open(optional DOMString unused1, optional DOMString unused2);
[CEReactions, Throws]
WindowProxy open(USVString url, DOMString name, DOMString features);
WindowProxy? open(USVString url, DOMString name, DOMString features);
[CEReactions, Throws]
void close();
[CEReactions, Throws]
Expand Down
4 changes: 2 additions & 2 deletions components/script/dom/webidls/Window.webidl
Expand Up @@ -40,8 +40,8 @@
// https://github.com/whatwg/html/issues/2115
[Replaceable] readonly attribute WindowProxy? parent;
readonly attribute Element? frameElement;
WindowProxy? open(optional USVString url = "", optional DOMString target = "_blank",
optional DOMString features = "");
[Throws] WindowProxy? open(optional USVString url = "", optional DOMString target = "_blank",
optional DOMString features = "");
//getter WindowProxy (unsigned long index);

// https://github.com/servo/servo/issues/14453
Expand Down
2 changes: 1 addition & 1 deletion components/script/dom/window.rs
Expand Up @@ -661,7 +661,7 @@ impl WindowMethods for Window {
url: USVString,
target: DOMString,
features: DOMString,
) -> Option<DomRoot<WindowProxy>> {
) -> Fallible<Option<DomRoot<WindowProxy>>> {
self.window_proxy().open(url, target, features)
}

Expand Down
14 changes: 7 additions & 7 deletions components/script/dom/windowproxy.rs
Expand Up @@ -4,7 +4,7 @@

use crate::dom::bindings::cell::DomRefCell;
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::proxyhandler::fill_property_descriptor;
use crate::dom::bindings::reflector::{DomObject, Reflector};
Expand Down Expand Up @@ -415,7 +415,7 @@ impl WindowProxy {
url: USVString,
target: DOMString,
features: DOMString,
) -> Option<DomRoot<WindowProxy>> {
) -> Fallible<Option<DomRoot<WindowProxy>>> {
// Step 4.
let non_empty_target = match target.as_ref() {
"" => DOMString::from("_blank"),
Expand All @@ -433,12 +433,12 @@ impl WindowProxy {
// Step 10, 11
let (chosen, new) = match self.choose_browsing_context(non_empty_target, noopener) {
(Some(chosen), new) => (chosen, new),
(None, _) => return None,
(None, _) => return Ok(None),
};
// TODO Step 12, set up browsing context features.
let target_document = match chosen.document() {
Some(target_document) => target_document,
None => return None,
None => return Ok(None),
};
let target_window = target_document.window();
// Step 13, and 14.4, will have happened elsewhere,
Expand All @@ -452,7 +452,7 @@ impl WindowProxy {
// Step 14.1
let url = match existing_document.url().join(&url) {
Ok(url) => url,
Err(_) => return None, // TODO: throw a "SyntaxError" DOMException.
Err(_) => return Err(Error::Syntax),
};
// Step 14.3
let referrer = if noreferrer {
Expand All @@ -479,10 +479,10 @@ impl WindowProxy {
}
if noopener {
// Step 15 (Dis-owning has been done in create_auxiliary_browsing_context).
return None;
return Ok(None);
}
// 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
Expand Down
@@ -1,5 +1,4 @@
[creating_browsing_context_test_01.html]
expected: TIMEOUT
[first argument: absolute url]
expected: TIMEOUT
expected: FAIL

117 changes: 0 additions & 117 deletions tests/wpt/metadata/url/failure.html.ini
Expand Up @@ -3,33 +3,12 @@
[Test URL parser failure consistency]
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]
expected: FAIL

[window.open(): http:/:@/www.example.com should throw]
expected: FAIL

[window.open(): http://user@/www.example.com should throw]
expected: FAIL

[XHR: http:@/www.example.com should throw]
expected: FAIL

Expand All @@ -42,12 +21,6 @@
[window.open(): http:/@/www.example.com should throw]
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]
expected: FAIL

Expand All @@ -60,9 +33,6 @@
[window.open(): http:/a:b@/www.example.com should throw]
expected: FAIL

[window.open(): http://a:b@/www.example.com should throw]
expected: FAIL

[XHR: http::@/www.example.com should throw]
expected: FAIL

Expand All @@ -81,27 +51,6 @@
[window.open(): http:/@:www.example.com should throw]
expected: FAIL

[window.open(): http://@:www.example.com should throw]
expected: FAIL

[window.open(): https://� 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]
expected: FAIL

Expand Down Expand Up @@ -195,69 +144,6 @@
[window.open(): sc://:12/ should throw]
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]
expected: FAIL
Expand All @@ -276,6 +162,3 @@
[window.open(): a// should throw]
expected: FAIL
[window.open(): https://� should throw]
expected: FAIL

0 comments on commit 86a5cf7

Please sign in to comment.