CNode

安利一个在nodejs中运行js的库

分享
Jjoesonw发布于11 年前最后回复11 年前0 回复3963 浏览0 收藏

用普通的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.
查看回复

回复 (0)

暂无回复,成为第一个参与讨论的人。
参与回复
登录后即可参与回复。登录