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

Javascript mapping of ScriptEngine bindings does not expose keys.

    XMLWordPrintable

Details

    • Bug
    • Resolution: Fixed
    • P4
    • 8
    • 8
    • core-libs
    • None
    • b94
    • Verified

    Description

      The pasted example shows it all.
      In java the Map contains the declaration, in JS it doesn't. Retrieving the property using the property name
      gets you the property.

      // Works in Java.
      //final ScriptEngineManager m = new ScriptEngineManager();
      //final ScriptEngine e = m.getEngineByName("nashorn");
      //e.eval("function doIt(){}");
      //System.out.println(" Contains obj ? " + e.getBindings(ScriptContext.ENGINE_SCOPE).containsKey("doIt"));

      // Doesn't work in JS
      var se = new javax.script.ScriptEngineManager();
      var e = se.getEngineByName("nashorn");
      e.eval("function doIt(){}");
      // The returned bindings is not iterable...
      var b = e.getBindings(javax.script.ScriptContext.ENGINE_SCOPE);
      // Returns nothing
      for( k in b){
          print("K " + b[k]);
      }
      // returns the function
      print(b["doIt"]);

      Attachments

        Activity

          People

            sundar Sundararajan Athijegannathan
            jfdenise Jean-Francois Denise (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: