Houfeng / safeify

📦 Safe sandbox that can be used to execute untrusted code.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

请问如何把外部变量传入?好像我这样的写法无法实现吧......

king0bear opened this issue · comments

const context = {
   system:{
     load_wasm(module_name,funtion_name,params){
       let { funtion_name } = require('../pkg/module_name.js')
       let hello = funtion_name(params) 
       delete require.cache[require.resolve('../pkg/module_name.js')]; 
       return hello
     }   
   }
 }
async function load_wasm_module(module_name,funtion_name){
   let safeVm = new Safeify({
      timeout: 50,          //超时时间,默认 50ms
      asyncTimeout: 500,    //包含异步操作的超时时间,默认 500ms
      quantity: 4,          //沙箱进程数量,默认同 CPU 核数
      memoryQuota: 500,     //沙箱最大能使用的内存(单位 m),默认 500m
      cpuQuota: 0.5,        //沙箱的 cpu 资源配额(百分比),默认 50%
    });

   hello = await safeVm.run(function (system,module_name,funtion_name) {
        return system.load_wasm(module_name,funtion_name,'hellowo');
    }, context);
   safeVm.destroy();
   console.log(hello) // hello I love you
   res.send(hello)
}