Hi Axel, I tried doing a similar thing for a while and found there is no pretty way to do it from the Java-side. I think the best solution is making your JS-code have no global state, by utilizing function scopes* and maybe small (custom, mutable) context objects that get passed around. Generally, the public API for providing bindings etc. certainly looks nice, but in practice I think some use-cases might just be too complicated to be supported.
Regards, Benjamin * For your small example, simply wrapping it in a function would already get rid of the issue and would even be completely thread-safe. (function() { var found; print found; found = 1; })(); On 14 June 2016 at 10:41, Axel Dörfler <ax...@pinc-software.de> wrote: > Hi Hannes, > > Am 14/06/2016 um 09:53 schrieb Hannes Wallnöfer: >> >> The problem seems to be that bindings.clear() uses the ECMAScript >> delete operation to clear the bindings, and that will only delete a >> property if it is configurable. However, var declarations are >> non-configurable and therefore „survive“. >> >> I’m not sure how to work around this, and possibly we should fix our >> implementation of clear to include non-configurable (declared) >> variables. > > > That would be great! > > Is there any other way of reusing the JS context that does not exhibit the > issue? Recreating for every call is very expensive (having a single engine, > using compiled scripts, and sharing the context brought a 100x speedup in > execution time -- and the context was responsible for half of it IIRC). > > Bye, > Axel. -- Benjamin Sieffert metrigo GmbH | A Zalando Company Lagerstraße 36 20357 Hamburg Geschäftsführer: Tobias Schlottke, Philipp Erler Die Gesellschaft ist eingetragen beim Registergericht Hamburg HRB 120447