sundar@1833: /* sundar@1833: * Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved. sundar@1833: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. sundar@1833: * sundar@1833: * This code is free software; you can redistribute it and/or modify it sundar@1833: * under the terms of the GNU General Public License version 2 only, as sundar@1833: * published by the Free Software Foundation. sundar@1833: * sundar@1833: * This code is distributed in the hope that it will be useful, but WITHOUT sundar@1833: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or sundar@1833: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License sundar@1833: * version 2 for more details (a copy is included in the LICENSE file that sundar@1833: * accompanied this code). sundar@1833: * sundar@1833: * You should have received a copy of the GNU General Public License version sundar@1833: * 2 along with this work; if not, write to the Free Software Foundation, sundar@1833: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. sundar@1833: * sundar@1833: * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA sundar@1833: * or visit www.oracle.com if you need additional information or have any sundar@1833: * questions. sundar@1833: */ sundar@1833: sundar@1833: /** sundar@1833: * JDK-8157819: TypeError when a java.util.Comparator object is invoked as a function sundar@1833: * sundar@1833: * @test sundar@1833: * @run sundar@1833: */ sundar@1833: sundar@1833: var compare = java.util.Comparator.naturalOrder() sundar@1833: Assert.assertTrue(compare("nashorn", "ecmascript") > 0) sundar@1833: Assert.assertTrue(compare("abc", "xyz") < 0) sundar@1833: Assert.assertTrue(compare("hello", "hello") == 0) sundar@1833: sundar@1833: var rcompare = java.util.Comparator.reverseOrder() sundar@1833: Assert.assertTrue(rcompare("nashorn", "ecmascript") < 0) sundar@1833: Assert.assertTrue(rcompare("abc", "xyz") > 0) sundar@1833: Assert.assertTrue(rcompare("hello", "hello") == 0) sundar@1833: sundar@1833: var arr = [ "nashorn", "JavaScript", "ECMAScript", "ecmascript", "js" ] sundar@1833: Assert.assertEquals(arr.sort(compare).join(), sundar@1833: "ECMAScript,JavaScript,ecmascript,js,nashorn") sundar@1833: Assert.assertEquals(arr.sort(rcompare).join(), sundar@1833: "nashorn,js,ecmascript,JavaScript,ECMAScript") sundar@1833: