<commit_before>define(function () {
    'use strict';

    // Calling eval indirectly, to obtain global object (http://ecma-international.org/ecma-262/5.1/#sec-10.4.2).
    // We are making this code portable across different execution environments by not having direct reference to 'window'.
    var global = (0, eval)('this');



    /**
     * Traverses property access expression in order to obtain a value without executing this expression.
     *
     * @function
     * @param {string} expression - Property access expression in dot notation.
     * @returns Object obtained as the result of traversal of property access expression.
     */
    function resolveExpression(expression) {
        var referenceTarget;
        var propertyNames = parseExpression(expression);
        
        for (var propertyIndex = 0;
            propertyIndex < propertyNames.length;
            propertyIndex++) {
            
            var propertyName = propertyNames[propertyIndex];
            referenceTarget = resolveReference(referenceTarget, propertyName, propertyIndex);
        }

        checkReferentialSafety(referenceTarget);

        return referenceTarget;
    }

    /**
     * Parses property access expression in dot notation into individual components.
     * 
     * @function
     * @param {string} expression - Property access expression in dot notation.
     * @returns {string[]} Array of a property access expression components.
     */
    function parseExpression(expression) {
        return expression.split('.');
    }


    /**
     * Follows a reference specified with components similar to ECMAScript 5 reference components.
     *
     * @function
     * @param referenceTarget - Object to follow when resolving a reference.
     * @param {string} propertyName - Name of a property to resolve.
     * @param {number} propertyIndex - Index of a component of a property access expression.
     * @returns Object obtained as the result of reference resolution.
     */
    function resolveReference(referenceTarget, propertyName, propertyIndex) {
        var referenceBase = getReferenceBase(referenceTarget, propertyName, propertyIndex);

        if (isUnresolvableReference(referenceBase)) {
            if (propertyIndex === 0) {
                throw new ReferenceError(makeLibraryString(propertyName + ' is not defined.'));
            }
            else {
                throw new TypeError(makeLibraryString('Can\'t read ' + propertyName + ' of ' + referenceTarget + '.'));
            }
        }

        return referenceBase[propertyName];
    }

    /**
     * Deduces base component of a reference.
     * 
     * @function
     * @param referenceTarget - Object to follow when resolving a reference.
     * @param {string} propertyName - Name of a property to resolve.
     * @param {number} propertyIndex - Index of a component of a property access expression.
     * @returns Base component of a reference.
     */
    function getReferenceBase(referenceTarget, propertyName, propertyIndex) {
        if (propertyIndex === 0) {
            // Emulate behavior of unresolvable references (http://ecma-international.org/ecma-262/5.1/#sec-8.7),
            // thus minimazing impact on semantics of a program when switching from global variables to Require Global.
            if (propertyName in global) {
                return global;
            }

            return;
        }

        return referenceTarget;
    }
    
    /**
     * Determines whether reference can be resolved.
     *      Note: Algorithm is based on (http://ecma-international.org/ecma-262/5.1/#sec-8.7).
     * 
     * @function
     * @param referenceBase - Base component of a reference.
     * @returns {boolean} Is reference can't be resolved.
     */
    function isUnresolvableReference(referenceBase) {
        return (referenceBase == null);
    }

    /**
     * Checks for undesirable or surprising behavior of required object and if so, produces warnings.
     * 
     * @function
     * @param referenceTarget - Object obtained with expression resolution.
     */
    function checkReferentialSafety(referenceTarget) {
        if (referenceTarget === global) {
            printWarning('Requiring global object invalidates advantages of Require Global. Consider more granular requiring.')
        }
        else if (referenceTarget === global.eval) {
            printWarning('Indirect eval calls have unobvious runtime behavior (http://www.ecma-international.org/ecma-262/5.1/#sec-10.4.2).');
        }
    }


    /**
     * Prints a message to console in a cross-browser manner.
     * 
     * @function
     * @param {string} s - String to print.
     */
    function printWarning(s) {
        if (!global.console || !global.console.warn) {
            return;
        }

        global.console.warn(makeLibraryString(s));
    }

    /**
     * Amends string with library specific prefix.
     * 
     * @function
     * @param {string} s - String to amend.
     */
    function makeLibraryString(s) {
        return ('Require Global: ' + s);
    }



    function load(name, localRequire, onLoad, config) {
        if (config.isBuild) {
            onLoad(null);
        }
        else {
            try {
                var value = resolveExpression(name);
                onLoad(value);
            }
            catch (e) {
                onLoad.error(e);
            }
        }
    }


    return {
        load: load
    };<commit_msg>Fixed famous callback-related problem that caused onLoad to be called twice under error condition.<commit_after>define(function () {
    'use strict';

    // Calling eval indirectly, to obtain global object (http://ecma-international.org/ecma-262/5.1/#sec-10.4.2).
    // We are making this code portable across different execution environments by not having direct reference to 'window'.
    var global = (0, eval)('this');



    /**
     * Traverses property access expression in order to obtain a value without executing this expression.
     *
     * @function
     * @param {string} expression - Property access expression in dot notation.
     * @returns Object obtained as the result of traversal of property access expression.
     */
    function resolveExpression(expression) {
        var referenceTarget;
        var propertyNames = parseExpression(expression);
        
        for (var propertyIndex = 0;
            propertyIndex < propertyNames.length;
            propertyIndex++) {
            
            var propertyName = propertyNames[propertyIndex];
            referenceTarget = resolveReference(referenceTarget, propertyName, propertyIndex);
        }

        checkReferentialSafety(referenceTarget);

        return referenceTarget;
    }

    /**
     * Parses property access expression in dot notation into individual components.
     * 
     * @function
     * @param {string} expression - Property access expression in dot notation.
     * @returns {string[]} Array of a property access expression components.
     */
    function parseExpression(expression) {
        return expression.split('.');
    }


    /**
     * Follows a reference specified with components similar to ECMAScript 5 reference components.
     *
     * @function
     * @param referenceTarget - Object to follow when resolving a reference.
     * @param {string} propertyName - Name of a property to resolve.
     * @param {number} propertyIndex - Index of a component of a property access expression.
     * @returns Object obtained as the result of reference resolution.
     */
    function resolveReference(referenceTarget, propertyName, propertyIndex) {
        var referenceBase = getReferenceBase(referenceTarget, propertyName, propertyIndex);

        if (isUnresolvableReference(referenceBase)) {
            if (propertyIndex === 0) {
                throw new ReferenceError(makeLibraryString(propertyName + ' is not defined.'));
            }
            else {
                throw new TypeError(makeLibraryString('Can\'t read ' + propertyName + ' of ' + referenceTarget + '.'));
            }
        }

        return referenceBase[propertyName];
    }

    /**
     * Deduces base component of a reference.
     * 
     * @function
     * @param referenceTarget - Object to follow when resolving a reference.
     * @param {string} propertyName - Name of a property to resolve.
     * @param {number} propertyIndex - Index of a component of a property access expression.
     * @returns Base component of a reference.
     */
    function getReferenceBase(referenceTarget, propertyName, propertyIndex) {
        if (propertyIndex === 0) {
            // Emulate behavior of unresolvable references (http://ecma-international.org/ecma-262/5.1/#sec-8.7),
            // thus minimazing impact on semantics of a program when switching from global variables to Require Global.
            if (propertyName in global) {
                return global;
            }

            return;
        }

        return referenceTarget;
    }
    
    /**
     * Determines whether reference can be resolved.
     *      Note: Algorithm is based on (http://ecma-international.org/ecma-262/5.1/#sec-8.7).
     * 
     * @function
     * @param referenceBase - Base component of a reference.
     * @returns {boolean} Is reference can't be resolved.
     */
    function isUnresolvableReference(referenceBase) {
        return (referenceBase == null);
    }

    /**
     * Checks for undesirable or surprising behavior of required object and if so, produces warnings.
     * 
     * @function
     * @param referenceTarget - Object obtained with expression resolution.
     */
    function checkReferentialSafety(referenceTarget) {
        if (referenceTarget === global) {
            printWarning('Requiring global object invalidates advantages of Require Global. Consider more granular requiring.')
        }
        else if (referenceTarget === global.eval) {
            printWarning('Indirect eval calls have unobvious runtime behavior (http://www.ecma-international.org/ecma-262/5.1/#sec-10.4.2).');
        }
    }


    /**
     * Prints a message to console in a cross-browser manner.
     * 
     * @function
     * @param {string} s - String to print.
     */
    function printWarning(s) {
        if (!global.console || !global.console.warn) {
            return;
        }

        global.console.warn(makeLibraryString(s));
    }

    /**
     * Amends string with library specific prefix.
     * 
     * @function
     * @param {string} s - String to amend.
     */
    function makeLibraryString(s) {
        return ('Require Global: ' + s);
    }



    function load(name, localRequire, onLoad, config) {
        if (config.isBuild) {
            onLoad(null);
        }
        else {
            var value;
            var error;

            try {
                value = resolveExpression(name);
            }
            catch (e) {
                error = e;
            }

            if (!error) {
                onLoad(value);
            }
            else {
                onLoad.error(error);
            }
        }
    }


    return {
        load: load
    };
{'fraction_non_alphanumeric': 0.09090909090909091, 'fraction_numerical': 0.00661482077411281, 'mean_word_length': 2.140050519225372, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '1022269', 'n_tokens_mistral': 2870, 'n_tokens_neox': 2722, 'n_words': 887}