How to use the vm.runInThisContext function in vm

To help you get started, we’ve selected a few vm examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github exokitxr / exokit / src / WindowBase.js View on Github external
function importScripts() {
  for (let i = 0; i < arguments.length; i++) {
    const importScriptPath = arguments[i];
    const importScriptSource = getScript(importScriptPath);
    vm.runInThisContext(importScriptSource, global, {
      filename: /^https?:/.test(importScriptPath) ? importScriptPath : 'data-url://',
    });
  }
}
global.importScripts = importScripts;
github jubianchi / atoum.js / lib / includer.js View on Github external
target.include = function(module) {
            var code;

            module = self.resolve(module, target);
            if(null === module.match(/\.js$/)) {
                module = module + ".js";
            }

            code = fs.readFileSync(module);

            vm.runInThisContext(code, module);
        };
github swank-js / swank-js / swank-handler.js View on Github external
function evalcx(code, context, filename) {
  try {
    return vm.runInThisContext(code, filename);
  } catch (err) {
    var regex = new RegExp('(at ' + filename + ':.*)[\\s\\S]*');
    var syntaxRegex = /\s*at evalcx[\s\S]*/;
    err.stack = err.stack.replace(syntaxRegex, '').replace(regex, '$1');
    throw err;
  }
};
var util = require("util");

vm

NodeJS Core Module Extended

MIT
Latest version published 8 years ago

Package Health Score

47 / 100
Full package analysis