<commit_before>/*global define*/
define([
        'require',
        './buildModuleUrl',
        './defaultValue',
        './isCrossOriginUrl',
        '../ThirdParty/when',
        '../ThirdParty/Uri'
    ], function(
        require,
        buildModuleUrl,
        defaultValue,
        isCrossOriginUrl,
        when,
        Uri) {
    "use strict";

    function completeTask(processor, event) {
        --processor._activeTasks;

        var data = event.data;
        var id = data.id;
        var result = data.result;

        var deferreds = processor._deferreds;
        var deferred = deferreds[id];

        deferred.resolve(result);

        delete deferreds[id];
    }

    var _bootstrapperUrl;
    function getBootstrapperUrl() {
        if (typeof _bootstrapperUrl !== 'undefined') {
            return _bootstrapperUrl;
        }

        _bootstrapperUrl = buildModuleUrl('Workers/cesiumWorkerBootstrapper.js');

        if (isCrossOriginUrl(_bootstrapperUrl)) {
            //to load cross-origin, create a shim worker from a blob URL
            var script = 'importScripts("' + _bootstrapperUrl + '");';

            var blob;
            try {
                blob = new Blob([script], {
                    type : 'application/javascript'
                });
            } catch (e) {
                var BlobBuilder = window.BlobBuilder || window.WebKitBlobBuilder || window.MozBlobBuilder || window.MSBlobBuilder;
                var blobBuilder = new BlobBuilder();
                blobBuilder.append(script);
                blob = blobBuilder.getBlob('application/javascript');
            }

            var URL = window.URL || window.webkitURL;
            _bootstrapperUrl = URL.createObjectURL(blob);
        }

        return _bootstrapperUrl;
    }

    function createWorker(processor) {
        var bootstrapperUrl = getBootstrapperUrl();
        var worker = new Worker(bootstrapperUrl);
        worker.postMessage = defaultValue(worker.webkitPostMessage, worker.postMessage);

        //bootstrap
        var bootstrapMessage = {
            loaderConfig : {},
            workerModule : 'Workers/' + processor._workerName
        };

        if (typeof require.toUrl !== 'undefined') {
            var resolvedBootstrapperUrl = new Uri(buildModuleUrl('Workers/cesiumWorkerBootstrapper.js')).resolve(new Uri(document.location.href));
            var baseUrl = new Uri('..').resolve(resolvedBootstrapperUrl).toString();
            bootstrapMessage.loaderConfig.baseUrl = baseUrl;
        } else {
            var workersUrl = new Uri(buildModuleUrl('Workers')).resolve(new Uri(document.location.href)).toString();
            bootstrapMessage.loaderConfig.paths = {
                'Workers' : workersUrl
            };
        }

        worker.postMessage(bootstrapMessage);

        worker.onmessage = function(event) {
            completeTask(processor, event);
        };

        processor._worker = worker;
    }

    /**
     * A wrapper around a web worker that allows scheduling tasks for a given worker,
     * returning results asynchronously via a promise.
     *
     * The Worker is not constructed until a task is scheduled.<commit_msg>Simplify some code now that buildModuleUrl always returns absolute URLs.<commit_after>/*global define*/
define([
        'require',
        './buildModuleUrl',
        './defaultValue',
        './isCrossOriginUrl',
        '../ThirdParty/when',
        '../ThirdParty/Uri'
    ], function(
        require,
        buildModuleUrl,
        defaultValue,
        isCrossOriginUrl,
        when,
        Uri) {
    "use strict";

    function completeTask(processor, event) {
        --processor._activeTasks;

        var data = event.data;
        var id = data.id;
        var result = data.result;

        var deferreds = processor._deferreds;
        var deferred = deferreds[id];

        deferred.resolve(result);

        delete deferreds[id];
    }

    var _bootstrapperUrl;
    function getBootstrapperUrl() {
        if (typeof _bootstrapperUrl !== 'undefined') {
            return _bootstrapperUrl;
        }

        _bootstrapperUrl = buildModuleUrl('Workers/cesiumWorkerBootstrapper.js');

        if (isCrossOriginUrl(_bootstrapperUrl)) {
            //to load cross-origin, create a shim worker from a blob URL
            var script = 'importScripts("' + _bootstrapperUrl + '");';

            var blob;
            try {
                blob = new Blob([script], {
                    type : 'application/javascript'
                });
            } catch (e) {
                var BlobBuilder = window.BlobBuilder || window.WebKitBlobBuilder || window.MozBlobBuilder || window.MSBlobBuilder;
                var blobBuilder = new BlobBuilder();
                blobBuilder.append(script);
                blob = blobBuilder.getBlob('application/javascript');
            }

            var URL = window.URL || window.webkitURL;
            _bootstrapperUrl = URL.createObjectURL(blob);
        }

        return _bootstrapperUrl;
    }

    function createWorker(processor) {
        var bootstrapperUrl = getBootstrapperUrl();
        var worker = new Worker(bootstrapperUrl);
        worker.postMessage = defaultValue(worker.webkitPostMessage, worker.postMessage);

        //bootstrap
        var bootstrapMessage = {
            loaderConfig : {},
            workerModule : 'Workers/' + processor._workerName
        };

        if (typeof require.toUrl !== 'undefined') {
            var baseUrl = new Uri('..').resolve(new Uri(buildModuleUrl('Workers/cesiumWorkerBootstrapper.js'))).toString();
            bootstrapMessage.loaderConfig.baseUrl = baseUrl;
        } else {
            bootstrapMessage.loaderConfig.paths = {
                'Workers' : buildModuleUrl('Workers')
            };
        }

        worker.postMessage(bootstrapMessage);

        worker.onmessage = function(event) {
            completeTask(processor, event);
        };

        processor._worker = worker;
    }

    /**
     * A wrapper around a web worker that allows scheduling tasks for a given worker,
     * returning results asynchronously via a promise.
     *
     * The Worker is not constructed until a task is scheduled.
{'fraction_non_alphanumeric': 0.10193941336752685, 'fraction_numerical': 0.0, 'mean_word_length': 1.9870751555768311, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '4525488', 'n_tokens_mistral': 1638, 'n_tokens_neox': 1573, 'n_words': 359}