Taritsyn / JavaScriptEngineSwitcher

JavaScript Engine Switcher determines unified interface for access to the basic features of popular JavaScript engines. This library allows you to quickly and easily switch to using of another JavaScript engine.
Apache License 2.0
439 stars 49 forks source link

It's possible to reset IJSEngine state? #90

Closed coader closed 2 years ago

coader commented 3 years ago

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; }

Taritsyn commented 3 years ago

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

Taritsyn commented 3 years ago

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

coader commented 3 years ago

got it, tks

coader commented 3 years ago

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

Taritsyn commented 3 years ago

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