meteor/backdoor.js
function isolateScope(code, closure) {
  if (typeof code === 'string') {
    code = code.split('\n');
  }
  var keys = Object.keys(closure).map(function (key) {
    return stringify(key) + ": " + key;
  });
  var chunks = [];

  chunks.push(
    "function (" + Object.keys(closure).join(', ') + ") {",
    "  'use strict';",
    "  return (function (userFunc, getClosure, action) {",
    "    try {",
    "      return action(userFunc, getClosure);",
    "    } catch (err) {",
    // this should never happen ...
    "      return { error: err.message, closure: getClosure() };",
    "    }",
    "  })("
  );

  // the code provided by the user goes here
  align(code).forEach(function (line) {
    chunks.push("    " + line);
  });
  chunks[chunks.length-1] += ',';

  chunks.push(
    // the function returning current state of the closure
    "    function () {",
    "      return { " + keys.join(', ') + " };",
    "    },",

    // the custom action
    "    arguments[arguments.length-1]",
    "  );",
    "}"
  );

  return chunks;
}
function isolateScope(code, closure) {
  if (typeof code === 'string') {
    code = code.split('\n');
  }
  var keys = Object.keys(closure).map(function (key) {
    return stringify(key) + ": " + key;
  });
  var chunks = [];

  chunks.push(
    "function (" + Object.keys(closure).join(', ') + ") {",
    "  'use strict';",
    "  return (function (userFunc, getClosure, action) {",
    "    try {",
    "      return action(userFunc, getClosure);",
    "    } catch (err) {",
    // this should never happen ...
    "      return { error: err.message, closure: getClosure() };",
    "    }",
    "  })("
  );

  // the code provided by the user goes here
  align(code).forEach(function (line) {
    chunks.push("    " + line);
  });
  chunks[chunks.length-1] += ',';

  chunks.push(
    // the function returning current state of the closure
    "    function () {",
    "      return { " + keys.join(', ') + " };",
    "    },",

    // the custom action
    "    arguments[arguments.length-1]",
    "  );",
    "}"
  );

  return chunks;
}
function isolateScope ( code , closure ) { if ( typeof code === 'string' ) { code = code . split ( '\n' ) ; } var keys = Object . keys ( closure ) . map ( function ( key ) { return stringify ( key ) + ": " + key ; } ) ; var chunks = [ ] ; chunks . push ( "function (" + Object . keys ( closure ) . join ( ', ' ) + ") {" , "  'use strict';" , "  return (function (userFunc, getClosure, action) {" , "    try {" , "      return action(userFunc, getClosure);" , "    } catch (err) {" , // this should never happen ... "      return { error: err.message, closure: getClosure() };" , "    }" , "  })(" ) ; // the code provided by the user goes here align ( code ) . forEach ( function ( line ) { chunks . push ( "    " + line ) ; } ) ; chunks [ chunks . length - 1 ] += ',' ; chunks . push ( // the function returning current state of the closure "    function () {" , "      return { " + keys . join ( ', ' ) + " };" , "    }," , // the custom action "    arguments[arguments.length-1]" , "  );" , "}" ) ; return chunks ; }
Make sure that the only local variables visible inside the code,
are those from the closure object.

@param {(string|string[])} code
@param {Object} closure
@returns {string[]}
Make sure that the only local variables visible inside the code are those from the closure object .