fleau.js
function(input) {
  var code = 'var $_isidentifier = ' + $_isidentifier.toString() + ';\n' +
    // FIXME: could we remove that eval?
    'eval((' + literaltovar.toString() + ')($_scope));\n';
  code += 'var $_parsers = {\n';
  var parsernames = Object.keys(parsers);
  for (var i = 0; i < parsernames.length; i++) {
    code += '  ' + JSON.stringify(parsernames[i]) + ': ' +
      parsers[parsernames[i]].toString() + ',\n';
  };
  code += '}\n';
  code += 'var $_written = "";\n' +
          'var $_write = function(data) { $_written += data; };\n';
  code += compile(input);
  code += '$_written\n';
  return function($_write, $_scope, timeout, cb) {
    var res;
    try {
      res = vm.runInNewContext(code, {$_scope: $_scope},
          {timeout: timeout || 1000});
    } catch(err) {
      console.error(err); $_write('');
      if (cb) { cb(err); }
      return;
    }
    $_write(res);
    if (cb) { cb(null); }
  };
}
function(input) {
  var code = 'var $_isidentifier = ' + $_isidentifier.toString() + ';\n' +
    // FIXME: could we remove that eval?
    'eval((' + literaltovar.toString() + ')($_scope));\n';
  code += 'var $_parsers = {\n';
  var parsernames = Object.keys(parsers);
  for (var i = 0; i < parsernames.length; i++) {
    code += '  ' + JSON.stringify(parsernames[i]) + ': ' +
      parsers[parsernames[i]].toString() + ',\n';
  };
  code += '}\n';
  code += 'var $_written = "";\n' +
          'var $_write = function(data) { $_written += data; };\n';
  code += compile(input);
  code += '$_written\n';
  return function($_write, $_scope, timeout, cb) {
    var res;
    try {
      res = vm.runInNewContext(code, {$_scope: $_scope},
          {timeout: timeout || 1000});
    } catch(err) {
      console.error(err); $_write('');
      if (cb) { cb(err); }
      return;
    }
    $_write(res);
    if (cb) { cb(null); }
  };
}
function ( input ) { var code = 'var $_isidentifier = ' + $_isidentifier . toString ( ) + ';\n' + // FIXME: could we remove that eval? 'eval((' + literaltovar . toString ( ) + ')($_scope));\n' ; code += 'var $_parsers = {\n' ; var parsernames = Object . keys ( parsers ) ; for ( var i = 0 ; i < parsernames . length ; i ++ ) { code += '  ' + JSON . stringify ( parsernames [ i ] ) + ': ' + parsers [ parsernames [ i ] ] . toString ( ) + ',\n' ; } ; code += '}\n' ; code += 'var $_written = "";\n' + 'var $_write = function(data) { $_written += data; };\n' ; code += compile ( input ) ; code += '$_written\n' ; return function ( $_write , $_scope , timeout , cb ) { var res ; try { res = vm . runInNewContext ( code , { $_scope : $_scope } , { timeout : timeout || 1000 } ) ; } catch ( err ) { console . error ( err ) ; $_write ( '' ) ; if ( cb ) { cb ( err ) ; } return ; } $_write ( res ) ; if ( cb ) { cb ( null ) ; } } ; }
Like template, with a timeout and sandbox.
Like template with a timeout and sandbox .