function mapLabel(label, useStd3ASCII, transitional) {
  var mapped = [];
  for (var ch of label) {
    var cp = ch.codePointAt(0);
    var composite = idna_map.mapChar(cp);
    var flags = (composite >> 23);
    var kind = (composite >> 21) & 3;
    var index = (composite >> 5) & 0xffff;
    var length = composite & 0x1f;
    var value = idna_map.mapStr.substr(index, length);
    if (kind == 0 || (useStd3ASCII && (flags & 1))) {
      throw new Error("Illegal char " + ch);
    } else if (kind == 1) {
      mapped.push(value);
    } else if (kind == 2) {
      mapped.push(transitional ? value : ch);
    } else if (kind == 3) {
      mapped.push(ch);
    }
  }

  var newLabel = mapped.join("").normalize("NFC");
  return newLabel;
}
Emulates the HTML 5 addEventListener interface.
@param {string} eventName
@param {function({data: Object})} handler