Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
276 views
in Technique[技术] by (71.8m points)

javascript - How to Runing scripts and code strings outside virtual machine in this script Node Js?

The following code is part of the Node-Red core node libraries, as you can see it executes scripts in a virtual machine "vm" Node Js module.

script on github node-red link

Any ideas on how the code should be written to execute script using the context of the Node Js environment instead of "vm" removing virtual machine usage?

Note: I am not interested in the problems related to executing insecure code, I just want it to do it outside the virtual machine to be able to use all the Node Js modules and their Globals without breaking Node-Red, because runInThisContext, get() and edit config.js is not the solution I want to remove the use of "vm".

Thanks for any idea

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Thanks to @knolleary

The solution is:

unsafe-function node for node-red node

unsafe-function node for node-red source

forked version of node-red

changes:

  • Replaced node "function" with node code "insecure function"
  • The node "vm" was created with the old node "function"
  • Added "text / x-red" script data help to new "function" node
  • Updated the data help of the script "text / x-red" to the new node "vm"
  • Added "require-from-string" dependency to node-red dependencies

enter image description here


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...