How to use the vm.Script 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 vizorvr / patches / lib / parsePluginSlots.js View on Github external
pluginNames.map(function(pluginName) {
			var pluginId = plugins[cat][pluginName]
			var pluginSourcePath = pluginsPath+'/'+pluginId+'.plugin.js'

			var pluginSource = fs.readFileSync(pluginSourcePath)
			pluginSource += ';\n'
			pluginSource += 'var fakeNode = new Node(E2.core.root_graph, "'+pluginId+'");\n'
			pluginSource += 'var plugin = new E2.plugins.'+pluginId+'(E2.core, fakeNode);\n'

			script = new vm.Script(pluginSource, { filename: pluginId })
			script.runInContext(context)

			sandbox.plugin.input_slots.map(seenSlot(pluginId, 0))
			sandbox.plugin.output_slots.map(seenSlot(pluginId, 1))
		})
	})
github ustbhuangyi / vue-analysis / vue / src / server / bundle-renderer / create-bundle-runner.js View on Github external
function getCompiledScript (filename) {
    if (compiledScripts[filename]) {
      return compiledScripts[filename]
    }
    const code = files[filename]
    const wrapper = NativeModule.wrap(code)
    const script = new vm.Script(wrapper, {
      filename,
      displayErrors: true
    })
    compiledScripts[filename] = script
    return script
  }
github kaola-fed / megalo / src / server / bundle-renderer / create-bundle-runner.js View on Github external
function getCompiledScript (filename) {
    if (compiledScripts[filename]) {
      return compiledScripts[filename]
    }
    const code = files[filename]
    const wrapper = NativeModule.wrap(code)
    const script = new vm.Script(wrapper, {
      filename,
      displayErrors: true
    })
    compiledScripts[filename] = script
    return script
  }
github nikersify / jay / source / eval.ts View on Github external
const evaluate = async (line: string) => {
		line = wrapIfNeeded(line)

		const script = new Script(line)

		try {
			const output = await script.runInContext(context)
			context._ = output

			return {output}
		} catch (error) {
			return {error}
		}
	}
github datastax / nodejs-driver / lib / mapping / result-mapper.js View on Github external
static getSelectAdapter(info, rs) {
    const columns = rs.columns;
    if (!columns) {
      throw new Error('Expected ROWS result obtained VOID');
    }

    let scriptText = '(function rowAdapter(row, info) {\n' +
      '  const item = info.newInstance();\n';

    scriptText += columns.map(c => `  item['${info.getPropertyName(c.name)}'] = row['${c.name}'];`).join('\n');

    scriptText += '\n  return item;\n})';

    const script = new vm.Script(scriptText);
    return script.runInThisContext({ filename: 'gen-result-mapper.js'});
  }

vm

NodeJS Core Module Extended

MIT
Latest version published 8 years ago

Package Health Score

47 / 100
Full package analysis