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

    var webpage  = require('webpage');
    var base64   = require('./libs/base64.js');
    var Renderer = function(data) { this.init(data); };

    Renderer.prototype.init = function(data) {
        this.html = data.html;

        if (data.width && data.height) {
            this.width = parseInt(data.width, 10);
            this.height = parseInt(data.height, 10);
        }

        this.timeout = data.timeout ? parseInt(data.timeout) : 100;
        if (this.timeout > 1000) { this.timeout = 1000; }

        this.page = webpage.create();

        this.setOnRenderCallback(function() {});

        this.page.onCallback = this.onPhantomCallback.bind(this);

        this.page.onConsoleMessage = function(message, lineNum, sourceId) {
            console.log('CONSOLE: ' + (typeof message == 'string' ? message : JSON.stringify(message)));
        };
    };

    Renderer.prototype.setResponse = function(response) {
        this.response = response;
    };

    Renderer.prototype.loadPage = function() {
        if (this.width > 0 && this.height > 0) {
            this.page.viewportSize = { width: this.width, height: this.height };
        }
        this.page.open('about:blank', this.onPageReady.bind(this));
    };

    Renderer.prototype.setOnRenderCallback = function(callback) {
        this.onRenderCompleteCallback = callback;
    };

    Renderer.prototype.onPhantomCallback = function(message) {
        var data = base64.decode(this.page.renderBase64('png'));
        var decoded = '';

        for (var i = 0; i < data.length; i++) {
            decoded = decoded + String.fromCharCode(data[i]);
        }

        this.onRenderCompleteCallback(
            this.response,
            decoded
        );

        this.page.close();
    };

    Renderer.prototype.onPageReady = function() {
        this.page.content = this.html;
        var pageReady = function() {
            window.onload = function() {
                window.callPhantom('OK');
            };
            setTimeout(function() {
                window.callPhantom('OK');
            }, this.timeout);
        };
        this.page.evaluate(pageReady);
    };

    Renderer.prototype.render = function() {
        this.loadPage();
    };

    module.exports = Renderer;

})();<commit_msg>Separate onload and timeout based page completion evaluations<commit_after>(function() {
    'use strict';

    var webpage  = require('webpage');
    var base64   = require('./libs/base64.js');
    var Renderer = function(data) { this.init(data); };

    Renderer.prototype.init = function(data) {
        this.html = data.html;

        if (data.width && data.height) {
            this.width = parseInt(data.width, 10);
            this.height = parseInt(data.height, 10);
        }

        this.pageTimeout = data.timeout ? parseInt(data.timeout) : 100;
        if (this.timeout > 1000) { this.timeout = 1000; }

        this.pageOnLoad = data.onload ? true : false;

        this.page = webpage.create();

        this.setOnRenderCallback(function() {});

        this.page.onCallback = this.onPhantomCallback.bind(this);

        this.page.onConsoleMessage = function(message, lineNum, sourceId) {
            console.log('CONSOLE: ' + (typeof message == 'string' ? message : JSON.stringify(message)));
        };
    };

    Renderer.prototype.setResponse = function(response) {
        this.response = response;
    };

    Renderer.prototype.loadPage = function() {
        if (this.width > 0 && this.height > 0) {
            this.page.viewportSize = { width: this.width, height: this.height };
        }
        this.page.open('about:blank', this.onPageReady.bind(this));
    };

    Renderer.prototype.setOnRenderCallback = function(callback) {
        this.onRenderCompleteCallback = callback;
    };

    Renderer.prototype.onPhantomCallback = function(message) {
        var data = base64.decode(this.page.renderBase64('png'));
        var decoded = '';

        for (var i = 0; i < data.length; i++) {
            decoded = decoded + String.fromCharCode(data[i]);
        }

        this.onRenderCompleteCallback(
            this.response,
            decoded
        );

        this.page.close();
    };

    Renderer.prototype.onPageReady = function() {
        this.page.content = this.html;

        if (this.pageOnLoad) {
            var pageOnLoad = function() {
                window.onload = function() {
                    window.callPhantom('OK');
                };
            };
            this.page.evaluate(pageOnLoad);
        }

        if (this.pageTimeout > 0) {
            var pageTimeout = function() {
                setTimeout(function() {
                    window.callPhantom('OK');
                }, this.pageTimeout);
            };
            this.page.evaluate(pageTimeout);
        }
    };

    Renderer.prototype.render = function() {
        this.loadPage();
    };

    module.exports = Renderer;

})();
{'fraction_non_alphanumeric': 0.13715660717866454, 'fraction_numerical': 0.010627631842791257, 'mean_word_length': 2.0322188449848024, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 10, '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': '2297396', 'n_tokens_mistral': 1500, 'n_tokens_neox': 1378, 'n_words': 244}