script: Improve dirty propagation and fix script-layout synchronization.

This fixes race conditions whereby layout and script could be running
simultaneously.

r? @jdm 
cc @cgaebel 
This used to have a confusing `// FIXME: Dirty all nodes?` This was because I wasn't sure whether `ReflowEvent` needed to dirty the document. I didn't see any breakage from not doing that, so I just removed the comment.