Houfeng / safeify

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

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

同步执行中的while循环不能超时退出

zjl410091917 opened this issue · comments

RT,代码如下
const { Safeify } = require ("safeify");

(async ()=>{

// 创建 safeify 实例
const safeVm = new Safeify({
    timeout: 3000,
    asyncTimeout: 60000
});

// 定义 context
const context = {
    a: 1,
    b: 2,
    system: {
        add(a, b) {
            while (1){

            }
            return (a + b) * 2;
        }
    }
};

// 执行动态代码
const result= await safeVm.run(`return system.add(1,2)`, context);
console.log('result', result);

// 释放资源
safeVm.destroy();

})();

system.add 方法是 host 提供的方法呀,又不是非受信代码,你写的是受信的不会做处理。