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.rs33
1 files changed, 29 insertions, 4 deletions
diff --git a/components/script/dom/document.rs b/components/script/dom/document.rs
index 75a54e5c6b9..aecc0b0d0e7 100644
--- a/components/script/dom/document.rs
+++ b/components/script/dom/document.rs
@@ -364,6 +364,8 @@ pub struct Document {
tti_window: DomRefCell<InteractiveWindow>,
/// RAII canceller for Fetch
canceller: FetchCanceller,
+ /// https://html.spec.whatwg.org/multipage/#throw-on-dynamic-markup-insertion-counter
+ throw_on_dynamic_markup_insertion_counter: Cell<u64>,
}
#[derive(JSTraceable, MallocSizeOf)]
@@ -1894,7 +1896,12 @@ impl Document {
pub fn can_invoke_script(&self) -> bool {
match self.get_current_parser() {
- Some(parser) => parser.parser_is_not_active(),
+ Some(parser) => {
+ // It is safe to run script if the parser is not actively parsing,
+ // or if it is impossible to interact with the token stream.
+ parser.parser_is_not_active() ||
+ self.throw_on_dynamic_markup_insertion_counter.get() > 0
+ }
None => true,
}
}
@@ -2053,6 +2060,16 @@ impl Document {
let global_scope = self.window.upcast::<GlobalScope>();
global_scope.script_to_constellation_chan().send(msg).unwrap();
}
+
+ pub fn increment_throw_on_dynamic_markup_insertion_counter(&self) {
+ let counter = self.throw_on_dynamic_markup_insertion_counter.get();
+ self.throw_on_dynamic_markup_insertion_counter.set(counter + 1);
+ }
+
+ pub fn decrement_throw_on_dynamic_markup_insertion_counter(&self) {
+ let counter = self.throw_on_dynamic_markup_insertion_counter.get();
+ self.throw_on_dynamic_markup_insertion_counter.set(counter - 1);
+ }
}
#[derive(MallocSizeOf, PartialEq)]
@@ -2294,6 +2311,7 @@ impl Document {
interactive_time: DomRefCell::new(interactive_time),
tti_window: DomRefCell::new(InteractiveWindow::new()),
canceller: canceller,
+ throw_on_dynamic_markup_insertion_counter: Cell::new(0),
}
}
@@ -3717,7 +3735,9 @@ impl DocumentMethods for Document {
}
// Step 2.
- // TODO: handle throw-on-dynamic-markup-insertion counter.
+ if self.throw_on_dynamic_markup_insertion_counter.get() > 0 {
+ return Err(Error::InvalidState);
+ }
if !self.is_active() {
// Step 3.
@@ -3863,7 +3883,10 @@ impl DocumentMethods for Document {
}
// Step 2.
- // TODO: handle throw-on-dynamic-markup-insertion counter.
+ if self.throw_on_dynamic_markup_insertion_counter.get() > 0 {
+ return Err(Error::InvalidState);
+ }
+
if !self.is_active() {
// Step 3.
return Ok(());
@@ -3910,7 +3933,9 @@ impl DocumentMethods for Document {
}
// Step 2.
- // TODO: handle throw-on-dynamic-markup-insertion counter.
+ if self.throw_on_dynamic_markup_insertion_counter.get() > 0 {
+ return Err(Error::InvalidState);
+ }
let parser = match self.get_current_parser() {
Some(ref parser) if parser.is_script_created() => DomRoot::from_ref(&**parser),