sundar@1828: /* sundar@1828: * Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved. sundar@1828: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. sundar@1828: * sundar@1828: * This code is free software; you can redistribute it and/or modify it sundar@1828: * under the terms of the GNU General Public License version 2 only, as sundar@1828: * published by the Free Software Foundation. sundar@1828: * sundar@1828: * This code is distributed in the hope that it will be useful, but WITHOUT sundar@1828: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or sundar@1828: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License sundar@1828: * version 2 for more details (a copy is included in the LICENSE file that sundar@1828: * accompanied this code). sundar@1828: * sundar@1828: * You should have received a copy of the GNU General Public License version sundar@1828: * 2 along with this work; if not, write to the Free Software Foundation, sundar@1828: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. sundar@1828: * sundar@1828: * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA sundar@1828: * or visit www.oracle.com if you need additional information or have any sundar@1828: * questions. sundar@1828: */ sundar@1828: sundar@1828: /** sundar@1828: * JDK-8157680: Callback parameter of any JS builtin implementation should accept any Callable sundar@1828: * sundar@1828: * @option -scripting sundar@1828: * @test sundar@1828: * @run sundar@1828: */ sundar@1828: sundar@1828: var SM = Java.type("javax.script.ScriptEngineManager") sundar@1828: var engine = new SM().getEngineByName("nashorn") sundar@1828: sundar@1828: engine.put("output", print); sundar@1828: var reviver = engine.eval(< " + value) sundar@1828: return value sundar@1828: } sundar@1828: }) sundar@1828: sundar@1828: // compare function from the mirror world sundar@1828: var arr = [34,567,-3, 53].sort(engine.eval(< y)? 1 : 0) sundar@1828: EOF)) sundar@1828: print(arr) sundar@1828: sundar@1828: // compare function as a JSObject function sundar@1828: arr = [34,57,-3, 53, 670, 33].sort(new AJO() { sundar@1828: isFunction: function() true, sundar@1828: call: function(thiz, args) { sundar@1828: var x = args[0], y = args[1] sundar@1828: return x < y? -1 : ((x > y)? 1 : 0) sundar@1828: } sundar@1828: }) sundar@1828: print(arr) sundar@1828: sundar@1828: // replacer function from mirror world sundar@1828: var str = "hello".replace(/l/g, engine.eval(<