hacksparrow / safe-eval

Safer version of eval()
257 stars 37 forks source link

vm.runInNewContext and friends return the last completion value #3

Closed dead-claudia closed 6 years ago

dead-claudia commented 7 years ago

This would make the module as simple as this:

var vm = require('vm')

module.exports = function safeEval (code, context, opts) {
  var sandbox = {}
  Object.keys(context || {}).forEach(function (key) {
    sandbox[key] = context[key]
  })
  return vm.runInNewContext(code, sandbox, opts)
}
hacksparrow commented 7 years ago

@isiahmeadows a PR would be much appreciated.

dead-claudia commented 7 years ago

I'm not sure it's necessary, because as of Node 4, you could pretty much do module.exports = vm.runInNewContext directly. Before the new vm API (before Contextify was moved to core), this actually was very useful as a boilerplate module.

On Fri, Nov 18, 2016, 03:01 Hage Yaapa notifications@github.com wrote:

@isiahmeadows https://github.com/isiahmeadows a PR would be much appreciated.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/hacksparrow/safe-eval/issues/3#issuecomment-261471116, or mute the thread https://github.com/notifications/unsubscribe-auth/AERrBFyiQvXpYRUYFsfksVhD1Ke4mOvnks5q_VtJgaJpZM4K2H9s .

hacksparrow commented 6 years ago

Keeping as is for backwards-compatibility.