Auto merge of #20367 - CYBAI:ignore-type-in-document-open, r=jdm

Ignore type in document.open

Spec: https://html.spec.whatwg.org/multipage/dynamic-markup-insertion.html#dom-document-open

---
- [x] `./mach build -d` does not report any errors
- [x] `./mach test-tidy` does not report any errors
- [x] These changes fix #20279
- [x] There are tests for these changes; the tests in `dynamic-markup-insertion/opening-the-input-stream/type-argument.window.js` should pass

<!-- Reviewable:start -->
---
This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/20367)
<!-- Reviewable:end -->
This commit is contained in:
bors-servo 2018-03-20 12:32:00 -04:00 committed by GitHub
commit 730bd5ec80
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 26 additions and 56 deletions

View file

@ -132,7 +132,7 @@ use style::invalidation::element::restyle_hints::RestyleHint;
use style::media_queries::{Device, MediaList, MediaType}; use style::media_queries::{Device, MediaList, MediaType};
use style::selector_parser::{RestyleDamage, Snapshot}; use style::selector_parser::{RestyleDamage, Snapshot};
use style::shared_lock::{SharedRwLock as StyleSharedRwLock, SharedRwLockReadGuard}; use style::shared_lock::{SharedRwLock as StyleSharedRwLock, SharedRwLockReadGuard};
use style::str::{HTML_SPACE_CHARACTERS, split_html_space_chars, str_join}; use style::str::{split_html_space_chars, str_join};
use style::stylesheet_set::DocumentStylesheetSet; use style::stylesheet_set::DocumentStylesheetSet;
use style::stylesheets::{Stylesheet, StylesheetContents, Origin, OriginSet}; use style::stylesheets::{Stylesheet, StylesheetContents, Origin, OriginSet};
use task_source::TaskSource; use task_source::TaskSource;
@ -3675,7 +3675,7 @@ impl DocumentMethods for Document {
} }
// https://html.spec.whatwg.org/multipage/#dom-document-open // https://html.spec.whatwg.org/multipage/#dom-document-open
fn Open(&self, type_: DOMString, replace: DOMString) -> Fallible<DomRoot<Document>> { fn Open(&self, _type: Option<DOMString>, replace: DOMString) -> Fallible<DomRoot<Document>> {
if !self.is_html_document() { if !self.is_html_document() {
// Step 1. // Step 1.
return Err(Error::InvalidState); return Err(Error::InvalidState);
@ -3709,9 +3709,7 @@ impl DocumentMethods for Document {
// Step 6. // Step 6.
// TODO: ignore-opens-during-unload counter check. // TODO: ignore-opens-during-unload counter check.
// Step 7: first argument already bound to `type_`. // Step 7, 8.
// Step 8.
// TODO: check session history's state. // TODO: check session history's state.
let replace = replace.eq_ignore_ascii_case("replace"); let replace = replace.eq_ignore_ascii_case("replace");
@ -3740,11 +3738,11 @@ impl DocumentMethods for Document {
// Step 15. // Step 15.
Node::replace_all(None, self.upcast::<Node>()); Node::replace_all(None, self.upcast::<Node>());
// Steps 16-18. // Steps 16, 17.
// Let's not? // Let's not?
// TODO: https://github.com/whatwg/html/issues/1698 // TODO: https://github.com/whatwg/html/issues/1698
// Step 19. // Step 18.
self.implementation.set(None); self.implementation.set(None);
self.images.set(None); self.images.set(None);
self.embeds.set(None); self.embeds.set(None);
@ -3760,65 +3758,59 @@ impl DocumentMethods for Document {
self.target_element.set(None); self.target_element.set(None);
*self.last_click_info.borrow_mut() = None; *self.last_click_info.borrow_mut() = None;
// Step 19.
// TODO: Set the active document of document's browsing context to document with window.
// Step 20. // Step 20.
self.set_encoding(UTF_8); // TODO: Replace document's singleton objects with new instances of those objects, created in window's Realm.
// Step 21. // Step 21.
// TODO: reload override buffer. self.set_encoding(UTF_8);
// Step 22. // Step 22.
// TODO: reload override buffer.
// Step 23.
// TODO: salvageable flag. // TODO: salvageable flag.
let url = entry_responsible_document.url(); let url = entry_responsible_document.url();
// Step 23. // Step 24.
self.set_url(url.clone()); self.set_url(url.clone());
// Step 24. // Step 25.
// TODO: mute iframe load. // TODO: mute iframe load.
// Step 27. // Step 26.
let type_ = if type_.eq_ignore_ascii_case("replace") {
"text/html"
} else if let Some(position) = type_.find(';') {
&type_[0..position]
} else {
&*type_
};
let type_ = type_.trim_matches(HTML_SPACE_CHARACTERS);
// Step 25.
let resource_threads = let resource_threads =
self.window.upcast::<GlobalScope>().resource_threads().clone(); self.window.upcast::<GlobalScope>().resource_threads().clone();
*self.loader.borrow_mut() = *self.loader.borrow_mut() =
DocumentLoader::new_with_threads(resource_threads, Some(url.clone())); DocumentLoader::new_with_threads(resource_threads, Some(url.clone()));
ServoParser::parse_html_script_input(self, url, type_); ServoParser::parse_html_script_input(self, url, "text/html");
// Step 26. // Step 27.
self.ready_state.set(DocumentReadyState::Interactive); self.ready_state.set(DocumentReadyState::Interactive);
// Step 28 is handled when creating the parser in step 25. // Step 28.
// TODO: remove history traversal tasks.
// Step 29. // Step 29.
// TODO: truncate session history. // TODO: truncate session history.
// Step 30. // Step 30.
// TODO: remove history traversal tasks.
// Step 31.
// TODO: remove earlier entries. // TODO: remove earlier entries.
if !replace { if !replace {
// Step 32. // Step 31.
// TODO: add history entry. // TODO: add history entry.
} }
// Step 33. // Step 32.
// TODO: clear fired unload flag. // TODO: clear fired unload flag.
// Step 34 is handled when creating the parser in step 25. // Step 33 is handled when creating the parser in step 26.
// Step 35. // Step 34.
Ok(DomRoot::from_ref(self)) Ok(DomRoot::from_ref(self))
} }
@ -3851,7 +3843,7 @@ impl DocumentMethods for Document {
return Ok(()); return Ok(());
} }
// Step 5. // Step 5.
self.Open("text/html".into(), "".into())?; self.Open(None, "".into())?;
self.get_current_parser().unwrap() self.get_current_parser().unwrap()
} }
}; };

