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

Global scope passed as "thiz" arg in JSObject.call(Object,Object[])

    Details

    • Subcomponent:
    • Introduced In Build:
      b148
    • Introduced In Version:
      9
    • CPU:
      x86_64
    • OS:
      windows_8

      Description

      ADDITIONAL SYSTEM INFORMATION :
      Microsoft Windows [Version 6.3.9600]

      java version "1.8.0_172"
      Java(TM) SE Runtime Environment (build 1.8.0_172-b11)
      Java HotSpot(TM) 64-Bit Server VM (build 25.172-b11, mixed mode)

      A DESCRIPTION OF THE PROBLEM :
      When having a host object (JSObject implementation) in the global scope, and calling it like a function (without an owner), the global scope object is erroneously passed as an argument to the JSObject's call(Object,Object[]) method as the first argument.

      This is regardless of strict mode: it happens either way.

      Extra information: my guess would be that this is a result of changes made for JDK-8170565

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      Run the supplied code.

      Uncomment the "use strict" line to see that this happens regardless of strict mode.

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      The following output:
      undefined
      ACTUAL -
      The following output:
      [object global]

      ---------- BEGIN SOURCE ----------
      import javax.script.ScriptEngine;
      import javax.script.ScriptEngineManager;
      import jdk.nashorn.api.scripting.AbstractJSObject;
      import jdk.nashorn.api.scripting.JSObject;
      import jdk.nashorn.api.scripting.NashornScriptEngineFactory;

      public class A {

          public static void main(String[] args) throws Exception {
              ScriptEngine se = ((NashornScriptEngineFactory) new ScriptEngineManager()
                      .getEngineFactories()
                      .get(0))
                      .getScriptEngine( //
                      // "-strict"
                      );

              JSObject o = (JSObject) se.eval("var a = ({}); a;");
              o.setMember("something", new AbstractJSObject() {
                  @Override
                  public Object call(Object thiz, Object... args) {
                      System.out.println(thiz);
                      return null;
                  }

              });
              se.eval("var b = a.something; b();");
          }

      }
      ---------- END SOURCE ----------

      CUSTOMER SUBMITTED WORKAROUND :
      There is no workaround.

      FREQUENCY : always


        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                hannesw Hannes Wallnoefer
                Reporter:
                webbuggrp Webbug Group
              • Votes:
                0 Vote for this issue
                Watchers:
                3 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved: