<commit_before>

/////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//
// General-purpose functions
//
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////


/**
 * Extend an object prototype with an associative array of properties
 *
 * @param baseClass a javascript class
 * @param properties an associative array of properties to add to the prototype of baseClass
 */
function extendPrototype(baseClass, properties) {
    for (var p in properties) {
        baseClass.prototype[p] = properties[p];
    }
}

/**
 * Return true if the element is usable -- not some form of nil
 *
 * @param elem the element to check
 */
function isNotNilElement(elem) {
    if (elem === undefined) return false;
    if (elem === null) return false;
    if (elem.isNotNil) return elem.isNotNil();
    return elem.toString() != "[object UIAElementNil]";
}

/**
 * "constructor" for UIAElementNil
 *
 * UIAutomation doesn't give us access to the UIAElementNil constructor, so do it our own way
 */
function newUIAElementNil() {
    return UIATarget.localTarget().frontMostApp().windows().firstWithPredicate("name == 'x' and name != 'x'");
}


/**
 * Wait for a function to return a value (i.e. not throw an exception)
 *
 * Execute a function repeatedly.  If it returns a value, return that value.
 * If the timeout is reached, re-raise the exception that the function raised.
 * Guaranteed to execute once and only once after timeout has passed, ensuring
 * that the function is given its full allotted time (2 runs minimum if only exceptions are thrown)
 *
 * @param callerName string name of calling function for logging/erroring purposes
 * @param timeout the timeout in seconds
 * @param functionReturningValue the function to execute.  can return anything.
 */
function waitForReturnValue(timeout, functionName, functionReturningValue) {
    var stopTime = now + (timeout * 1000);
    var caught = null;

    for (var now = getTime(), runsAfterTimeout = 0; now < stopTime || runsAfterTimeout < 1; now = getTime()) {
        if (now >= stopTime) {
            ++runsAfterTimeout;
        }
<commit_msg>getTime() has a one-second delay, so use a faster method<commit_after>

/////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//
// General-purpose functions
//
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////


/**
 * Extend an object prototype with an associative array of properties
 *
 * @param baseClass a javascript class
 * @param properties an associative array of properties to add to the prototype of baseClass
 */
function extendPrototype(baseClass, properties) {
    for (var p in properties) {
        baseClass.prototype[p] = properties[p];
    }
}

/**
 * Return true if the element is usable -- not some form of nil
 *
 * @param elem the element to check
 */
function isNotNilElement(elem) {
    if (elem === undefined) return false;
    if (elem === null) return false;
    if (elem.isNotNil) return elem.isNotNil();
    return elem.toString() != "[object UIAElementNil]";
}

/**
 * "constructor" for UIAElementNil
 *
 * UIAutomation doesn't give us access to the UIAElementNil constructor, so do it our own way
 */
function newUIAElementNil() {
    return UIATarget.localTarget().frontMostApp().windows().firstWithPredicate("name == 'x' and name != 'x'");
}


/**
 * Wait for a function to return a value (i.e. not throw an exception)
 *
 * Execute a function repeatedly.  If it returns a value, return that value.
 * If the timeout is reached, re-raise the exception that the function raised.
 * Guaranteed to execute once and only once after timeout has passed, ensuring
 * that the function is given its full allotted time (2 runs minimum if only exceptions are thrown)
 *
 * @param callerName string name of calling function for logging/erroring purposes
 * @param timeout the timeout in seconds
 * @param functionReturningValue the function to execute.  can return anything.
 */
function waitForReturnValue(timeout, functionName, functionReturningValue) {
    var myGetTime = function () {
        return (new Date).getTime() / 1000;
    }

    var stopTime = myGetTime() + timeout;
    var caught = null;


    for (var now = myGetTime(), runsAfterTimeout = 0; now < stopTime || runsAfterTimeout < 1; now = myGetTime()) {
        if (now >= stopTime) {
            ++runsAfterTimeout;
        }

{'fraction_non_alphanumeric': 0.18722563652326601, 'fraction_numerical': 0.0030728709394205445, 'mean_word_length': 2.3581429624170966, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2040004', 'n_tokens_mistral': 1147, 'n_tokens_neox': 1116, 'n_words': 465}