function augment(regex, captureNames, xSource, xFlags, isInternalOnly) {
    regex[REGEX_DATA] = {
        captureNames
    };

    if (isInternalOnly) {
        return regex;
    }

    // Can't auto-inherit these since the XRegExp constructor returns a nonprimitive value
    if (regex.__proto__) {
        regex.__proto__ = XRegExp.prototype;
    } else {
        for (const p in XRegExp.prototype) {
            // An `XRegExp.prototype.hasOwnProperty(p)` check wouldn't be worth it here, since this
            // is performance sensitive, and enumerable `Object.prototype` or `RegExp.prototype`
            // extensions exist on `regex.prototype` anyway
            regex[p] = XRegExp.prototype[p];
        }
    }

    regex[REGEX_DATA].source = xSource;
    // Emulate the ES6 `flags` prop by ensuring flags are in alphabetical order
    regex[REGEX_DATA].flags = xFlags ? xFlags.split('').sort().join('') : xFlags;

    return regex;
}
Attaches extended data and `XRegExp.prototype` properties to a regex object.

@private
@param {RegExp} regex Regex to augment.
@param {Array} captureNames Array with capture names, or `null`.
@param {String} xSource XRegExp pattern used to generate `regex`, or `null` if N/A.
@param {String} xFlags XRegExp flags used to generate `regex`, or `null` if N/A.
@param {Boolean} [isInternalOnly=false] Whether the regex will be used only for internal
  operations, and never exposed to users. For internal-only regexes, we can improve perf by
  skipping some operations like attaching `XRegExp.prototype` properties.
@returns {!RegExp} Augmented regex.