I have the following code:
var date = new Date(2010,09,09); //09.10.2010 00:00
date.setHours(-1); //sets the date to 08.10.2010 23:00
Calling date.setHours(-1); sets the date to 23:00 at the previous day (at least for Opera and Chrome).
Is this legal?
Yes, this is effectively what the specification dictates, so it would be an "illegal" implementation if it didn’t.
The actual computation happens in
MakeDate. The date is converted into milliseconds, as is the -1 hours. These are then added. Adding a negative number does subtraction, so you get an earlier date.