JDK-8148140 : arguments are handled differently in apply for JS functions and AbstractJSObjects
  • Type: Bug
  • Component: core-libs
  • Sub-Component: jdk.nashorn
  • Affected Version: 9
  • Priority: P4
  • Status: Resolved
  • Resolution: Fixed
  • Submitted: 2016-01-25
  • Updated: 2016-10-13
  • Resolved: 2016-02-16
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
JDK 8 JDK 9
8u112Fixed 9 b107Fixed
Related Reports
Relates :  
Relates :  
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
Comments
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.
16-02-2016