It was not entirely clear to me that the process of doing .Source = '..'; and .Run() several times was just appending to the source code, like a REPL, but anyways it's cool that it works like this. However, re-defining variables or functions seem to lead to memory leaks, and I'm not sure if this is intended or part of the ECMA script or not, i.e. the following will log "A2" twice, both in Node.js and RO Script:
functionA(){console.log("A1")};A();functionA(){console.log("A2")};A();So, a short example:
EcmaScriptComponentscript=newRemObjects.Script.EcmaScriptComponent();// imagine there is a console.log()script.Source=@"function A() { console.log(""A1"") }; A(); function A() { console.log(""A2"") }; A();";script.Run();// logs A2 twicescript.Source=@"function B() { console.log(""B1"") }; B();";script.Run();// logs B1script.Source=@"function B() { console.log(""B2"") }; B();";script.Run();// logs B2script.Source=@"function B() { console.log(""B3"") }; B();";script.Run();// logs B3script.Source="var foo = 'bar';";script.Run();script.Source="var foo = ''; console.log('foo is: ' + foo)";// logs bar as expected, unless we call script.Clear() in which case "var is unexpected"-borks.script.Run();while(true){//script.Source = "var foo = 'bar';"; // leaks a bitscript.Source="function A() {}";// leaks a lotscript.Run();}
It was not entirely clear to me that the process of doing .Source = '..'; and .Run() several times was just appending to the source code, like a REPL, but anyways it's cool that it works like this. However, re-defining variables or functions seem to lead to memory leaks, and I'm not sure if this is intended or part of the ECMA script or not, i.e. the following will log "A2" twice, both in Node.js and RO Script:
So, a short example: