while(!line.EOF())
{
line = f.ReadLine();
}
You should be able to write the following:

Code:
while(line = f.ReadLine())
{
...Do Stuff...
}
I'm not familiar with JavaScript, but this works in almost every other programming language out there. The read should return false when it hits the end of file.