Skip to content

Instantly share code, notes, and snippets.

@suguru03
Created December 30, 2016 11:09
Show Gist options
  • Save suguru03/a07a9f9eebc27b66542e319736ed45dd to your computer and use it in GitHub Desktop.
Save suguru03/a07a9f9eebc27b66542e319736ed45dd to your computer and use it in GitHub Desktop.
'use strict';
const fs = require('fs');
const path = require('path');
const filepath = path.resolve(__dirname, 'sample.js');
const code = fs.readFileSync(filepath, 'utf8');
const { Agent } = require('vm-agent');
const result1 = new Agent(code).run().getInnerVariable();
/**
* { test1: 'test1',
* test2: 'test2',
* test3: 'test3',
* test: [Function: test] }
*/
const result2 = new Agent(result1.test).setArguments(4, 5, 6).run().getInnerVariable();
/**
* { arg1: 4,
* arg2: 5,
* arg3: 6,
* sum: 15,
* num1: 1,
* num2: 2,
* num3: 3 }
*/
'use strict';
const test1 = 'test1';
let test2 = 'test2';
var test3 = 'test3';
function test(arg1, arg2, arg3) {
const sum = arg1 + arg2 + arg3;
let num1 = 1;
var num2 = 2;
num3 = 3;
return sum + num1 + num2 + num3;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment