aboutsummaryrefslogtreecommitdiffstats
path: root/components/script/dom/document.rs
diff options
context:
space:
mode:
Diffstat (limited to 'components/script/dom/document.rs')
-rw-r--r--components/script/dom/document.rs60
1 files changed, 40 insertions, 20 deletions
diff --git a/components/script/dom/document.rs b/components/script/dom/document.rs
index 94c9c8603c4..572c18dc129 100644
--- a/components/script/dom/document.rs
+++ b/components/script/dom/document.rs
@@ -11,7 +11,6 @@ use crate::dom::bindings::callback::ExceptionHandling;
use crate::dom::bindings::cell::DomRefCell;
use crate::dom::bindings::codegen::Bindings::BeforeUnloadEventBinding::BeforeUnloadEventBinding::BeforeUnloadEventMethods;
use crate::dom::bindings::codegen::Bindings::DocumentBinding;
-use crate::dom::bindings::codegen::Bindings::DocumentBinding::ElementCreationOptions;
use crate::dom::bindings::codegen::Bindings::DocumentBinding::{
DocumentMethods, DocumentReadyState,
};
@@ -25,7 +24,7 @@ use crate::dom::bindings::codegen::Bindings::TouchBinding::TouchMethods;
use crate::dom::bindings::codegen::Bindings::WindowBinding::{
FrameRequestCallback, ScrollBehavior, WindowMethods,
};
-use crate::dom::bindings::codegen::UnionTypes::NodeOrString;
+use crate::dom::bindings::codegen::UnionTypes::{NodeOrString, StringOrElementCreationOptions};
use crate::dom::bindings::error::{Error, ErrorResult, Fallible};
use crate::dom::bindings::inheritance::{Castable, ElementTypeId, HTMLElementTypeId, NodeTypeId};
use crate::dom::bindings::num::Finite;
@@ -371,6 +370,8 @@ pub struct Document {
page_showing: Cell<bool>,
/// Whether the document is salvageable.
salvageable: Cell<bool>,
+ /// Whether the document was aborted with an active parser
+ active_parser_was_aborted: Cell<bool>,
/// Whether the unload event has already been fired.
fired_unload: Cell<bool>,
/// List of responsive images
@@ -2265,6 +2266,7 @@ impl Document {
// Step 3.
if let Some(parser) = self.get_current_parser() {
+ self.active_parser_was_aborted.set(true);
parser.abort();
self.salvageable.set(false);
}
@@ -2813,6 +2815,7 @@ impl Document {
throw_on_dynamic_markup_insertion_counter: Cell::new(0),
page_showing: Cell::new(false),
salvageable: Cell::new(true),
+ active_parser_was_aborted: Cell::new(false),
fired_unload: Cell::new(false),
responsive_images: Default::default(),
redirect_count: Cell::new(0),
@@ -3622,7 +3625,7 @@ impl DocumentMethods for Document {
fn CreateElement(
&self,
mut local_name: DOMString,
- options: &ElementCreationOptions,
+ options: StringOrElementCreationOptions,
) -> Fallible<DomRoot<Element>> {
if xml_name_type(&local_name) == InvalidXMLName {
debug!("Not a valid element name");
@@ -3643,7 +3646,12 @@ impl DocumentMethods for Document {
};
let name = QualName::new(None, ns, LocalName::from(local_name));
- let is = options.is.as_ref().map(|is| LocalName::from(&**is));
+ let is = match options {
+ StringOrElementCreationOptions::String(_) => None,
+ StringOrElementCreationOptions::ElementCreationOptions(options) => {
+ options.is.as_ref().map(|is| LocalName::from(&**is))
+ },
+ };
Ok(Element::create(
name,
is,
@@ -3658,11 +3666,16 @@ impl DocumentMethods for Document {
&self,
namespace: Option<DOMString>,
qualified_name: DOMString,
- options: &ElementCreationOptions,
+ options: StringOrElementCreationOptions,
) -> Fallible<DomRoot<Element>> {
let (namespace, prefix, local_name) = validate_and_extract(namespace, &qualified_name)?;
let name = QualName::new(prefix, namespace, local_name);
- let is = options.is.as_ref().map(|is| LocalName::from(&**is));
+ let is = match options {
+ StringOrElementCreationOptions::String(_) => None,
+ StringOrElementCreationOptions::ElementCreationOptions(options) => {
+ options.is.as_ref().map(|is| LocalName::from(&**is))
+ },
+ };
Ok(Element::create(
name,
is,
@@ -4449,18 +4462,25 @@ impl DocumentMethods for Document {
return Ok(DomRoot::from_ref(self));
}
+ // Step 7
+ if self.active_parser_was_aborted.get() {
+ return Ok(DomRoot::from_ref(self));
+ }
+
// TODO: prompt to unload.
// TODO: set unload_event_start and unload_event_end
window_from_node(self).set_navigation_start();
- // Step 7
+ // Step 8
// TODO: https://github.com/servo/servo/issues/21937
if self.has_browsing_context() {
+ // spec says "stop document loading",
+ // which is a process that does more than just abort
self.abort();
}
- // Step 8
+ // Step 9
for node in self
.upcast::<Node>()
.traverse_preorder(ShadowIncluding::Yes)
@@ -4468,16 +4488,16 @@ impl DocumentMethods for Document {
node.upcast::<EventTarget>().remove_all_listeners();
}
- // Step 9
+ // Step 10
if self.window.Document() == DomRoot::from_ref(self) {
self.window.upcast::<EventTarget>().remove_all_listeners();
}
- // Step 10
+ // Step 11
// TODO: https://github.com/servo/servo/issues/21936
Node::replace_all(None, self.upcast::<Node>());
- // Step 11
+ // Step 12
if self.is_fully_active() {
let mut new_url = entry_responsible_document.url();
if entry_responsible_document != DomRoot::from_ref(self) {
@@ -4487,13 +4507,13 @@ impl DocumentMethods for Document {
self.set_url(new_url);
}
- // Step 12
+ // Step 13
// TODO: https://github.com/servo/servo/issues/21938
- // Step 13
+ // Step 14
self.set_quirks_mode(QuirksMode::NoQuirks);
- // Step 14
+ // Step 15
let resource_threads = self
.window
.upcast::<GlobalScope>()
@@ -4503,13 +4523,13 @@ impl DocumentMethods for Document {
DocumentLoader::new_with_threads(resource_threads, Some(self.url()));
ServoParser::parse_html_script_input(self, self.url());
- // Step 15
- self.ready_state.set(DocumentReadyState::Loading);
-
// Step 16
- // Handled when creating the parser in step 14
+ self.ready_state.set(DocumentReadyState::Loading);
// Step 17
+ // Handled when creating the parser in step 15
+
+ // Step 18
Ok(DomRoot::from_ref(self))
}
@@ -4541,8 +4561,8 @@ impl DocumentMethods for Document {
return Err(Error::InvalidState);
}
- if !self.is_active() {
- // Step 3.
+ // Step 3 - what specifies the is_active() part here?
+ if !self.is_active() || self.active_parser_was_aborted.get() {
return Ok(());
}