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

ScriptObjectMirror causing havoc with Invocation interface

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Closed
    • Priority: P2
    • Resolution: Fixed
    • Affects Version/s: 8u40
    • Fix Version/s: 9
    • Component/s: core-libs
    • Labels:
      None
    • Subcomponent:
    • Resolved In Build:
      b28
    • CPU:
      generic
    • OS:
      generic
    • Verification:
      Verified

      Backports

        Description

        http://mail.openjdk.java.net/pipermail/nashorn-dev/2014-July/003204.html

        Inconsistency about conversion to ScriptObjectMirror with getInterface and invokeFunction makes it difficult know which kind of object is being worked with in Nashorn. Example;

        package mirrors;

        import java.util.*;
        import javax.script.*;

        public class Mirrors {
            public interface Example {
                Object test1(Object arg);
                Object test2(Object arg);
            }
            
            public static void main(String[] args) throws Exception {
                ScriptEngineManager engineManager = new ScriptEngineManager();
                ScriptEngine engine = engineManager.getEngineByName("nashorn");
                Invocable invocable = (Invocable)engine;

                engine.eval("function test1(arg) { print(arg.class); return { arg: arg }; }");
                engine.eval("function test2(arg) { print(arg.class); return arg; }");

                Map<String, Object> map = new HashMap<>();
                map.put("option", true);

                Example example = invocable.getInterface(Example.class);
                
                Object value1 = invocable.invokeFunction("test1", map);
                Object value2 = example.test1(map);
                Object value3 = invocable.invokeFunction("test2", value2);
                Object value4 = example.test2(value2);

                System.out.println(value1.getClass());
                System.out.println(value2.getClass());
                System.out.println(value3.getClass());
                System.out.println(value4.getClass());
            }
        }


        Output:

        class java.util.HashMap
        class java.util.HashMap
        undefined
        undefined
        class jdk.nashorn.api.scripting.ScriptObjectMirror
        class jdk.nashorn.internal.scripts.JO4
        class jdk.nashorn.api.scripting.ScriptObjectMirror
        class jdk.nashorn.internal.scripts.JO4

          Attachments

            Issue Links

              Activity

                People

                Assignee:
                sundar Sundararajan Athijegannathan
                Reporter:
                jlaskey Jim Laskey
                Votes:
                0 Vote for this issue
                Watchers:
                3 Start watching this issue

                  Dates

                  Created:
                  Updated:
                  Resolved: