<commit_before>var _ = require('lodash'),
    inherits = require('inherits'),
    uuid = require('uuid'),
    UniversalVM = require('uvm'),
    bootcode = require('./bootcode'),

    PostmanSandbox;


PostmanSandbox = function PostmanSandbox (options, callback) {
    this.executing = {};
    this.debug = Boolean(options && options.debug);

    UniversalVM.call(this, options, function (err, context) {
        if (err) { return callback(err); }
        context.ping(function (err) {
            callback(err, context);
            context = null;
        });
    });
};

inherits(PostmanSandbox, UniversalVM);

_.assign(PostmanSandbox.prototype, {
    ping: function (callback) {
        var packet = uuid(),
            start = Date.now();

        this.once('pong', function (echo) {
            callback((echo !== packet ? new Error('sandbox: ping packet mismatch') : null), Date.now() - start, packet);
        });

        this.dispatch('ping', packet);
    },

    /**
     * @param {String} code
     * @param {Object} options
     * @param {Boolean} options.debug
     * @param {Number} options.timeout
     * @param {String} options.scriptType - 'test', 'prerequest'
     * @param {Object} options.legacy
     * @param {Object} options.legacy.environment
     * @param {Object} options.legacy.globals
     * @param {Object} options.legacy.request
     * @param {Object} options.legacy.responseCookies
     * @param {Object} options.legacy.responseHeaders
     * @param {String} options.legacy.responseBody
     * @param {Number} options.legacy.responseTime
     * @param {Object} options.legacy.responseCode
     * @param {Object} options.legacy.tests
     * @param {Number} options.legacy.iteration
     * @param {Function} callback
     */
    execute: function (code, options, data, callback) {
        if (_.isFunction(options) && !callback) {
            callback = options;
            options = null;
        }
        !_.isObject(options) && (options = {});
        options.debug = this.debug;

        var id = uuid(),
            executionEventName = `execution.${id}`;
        this.executing[id] = true;

        // @todo decide how the results will return in a more managed fashion
        this.once(executionEventName, function (err, result) {
            delete this.executing[id];
            this.emit('execution', err, id, result);
            callback(err, result);
        });

        // set execution timeout
        // @todo add tests
        _.isFinite(options.timeout) && setTimeout(this.emit.bind(this, executionEventName,
            new Error('sandbox: execution timeout')), options.timeout);

        // send the code to the sendbox to be intercepted and executed
        this.dispatch('execute', id, code, options, data);
    },<commit_msg>Added polymorphism to the data argument of execution<commit_after>var _ = require('lodash'),
    inherits = require('inherits'),
    uuid = require('uuid'),
    UniversalVM = require('uvm'),
    bootcode = require('./bootcode'),

    PostmanSandbox;


PostmanSandbox = function PostmanSandbox (options, callback) {
    this.executing = {};
    this.debug = Boolean(options && options.debug);

    UniversalVM.call(this, options, function (err, context) {
        if (err) { return callback(err); }
        context.ping(function (err) {
            callback(err, context);
            context = null;
        });
    });
};

inherits(PostmanSandbox, UniversalVM);

_.assign(PostmanSandbox.prototype, {
    ping: function (callback) {
        var packet = uuid(),
            start = Date.now();

        this.once('pong', function (echo) {
            callback((echo !== packet ? new Error('sandbox: ping packet mismatch') : null), Date.now() - start, packet);
        });

        this.dispatch('ping', packet);
    },

    /**
     * @param {String} code
     * @param {Object} options
     * @param {Boolean} options.debug
     * @param {Number} options.timeout
     * @param {String} options.scriptType - 'test', 'prerequest'
     * @param {Object} options.legacy
     * @param {Object} options.legacy.environment
     * @param {Object} options.legacy.globals
     * @param {Object} options.legacy.request
     * @param {Object} options.legacy.responseCookies
     * @param {Object} options.legacy.responseHeaders
     * @param {String} options.legacy.responseBody
     * @param {Number} options.legacy.responseTime
     * @param {Object} options.legacy.responseCode
     * @param {Object} options.legacy.tests
     * @param {Number} options.legacy.iteration
     * @param {Function} callback
     */
    execute: function (code, options, data, callback) {
        if (_.isFunction(options) && !callback) {
            callback = options;
            options = null;
            data = null;
        }
        if (_.isFunction(data) && !callback) {
            callback = data;
            data = null;
        }

        !_.isObject(options) && (options = {});
        !_.isObject(data) && (data = {});
        options.debug = this.debug;

        var id = uuid(),
            executionEventName = `execution.${id}`;
        this.executing[id] = true;

        // @todo decide how the results will return in a more managed fashion
        this.once(executionEventName, function (err, result) {
            delete this.executing[id];
            this.emit('execution', err, id, result);
            callback(err, result);
        });

        // set execution timeout
        // @todo add tests
        _.isFinite(options.timeout) && setTimeout(this.emit.bind(this, executionEventName,
            new Error('sandbox: execution timeout')), options.timeout);

        // send the code to the sendbox to be intercepted and executed
        this.dispatch('execute', id, code, options, data);
    },
{'fraction_non_alphanumeric': 0.1360332294911734, 'fraction_numerical': 0.0, 'mean_word_length': 2.4708708708708707, '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': '3336331', 'n_tokens_mistral': 1661, 'n_tokens_neox': 1608, 'n_words': 404}