Fix a script -> layout race

When content changed, script used to immediately dirty the changed
nodes regardless of what layout was doing at the same time. The
correct thing to do in that situation is to queue the nodes, then
dirty them after layout is finished and re-run layout.

This patch makes that change.

There's also some extra debugging goodness in this patch that I found
useful when tracking down the bug.

r? @jdm @pcwalton