安利一个在nodejs中运行js的库
发布于 9 年前 作者 joesonw 3400 次浏览 最后一次编辑是 8 年前 来自 分享

用普通的new Function(src)会暴露许多不想暴露给用户的方法。而且还不支持generator

https://github.com/brianmcd/contextify 完全的JS虚拟机(c++wrap了一下v8),可以给用户创建一个完全虚拟的运行时。

例子:

var Contextify = require('contextify');
var sandbox = { console : console, prop1 : 'prop1'}; 
Contextify(sandbox);
sandbox.run('console.log(prop1);');
sandbox.dispose(); // free the resources allocated for the context.
回到顶部