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 unconditionally set `NodeStyleDamaged` regardless of the attribute that was actually being set. I refined it to actually check the attribute.