<commit_before>var EventEmitter = require('events').EventEmitter;
var util = require('util');
var contextify = require('contextify');
var fondue = require('fondue');
var mpath = require('mpath');

function PuzzleBox(opt) {
  EventEmitter.call(this);
  this.options = opt;
  this._code = '';
  this._calls = [];
  this._context = {};
  this._tracers = null;
}

util.inherits(PuzzleBox, EventEmitter);

// set the code
PuzzleBox.prototype.code = function(code) {
  this._code = fondue.instrument(code, {nodejs: true}).toString();
  return this;
};

// set the context object
PuzzleBox.prototype.context = function(context) {
  this.dispose();
  this._context = context;
  return this;
};

// spy on things in the context
// TODO: field accesses and sets
PuzzleBox.prototype.track = function(key, cb) {
  var newFn = this.createReplacement(key, mpath.get(key, this._context));
  mpath.set(key, newFn, this._context);
  return this;
};

// create the sandbox
PuzzleBox.prototype.build = function() {
  // create a global callback
  var that = this;
  this._context.__tracer = undefined;
  this._context.finished = function(){
    var args = Array.prototype.slice.call(arguments);
    args.unshift('finished');
    process.nextTick(function(){
      that.emit.apply(that, args);
    });
  };

  this._sandbox = contextify(this._context);
  return this;
};

// get the sandbox data
PuzzleBox.prototype.sandbox = function(){
  return this._sandbox.getGlobal();
};

// get the call data<commit_msg>use fondue<commit_after>var EventEmitter = require('events').EventEmitter;
var util = require('util');
var contextify = require('contextify');
var fondue = require('fondue');
var mpath = require('mpath');

function PuzzleBox(opt) {
  EventEmitter.call(this);
  this.options = opt;
  this._code = '';
  this._calls = [];
  this._context = {};
  this._tracers = null;
}

util.inherits(PuzzleBox, EventEmitter);

// set the code
PuzzleBox.prototype.code = function(code) {
  this._code = fondue.instrument(code, {nodejs: true}).toString();
  return this;
};

// set the context object
PuzzleBox.prototype.context = function(context) {
  this.dispose();
  this._context = context;
  return this;
};

// spy on things in the context
// TODO: field accesses and sets
PuzzleBox.prototype.track = function(key, cb) {
  var newFn = this.createReplacement(key, mpath.get(key, this._context));
  mpath.set(key, newFn, this._context);
  return this;
};

// create the sandbox
PuzzleBox.prototype.build = function() {
  // create a global callback
  var that = this;
  this._context.__tracer = undefined;
  this._context.finished = function(){
    var args = Array.prototype.slice.call(arguments);
    args.unshift('finished');
    process.nextTick(function(){
      that.emit.apply(that, args);
    });
  };
  this._context.require = this._context.require || require;
  this._context.console = this._context.console || console;
  this._sandbox = contextify(this._context);
  return this;
};

// get the sandbox data
PuzzleBox.prototype.sandbox = function(){
  return this._sandbox.getGlobal();
};

// get the call data
{'fraction_non_alphanumeric': 0.14728682170542637, 'fraction_numerical': 0.0, 'mean_word_length': 4.102141680395387, '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': '2307735', 'n_tokens_mistral': 1000, 'n_tokens_neox': 988, 'n_words': 230}