Right now it tries to predict what the complete input value will be after the keypress, and either allow or prevent that event.
However this is very unrealiable. For example if the limit is reached and you select all and begin typing, you can't because it will do (this.value + tobeinsertedkey) as prediction, and that's too long.
The solution is to watch *after* the key is pressed and then correct it. Because we can't simulate all possible ways of insertion:
because it caused the browser to limit the input field to 0 due to a browser bug (could be the kind of bug that is actually documented in the specification). So we'll have to do this another way.
See also: bug 38158