Skip to content

Commit

Permalink
Add a check for when the js execution stack is empty
Browse files Browse the repository at this point in the history
  • Loading branch information
cbrewster authored and jdm committed Jan 11, 2018
1 parent 87475b1 commit 43526c8
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
6 changes: 6 additions & 0 deletions components/script/dom/bindings/settings_stack.rs
Expand Up @@ -35,6 +35,12 @@ pub unsafe fn trace(tracer: *mut JSTracer) {
})
}

pub fn is_execution_stack_empty() -> bool {
STACK.with(|stack| {
stack.borrow().is_empty()
})
}

/// RAII struct that pushes and pops entries from the script settings stack.
pub struct AutoEntryScript {
global: DomRoot<GlobalScope>,
Expand Down
5 changes: 4 additions & 1 deletion components/script/dom/servoparser/mod.rs
Expand Up @@ -13,6 +13,7 @@ use dom::bindings::inheritance::Castable;
use dom::bindings::refcounted::Trusted;
use dom::bindings::reflector::{Reflector, reflect_dom_object};
use dom::bindings::root::{Dom, DomRoot, MutNullableDom, RootedReference};
use dom::bindings::settings_stack::is_execution_stack_empty;
use dom::bindings::str::DOMString;
use dom::characterdata::CharacterData;
use dom::comment::Comment;
Expand Down Expand Up @@ -1001,7 +1002,9 @@ fn create_element_for_token(
// Step 6.1.
// TODO: handle throw-on-dynamic-markup-insertion counter.
// Step 6.2
// TODO: If the JavaScript execution context stack is empty, then perform a microtask checkpoint.
if is_execution_stack_empty() {
document.window().upcast::<GlobalScope>().perform_a_microtask_checkpoint();
}
// Step 6.3
ScriptThread::push_new_element_queue()
}
Expand Down

0 comments on commit 43526c8

Please sign in to comment.