changeset 47232:205e4c0dc8a3

8186646: Nashorn: "duplicate code" assertion when binding a vararg function that just passes arguments along Reviewed-by: sundar, jlaskey
author hannesw
date Thu, 21 Sep 2017 14:40:50 +0200
parents 8fb3178bef87
children 5ee94c2e087e
files src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/runtime/CompiledFunction.java test/nashorn/script/basic/JDK-8186646.js
diffstat 2 files changed, 42 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/runtime/CompiledFunction.java	Thu Sep 21 18:00:44 2017 +0530
+++ b/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/runtime/CompiledFunction.java	Thu Sep 21 14:40:50 2017 +0200
@@ -537,6 +537,9 @@
 
         final int csParamCount = getParamCount(other);
         final boolean csIsVarArg = csParamCount == Integer.MAX_VALUE;
+        if (csIsVarArg && isApplyToCall()) {
+            return false; // apply2call function must be called with exact number of parameters
+        }
         final int thisThisIndex = needsCallee() ? 1 : 0; // Index of "this" parameter in this function's type
 
         final int fnParamCountNoCallee = fnParamCount - thisThisIndex;
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/nashorn/script/basic/JDK-8186646.js	Thu Sep 21 14:40:50 2017 +0200
@@ -0,0 +1,39 @@
+/*
+ * Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ * 
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ * 
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ * 
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ * 
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+/**
+ * JDK-8186646: Nashorn: "duplicate code" assertion when binding a vararg function that just passes arguments along
+ *
+ * @test
+ * @run
+ */
+
+var fn2 = function () {};
+
+var fn = function () {
+    fn2.apply(null, arguments);
+};
+
+fn();
+fn.bind();
+