Hi Axel,

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.

Regards,
Hannes

> Am 14.06.2016 um 09:09 schrieb Axel Dörfler <ax...@pinc-software.de>:
> 
> Hi there,
> 
> I'm trying to reduce the overhead of running JavaScript code. It looks like 
> the best thing you can do is a) share a single engine, and b) reuse the 
> script context.
> 
> I'm using a per-thread context like this:
> 
>    public static ScriptContext createJavaScriptContext() {
>        ScriptContext context = new SimpleScriptContext();
>        Bindings bindings = perThreadGlobalScope.get();
>        if (bindings == null) {
>            bindings = getJavaScriptEngine().createBindings();
>            perThreadGlobalScope.set(bindings);
>        } else
>            bindings.clear();
> 
>        context.setBindings(bindings, ScriptContext.ENGINE_SCOPE);
> 
>        return context;
>    }
> 
> Now I'm facing the problem that JavaScript variables are shared between 
> different uses.
> Ie. a:
> 
>    var found;
>    print found;
>    found = 1;
> 
> Would print "1" on the second run.
> 
> Is there a way to avoid this?
> 
> Bye,
>   Axel.

Reply via email to