Partial proposal on handling DOM events, script execution, XBL constructors at a safe time
At the moment we have a fundamental problem where the following actions may
happen at unsafe times:
1) Script execution. This happens inside BindToTree, before we've sent the
document observer notification for the content addition and before we've
fired the mutation event.
2) Mutation events. These happen while processing the insertion of a document
fragment into the DOM.
In both cases the problem is rearranging the DOM in a way the caller does not
3) XBL constructors. These fire sorta towards the end (but not _at_ the end)
of frame construction. Again, the problem is messing with the not-quite-built
frame model, or DOM changes that reenter frame construction.
The only way I've been able to think of this so far is that all of these should
add a callback somewhere to be called at a safe time. Options are to either put
the callback in an array or something that would become an in param to most of
the document observer methods and at least some of the nsIContent methods or to
put the callback in the document and have some way of notifying the document
when we're starting unsafe operation and when when we're done with it.
Perhaps we can just use BeginUpdate/EndUpdate for this last? That would mean no
firing of mutation events when aNotify is false, but I believe that's desirable