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

Wrong "this" passed to JSObject.eval call

    XMLWordPrintable

Details

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

    Backports

      Description

        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.

        Attachments

          Issue Links

            Activity

              People

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

                Dates

                  Created:
                  Updated:
                  Resolved: