Ensure that fileno() returns -1 when given an invalid file pointer.

Previously this would throw since getStreamFromPtr returns `undefined` for invalid file pointers.