andreasgal/j2me.js — pull request #522 by mykmelez (2014-10-31 23:08:39+00:00)
Title: awaken text editor thread if there are dirty editors when sleep() called

If there are dirty editors when *TextEditorThread.run* calls *TextEditorThread.sleep*, the latter will never return, because it only sets *textEditorResolve* if there aren't dirty editors, so it doesn't set it, and thus *wakeTextEditorThread* doesn't call it.

That means it's possible to hang *TextEditorThread* forever by racing *TextEditorThread.run*: enter two characters quickly enough that the second one triggers a call to *wakeTextEditorThread* (which pushes the editor ID onto *dirtyEditors*) before *TextEditorThread.run* processes the first character and calls *TextEditorThread.sleep* again.

The fix is trivial: simply call the promise's *resolve* function immediately if there are dirty editors when *TextEditorThread.run* calls *TextEditorThread.sleep*.