Taritsyn/JavaScriptEngineSwitcher

It's possible to reset IJSEngine state?

coader opened this issue · 5 comments

I have a script snippet, should be executed many times
so i precompile it at first, but every time execute, the engine still keep last state,
so get error: redeclared

code just like this:
'use strict'; const x=1+2+3+4; let y=2; function run( ){ return x*x; }

It's impossible. Rewrite your code as a function with parameters and execute it once. Then call the function with different parameters.

Although you can try manually removing a x, y and run global variables.

got it, tks

sorry for this issue, still another question, as it execute many times, so it's threadsafe for compile and execute?

Yes, these operations are threadsafe. There is even a test to check this.