Parses Unicode extension into key - value map.
Returns empty object if the extension string is invalid.
We are not concerned with the validity of the values at this point.
function parseExtension(extension) {
  var extensionSplit = %_Call(StringSplit, extension, '-');

  // Assume ['', 'u', ...] input, but don't throw.
  if (extensionSplit.length <= 2 ||
      (extensionSplit[0] !== '' && extensionSplit[1] !== 'u')) {
    return {};
  }

  // Key is {2}alphanum, value is {3,8}alphanum.
  // Some keys may not have explicit values (booleans).
  var extensionMap = {};
  var previousKey = UNDEFINED;
  for (var i = 2; i < extensionSplit.length; ++i) {
    var length = extensionSplit[i].length;
    var element = extensionSplit[i];
    if (length === 2) {
      extensionMap[element] = UNDEFINED;
      previousKey = element;
    } else if (length >= 3 && length <=8 && !IS_UNDEFINED(previousKey)) {
      extensionMap[previousKey] = element;
      previousKey = UNDEFINED;
    } else {
      // There is a value that's too long, or that doesn't have a key.
      return {};
    }
  }

  return extensionMap;
}