'use strict';

// Evaluate a Javascript expression.

const babel = require('babel-core');

/* eslint no-eval: 1 */
/* jshint evil: true */

// Setup debug log
const debug = require('abacus-debug')('abacus-eval');

// Evaluate the given Javascript expression
const xeval = (s) => {
  debug('Evaluating expression %s', s);
  return eval(babel.transform('(' + s + ')', { optional: ['runtime'] }).code);
};

// Export our public functions
module.exports = xeval;


'use strict';

// Evaluate a Javascript expression.

const babel = require('babel-core');
const vm = require('vm');

/* eslint no-eval: 1 */
/* jshint evil: true */

// Setup debug log
const debug = require('abacus-debug')('abacus-eval');

// Evaluate the given Javascript expression
const xeval = (s, c) => {
  const context = c || {};
  debug('Evaluating expression %s with context %c', s, context);
  vm.createContext(context);
  return vm.runInContext(
    babel.transform('(' + s + ')', { optional: ['runtime'] }).code, context);
};

// Export our public functions
module.exports = xeval;


Allow a context to be passed into eval
Allow a context to be passed into eval

Instead of using the plain javascript eval, abacus-eval is
now using node's vm to run the provided function inside
a sandbox with a given context

See Pivotal Tracker [#106168524]
