function validateCloseCodeAndReason (code, reason) {
  // 1. If code is not null, but is neither an integer equal to
  //    1000 nor an integer in the range 3000 to 4999, inclusive,
  //    throw an "InvalidAccessError" DOMException.
  if (code !== null) {
    if (code !== 1000 && (code < 3000 || code > 4999)) {
      throw new DOMException('invalid code', 'InvalidAccessError')
    }
  }

  // 2. If reason is not null, then:
  if (reason !== null) {
    // 2.1. Let reasonBytes be the result of UTF-8 encoding reason.
    // 2.2. If reasonBytes is longer than 123 bytes, then throw a
    //      "SyntaxError" DOMException.
    const reasonBytesLength = Buffer.byteLength(reason)

    if (reasonBytesLength > 123) {
      throw new DOMException(`Reason must be less than 123 bytes; received ${reasonBytesLength}`, 'SyntaxError')
    }
  }
}
@see https://whatpr.org/websockets/48/7b748d3...d5570f3.html#get-a-url-record
@param {string} url
@param {string} [baseURL]