Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8055687

Wrong "this" passed to JSObject.eval call

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: P3 P3
    • 9
    • None
    • core-libs
    • None
    • b29
    • generic
    • generic

        Test:

        import javax.script.*;
        import jdk.nashorn.api.scripting.JSObject;

        public class Main {
          public static void main(String[] args) throws Exception {
             ScriptEngineManager m = new ScriptEngineManager();
             ScriptEngine e = m.getEngineByName("nashorn");
             JSObject jsobj = (JSObject) e.eval("({ foo: 23})");
             jsobj.eval("print(Object.keys(this))");
             jsobj.eval("print(this.foo)");
          }
        }

        Output expected:
        foo
        23

        Output seen

        undefined

        Clearly, "global" is passed as "this" to the script evaluated by JSObject.eval.

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

                Created:
                Updated:
                Resolved: