- Notifications
You must be signed in to change notification settings - Fork0
filecxx/TrashScript
Folders and files
| Name | Name | Last commit message | Last commit date | |
|---|---|---|---|---|
Repository files navigation
TrashScript interpreter.
The primary purpose of TrashScript is to execute scripts in environments whereeval andnew Function are restricted, such as in browser extensions.
TrashScript was originally designed for modules in thefilecxx browser extension such asThird-Party Query Interfaces which can run custom scripts.
While not all JavaScript syntax has been implemented, the most commonly used syntax is available.
TrashScript does not provide any asynchronous interfaces and does not recommend using any callback-based asynchronous execution.
Instead of setTimeout, the trashscript_lib.js offers a sleep function.
Additionally, all asynchronous functions bound withTrashScript.bind will be converted to synchronous execution.
var test = async function(val){ return new Promise(function(resolve){ setTimeout(function(){ resolve(val) },1000); });}TrashScript.bind("test",test); //bind the test functionvar ret = await test(111);console.log(ret)var ret = test(111); //no awaitconsole.log(ret)var count = 0;var func = function(){ setTimeout(function(){ if(count < 5){ alert(count++); func(); } },1000)}func();for(i=0;i<5;++i){ sleep(1000); alert(i);}TrashScript.config = { max_exec_limit:10000000 //default}var executor = TrashScript("return 123",function(e){ if(e.status === "error"){ console.log(e); }else if(e.status === "complete"){ console.log(e.result); //123 }});executor.variables({global_var1:123}); //add global variablesexecutor.exec();TrashScript.bind("alert",function(arg){ window.alert(arg);});TrashScript.bind({ console:console, test:function(){}, print:console.log, alert:alert, JSON:JSON});var executor = TrashScript("function aaa(){alert(this)};return aaa()",function(e){...});executor.exec(window); //'this' is windowvar executor = TrashScript("function aaa(){alert(this)};return aaa()",function(e){...});executor.exec({}); //'this' is an empty objectAbout
TrashScript interpreter.
Topics
Resources
License
Uh oh!
There was an error while loading.Please reload this page.