How to use the vm.createContext 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 graalvm / graaljs / test / parallel / test-vm-proxy-failure-CP.js View on Github external
'use strict';
require('../common');
const vm = require('vm');

// Check that we do not accidentally query attributes.
// Issue: https://github.com/nodejs/node/issues/11902
const handler = {
  getOwnPropertyDescriptor: (target, prop) => {
    throw new Error('whoops');
  }
};
const sandbox = new Proxy({ foo: 'bar' }, handler);
const context = vm.createContext(sandbox);

vm.runInContext('', context);
github gabrielgrant / node-ember-precompile / src / context.js View on Github external
function getContext(sandboxExtras){
  sandbox = getBaseSandbox();
  sandboxExtras = sandboxExtras || {};
  for (var attrname in sandboxExtras){
    sandbox[attrname] = sandboxExtras[attrname];
  }
  
  // create a context for the vm using the sandbox data
  var context = vm.createContext(sandbox)

  // load Handlebars and Ember into the sandbox
  vm.runInContext(HANDLEBARSJS, context, 'handlebars.js')
  vm.runInContext(EMBERJS, context, 'ember.js')
  return context;
}
github freeCodeCamp / freeCodeCamp / curriculum / test-challenges.js View on Github external
async function runScript(scriptString, sandbox) {
  const context = vm.createContext(sandbox);
  scriptString += `;
    (async () => {
      const testResult = eval(test);
      if (typeof testResult === 'function') {
        const __result = testResult(() => code);
        if (isPromise(__result)) {
          await __result;
        }
      }
    })();`;
  const script = new vm.Script(scriptString);
  script.runInContext(context);
}
github pfrazee / libvms / lib / vm.js View on Github external
function evaluate (vm) {
  if (vm.hasEvaluated) {
    return
  }
  vm.script = new NodeVM.Script(vm.code)
  vm.sandbox = createNewSandbox(vm)
  vm.context = NodeVM.createContext(vm.sandbox)
  vm.script.runInContext(vm.context)
  vm.hasEvaluated = true
}
github sproutcore / sproutcore / lib / index.js View on Github external
var startUp = function () {
  context = vm.createContext(ctx);
  runInContext("var window = this;", "lib/index.js#startUp");
  //loadFile(pathlib.join(__dirname, 'jquery_node.js'));
  fws.forEach(loadFramework);
  loadFile(pathlib.join(curdir, '..', 'frameworks','foundation', 'system', 'benchmark.js'));
  //util.log("filesLoaded: " + util.inspect(filesLoadedInContext));
};

vm

NodeJS Core Module Extended

MIT
Latest version published 9 years ago

Package Health Score

47 / 100
Full package analysis