(func, emit)
| 7961 | // All of this vm hullaballoo is to be able to run arbitrary code in a sandbox |
| 7962 | // for security reasons. |
| 7963 | function evalFunctionInVm(func, emit) { |
| 7964 | return function (arg1, arg2, arg3) { |
| 7965 | var code = '(function() {"use strict";' + |
| 7966 | 'var createBuiltInError = ' + createBuiltInErrorInVm.toString() + ';' + |
| 7967 | 'var sum = ' + sum.toString() + ';' + |
| 7968 | 'var log = function () {};' + |
| 7969 | 'var isArray = Array.isArray;' + |
| 7970 | 'var toJSON = JSON.parse;' + |
| 7971 | 'var __emitteds__ = [];' + |
| 7972 | 'var emit = function (key, value) {__emitteds__.push([key, value]);};' + |
| 7973 | 'var __result__ = (' + |
| 7974 | func.replace(/;\s*$/, '') + ')' + '(' + |
| 7975 | JSON.stringify(arg1) + ',' + |
| 7976 | JSON.stringify(arg2) + ',' + |
| 7977 | JSON.stringify(arg3) + ');' + |
| 7978 | 'return {result: __result__, emitteds: __emitteds__};' + |
| 7979 | '})()'; |
| 7980 | |
| 7981 | var output = vm.runInNewContext(code); |
| 7982 | |
| 7983 | output.emitteds.forEach(function (emitted) { |
| 7984 | emit(emitted[0], emitted[1]); |
| 7985 | }); |
| 7986 | if (isBuiltInError(output.result)) { |
| 7987 | output.result = convertToTrueError(output.result); |
| 7988 | } |
| 7989 | return output.result; |
| 7990 | }; |
| 7991 | } |
| 7992 | |
| 7993 | var log = guardedConsole.bind(null, 'log'); |
| 7994 | var toJSON = JSON.parse; |
nothing calls this directly
no test coverage detected
searching dependent graphs…