Path: blob/aarch64-shenandoah-jdk8u272-b10/nashorn/test/script/basic/JDK-8008197.js
32281 views
/*1* Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/2223/**24* JDK-8008197: Cross script engine function calls do not work as expected25*26* @test27* @run28*/293031var m = new javax.script.ScriptEngineManager();32var e = m.getEngineByName("nashorn");3334var obj = {35func: function(str) {36return /hello/.exec(str);37}38};3940// set our object as object to the engine created41e.put("obj", obj);4243// try to invoke method from the other engine44if (e.eval("obj.func('hello')") == null) {45fail("FAILED: #1 obj.func('hello') returns null");46}4748// define an object in the engine49e.eval("var foo = { callMe: function(callback) { return callback() } }");5051// try to invoke a script method from here but callback is from this engine52var res = e.invokeMethod(e.get("foo"), "callMe", function() {53return /nashorn/;54});5556if (! res.exec("nashorn")) {57fail("FAILED: #2 /nashorn/ does not match 'nashorn'");58}5960// invoke a script method from here with callback from this engine.61// This uses JSObject.call interface62res = e.get("foo").callMe(function() {63return /ecmascript/;64});6566if (! res.exec("ecmascript")) {67fail("FAILED: #3 /ecmascript/ does not match 'ecmascript'");68}697071