function encodeValue_(value) {
  if (value && (typeof value === 'object' || typeof value === 'function')) {
    var ref = objectMap ? objectMap.get(value) : objectList.indexOf(value);
    if (ref === undefined || ref === -1) {
      throw RangeError('Object not found in table.');
    }
    return {'#': ref};
  }
  if (value === undefined) {
    return {Value: 'undefined'};
  }
  if (typeof value === 'number') {
    if (value === Infinity) {
      return {Value: 'Infinity'};
    } else if (value === -Infinity) {
      return {Value: '-Infinity'};
    } else if (isNaN(value)) {
      return {Value: 'NaN'};
    } else if (1 / value === -Infinity) {
      return {Value: '-0'};
    }
  }
  return value;
}
Given a real value, encode it to a serialized value.
Most values are themselves.  But objects are references, and Infinity, NaN,
-0 and undefined are specially encoded.
@param {*} value Real value.
@returns {*} Serialized value.