It's approximated by the strength of the reflected IR from the LED in the device.
eg. If you look at the graphs on page 11 of the 9930 data, the output is dependant on colour or reflectivity of the target object, as well as distance.
The other is a bit more sophisticated with multiple zones to detect object in varied positions etc., but the distance principle is similar.
Low cost true distance sensors usually work on the angular offset of a reflected light spot, eg. by detecting it with a single pixel line CCD sensor through a lens.
This shows an example of that method: