MCPcopy Create free account
hub / github.com/apache/pouchdb / evalFunctionInVm

Function evalFunctionInVm

lib/index.es.js:7958–7986  ·  view source on GitHub ↗
(func, emit)

Source from the content-addressed store, hash-verified

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

Callers

nothing calls this directly

Calls 4

emitFunction · 0.70
isBuiltInErrorFunction · 0.70
convertToTrueErrorFunction · 0.70
toStringMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…