View file

@ -118,7 +118,7 @@ partial /*sealed*/ interface Document {
// dynamic markup insertion // dynamic markup insertion
[CEReactions, Throws] [CEReactions, Throws]
Document open(optional DOMString type = "text/html", optional DOMString replace = ""); Document open(optional DOMString type, optional DOMString replace = "");
// WindowProxy open(DOMString url, DOMString name, DOMString features, optional boolean replace = false); // WindowProxy open(DOMString url, DOMString name, DOMString features, optional boolean replace = false);
[CEReactions, Throws] [CEReactions, Throws]
void close(); void close();

View file

@ -1,22 +0,0 @@
[type-argument.window.html]
[document.open() with type set to: NOBODY (type argument is supposed to be ignored)]
expected: FAIL
[document.open() with type set to: @ FD ; (type argument is supposed to be ignored)]
expected: FAIL
[document.open() with type set to: it does not matter, you see \x0c (type argument is supposed to be ignored)]
expected: FAIL
[document.open() with type set to: text/plain (type argument is supposed to be ignored)]
expected: FAIL
[document.open() with type set to: text/xml (type argument is supposed to be ignored)]
expected: FAIL
[document.open() with type set to: application/octet-stream (type argument is supposed to be ignored)]
expected: FAIL
[document.open() with type set to: \x00 (type argument is supposed to be ignored)]
expected: FAIL