Mon, 31 Aug 2015 17:51:02 +0530
8134731: Function.prototype.apply interacts incorrectly with arguments
Reviewed-by: attila, hannesw
sundar@1520 | 1 | /* |
sundar@1520 | 2 | * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved. |
sundar@1520 | 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
sundar@1520 | 4 | * |
sundar@1520 | 5 | * This code is free software; you can redistribute it and/or modify it |
sundar@1520 | 6 | * under the terms of the GNU General Public License version 2 only, as |
sundar@1520 | 7 | * published by the Free Software Foundation. |
sundar@1520 | 8 | * |
sundar@1520 | 9 | * This code is distributed in the hope that it will be useful, but WITHOUT |
sundar@1520 | 10 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
sundar@1520 | 11 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
sundar@1520 | 12 | * version 2 for more details (a copy is included in the LICENSE file that |
sundar@1520 | 13 | * accompanied this code). |
sundar@1520 | 14 | * |
sundar@1520 | 15 | * You should have received a copy of the GNU General Public License version |
sundar@1520 | 16 | * 2 along with this work; if not, write to the Free Software Foundation, |
sundar@1520 | 17 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
sundar@1520 | 18 | * |
sundar@1520 | 19 | * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
sundar@1520 | 20 | * or visit www.oracle.com if you need additional information or have any |
sundar@1520 | 21 | * questions. |
sundar@1520 | 22 | */ |
sundar@1520 | 23 | |
sundar@1520 | 24 | /** |
sundar@1520 | 25 | * JDK-8134731: `Function.prototype.apply` interacts incorrectly with `arguments` |
sundar@1520 | 26 | * |
sundar@1520 | 27 | * @test |
sundar@1520 | 28 | * @run |
sundar@1520 | 29 | */ |
sundar@1520 | 30 | |
sundar@1520 | 31 | function func() { |
sundar@1520 | 32 | return (function(f){ |
sundar@1520 | 33 | return function(a1, a2, a3, a4){ |
sundar@1520 | 34 | return (f.apply(this, arguments)); |
sundar@1520 | 35 | } |
sundar@1520 | 36 | })(function(){ |
sundar@1520 | 37 | return arguments.length; |
sundar@1520 | 38 | }) |
sundar@1520 | 39 | } |
sundar@1520 | 40 | |
sundar@1520 | 41 | Assert.assertTrue(func()() == 0); |
sundar@1520 | 42 | Assert.assertTrue(func()(33) == 1); |
sundar@1520 | 43 | Assert.assertTrue(func()(33, true) == 2); |
sundar@1520 | 44 | Assert.assertTrue(func()(33, true, "hello") == 3); |
sundar@1520 | 45 | Assert.assertTrue(func()(33, true, "hello", "world") == 4); |
sundar@1520 | 46 | Assert.assertTrue(func()(33, true, "hello", "world", 42) == 5); |