Small tweak to FileWriter's event sequences

The abort sequence in FileWriter looks like this:

"If readyState is DONE, throw a FileException with error code
INVALID_STATE_ERR and terminate this overall series of steps.
Set readyState to DONE.
Terminate any steps having to do with writing a file.
Dispatch a progress event called error. Set the error attribute to a
FileError object with the appropriate code (in this case, ABORT_ERR;
see error conditions).
Dispatch a progress event called abort
Dispatch a progress event called writeend
Stop dispatching any further progress events."

In this sequence, readyState gets set to DONE before any of the
progress events get sent out.  This leaves open a window of
opportunity in which one could start another write/truncate [e.g. in
onError] before the abort and writeend events get dispatched.  At that
point you'd get a writeend error that didn't refer to the write in
progress, which is at best nonintuitive.

I'm planning to move the setting of readyState to just before the
writeEnd event gets dispatched.
That way readyState==DONE always means it's safe to start another
operation, and an abort or writeend event is always  unambiguously
tied to a particular write.

Similarly, in the FileWriter's write and truncate sequences,
readyState gets set to DONE before the error and writeend progress
events are dispatched.  I'm going to make the same change there, for
the same reasons, and I'll alter the FileSaver's event sequence to
match.

Let me know if you see any problem with this.

Thanks,

     Eric

Received on Friday, 24 September 2010 20:16:18 UTC