improve variable handling in NashfornScriptEngine

XMLWordPrintable

    • Type: Bug
    • Resolution: Fixed
    • Priority: P3
    • 8
    • Affects Version/s: None
    • Component/s: core-libs
    • None
    • b82
    • generic
    • generic

      This issue was reported by Per Bothner. The following is from his email:

      ===== email =====
      The general case of (integrating) a user-provided ScriptContext or Bindings object is painful. However, we can do better when using a ScriptEngine's default ScriptContext and Bindings.

      Specifically, I suggest:

      When in the NashornScriptEngine constructor), do:

        context.setBindings(new NashornBindings(globalObject), ScriptContext.ENGINE_SCOPE);

      where:

      /** A wrapper (proxy) for a ScriptObject viewed as a Map. */
      class NashornBindings implements Bindings {
         ScriptObject base;
         public NashornBindings(ScriptObject base) { this.base = base; }
         public Object get(Object key) { return base.get(key); }
         ... other methods implementing Bindings using base ...
      }

      Every program that uses the default ScriptContext and Bindings (which I hope most so, and which we should encourage) now works much better, because the ScriptEngine's ENGINE_SCOPE is now automatically synchronized with the globalObject: The ScriptEngine evaluator automatically sees the properties of the globalObject, and JavaScript using the same Global automatically sees the bindings done by the ScriptEngine.

            Assignee:
            Sundararajan Athijegannathan
            Reporter:
            Sundararajan Athijegannathan
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: