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

arguments are handled differently in apply for JS functions and AbstractJSObjects

    Details

    • Type: Bug
    • Status: Resolved
    • Priority: P4
    • Resolution: Fixed
    • Affects Version/s: 9
    • Fix Version/s: 9
    • Component/s: core-libs
    • Labels:
      None

      Backports

        Description

        Functions defined at JS level and functions defined as an AbstractJSObject are passed arguments differently when invoked through Function.prototype.apply.call(): the AbstractJSObject implementation will be passed an Object[] containing an Object[] holding all the arguments, whereas the JS function will be passed an array containing the arguments (not nested in an extra array).

        The attached test case produces the following output:
        args = [1, 2, 3]
        args = [[1, 2, 3]] // note this line
        1
        2
        3
        1
        2
        3

        Expected:
        args = [1, 2, 3]
        args = [1, 2, 3] // this differs from above
        1
        2
        3
        1
        2
        3
        1. Main.java
          0.9 kB
          Michael Haupt

          Issue Links

            Activity

            Hide
            mhaupt Michael Haupt added a comment -
            JSObjectLinker always creates an arguments-collecting method handle, which leads to the arguments passed to apply in an array (as apply's protocol demands) being wrapped in an extra array.
            Show
            mhaupt Michael Haupt added a comment - JSObjectLinker always creates an arguments-collecting method handle, which leads to the arguments passed to apply in an array (as apply's protocol demands) being wrapped in an extra array.
            Hide
            hgupdate HG Updates added a comment -
            URL: http://hg.openjdk.java.net/jdk9/dev/nashorn/rev/221378857767
            User: mhaupt
            Date: 2016-02-16 16:26:17 +0000
            Show
            hgupdate HG Updates added a comment - URL: http://hg.openjdk.java.net/jdk9/dev/nashorn/rev/221378857767 User: mhaupt Date: 2016-02-16 16:26:17 +0000
            Hide
            hgupdate HG Updates added a comment -
            URL: http://hg.openjdk.java.net/jdk9/jdk9/nashorn/rev/221378857767
            User: lana
            Date: 2016-02-24 20:06:18 +0000
            Show
            hgupdate HG Updates added a comment - URL: http://hg.openjdk.java.net/jdk9/jdk9/nashorn/rev/221378857767 User: lana Date: 2016-02-24 20:06:18 +0000

              People

              • Assignee:
                mhaupt Michael Haupt
                Reporter:
                mhaupt Michael Haupt
              • Votes:
                0 Vote for this issue
                Watchers:
                2 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved: