author | hannesw |
Wed, 25 Jun 2014 14:36:24 +0200 | |
changeset 25243 | 7a1edca6ce94 |
parent 24778 | 2ff5d7041566 |
permissions | -rw-r--r-- |
16232
efd57dd90de6
8008197: Cross script engine function calls do not work as expected
sundar
parents:
diff
changeset
|
1 |
/* |
efd57dd90de6
8008197: Cross script engine function calls do not work as expected
sundar
parents:
diff
changeset
|
2 |
* Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved. |
efd57dd90de6
8008197: Cross script engine function calls do not work as expected
sundar
parents:
diff
changeset
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
24778
2ff5d7041566
8044638: Tidy up Nashorn codebase for code standards
attila
parents:
16232
diff
changeset
|
4 |
* |
16232
efd57dd90de6
8008197: Cross script engine function calls do not work as expected
sundar
parents:
diff
changeset
|
5 |
* This code is free software; you can redistribute it and/or modify it |
efd57dd90de6
8008197: Cross script engine function calls do not work as expected
sundar
parents:
diff
changeset
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
efd57dd90de6
8008197: Cross script engine function calls do not work as expected
sundar
parents:
diff
changeset
|
7 |
* published by the Free Software Foundation. |
24778
2ff5d7041566
8044638: Tidy up Nashorn codebase for code standards
attila
parents:
16232
diff
changeset
|
8 |
* |
16232
efd57dd90de6
8008197: Cross script engine function calls do not work as expected
sundar
parents:
diff
changeset
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
efd57dd90de6
8008197: Cross script engine function calls do not work as expected
sundar
parents:
diff
changeset
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
efd57dd90de6
8008197: Cross script engine function calls do not work as expected
sundar
parents:
diff
changeset
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
efd57dd90de6
8008197: Cross script engine function calls do not work as expected
sundar
parents:
diff
changeset
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
efd57dd90de6
8008197: Cross script engine function calls do not work as expected
sundar
parents:
diff
changeset
|
13 |
* accompanied this code). |
24778
2ff5d7041566
8044638: Tidy up Nashorn codebase for code standards
attila
parents:
16232
diff
changeset
|
14 |
* |
16232
efd57dd90de6
8008197: Cross script engine function calls do not work as expected
sundar
parents:
diff
changeset
|
15 |
* You should have received a copy of the GNU General Public License version |
efd57dd90de6
8008197: Cross script engine function calls do not work as expected
sundar
parents:
diff
changeset
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
efd57dd90de6
8008197: Cross script engine function calls do not work as expected
sundar
parents:
diff
changeset
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
24778
2ff5d7041566
8044638: Tidy up Nashorn codebase for code standards
attila
parents:
16232
diff
changeset
|
18 |
* |
16232
efd57dd90de6
8008197: Cross script engine function calls do not work as expected
sundar
parents:
diff
changeset
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
efd57dd90de6
8008197: Cross script engine function calls do not work as expected
sundar
parents:
diff
changeset
|
20 |
* or visit www.oracle.com if you need additional information or have any |
efd57dd90de6
8008197: Cross script engine function calls do not work as expected
sundar
parents:
diff
changeset
|
21 |
* questions. |
efd57dd90de6
8008197: Cross script engine function calls do not work as expected
sundar
parents:
diff
changeset
|
22 |
*/ |
efd57dd90de6
8008197: Cross script engine function calls do not work as expected
sundar
parents:
diff
changeset
|
23 |
|
efd57dd90de6
8008197: Cross script engine function calls do not work as expected
sundar
parents:
diff
changeset
|
24 |
/** |
efd57dd90de6
8008197: Cross script engine function calls do not work as expected
sundar
parents:
diff
changeset
|
25 |
* JDK-8008197: Cross script engine function calls do not work as expected |
efd57dd90de6
8008197: Cross script engine function calls do not work as expected
sundar
parents:
diff
changeset
|
26 |
* |
efd57dd90de6
8008197: Cross script engine function calls do not work as expected
sundar
parents:
diff
changeset
|
27 |
* @test |
efd57dd90de6
8008197: Cross script engine function calls do not work as expected
sundar
parents:
diff
changeset
|
28 |
* @run |
efd57dd90de6
8008197: Cross script engine function calls do not work as expected
sundar
parents:
diff
changeset
|
29 |
*/ |
efd57dd90de6
8008197: Cross script engine function calls do not work as expected
sundar
parents:
diff
changeset
|
30 |
|
efd57dd90de6
8008197: Cross script engine function calls do not work as expected
sundar
parents:
diff
changeset
|
31 |
|
efd57dd90de6
8008197: Cross script engine function calls do not work as expected
sundar
parents:
diff
changeset
|
32 |
var m = new javax.script.ScriptEngineManager(); |
efd57dd90de6
8008197: Cross script engine function calls do not work as expected
sundar
parents:
diff
changeset
|
33 |
var e = m.getEngineByName("nashorn"); |
efd57dd90de6
8008197: Cross script engine function calls do not work as expected
sundar
parents:
diff
changeset
|
34 |
|
efd57dd90de6
8008197: Cross script engine function calls do not work as expected
sundar
parents:
diff
changeset
|
35 |
var obj = { |
24778
2ff5d7041566
8044638: Tidy up Nashorn codebase for code standards
attila
parents:
16232
diff
changeset
|
36 |
func: function(str) { |
16232
efd57dd90de6
8008197: Cross script engine function calls do not work as expected
sundar
parents:
diff
changeset
|
37 |
return /hello/.exec(str); |
efd57dd90de6
8008197: Cross script engine function calls do not work as expected
sundar
parents:
diff
changeset
|
38 |
} |
efd57dd90de6
8008197: Cross script engine function calls do not work as expected
sundar
parents:
diff
changeset
|
39 |
}; |
efd57dd90de6
8008197: Cross script engine function calls do not work as expected
sundar
parents:
diff
changeset
|
40 |
|
efd57dd90de6
8008197: Cross script engine function calls do not work as expected
sundar
parents:
diff
changeset
|
41 |
// set our object as object to the engine created |
efd57dd90de6
8008197: Cross script engine function calls do not work as expected
sundar
parents:
diff
changeset
|
42 |
e.put("obj", obj); |
efd57dd90de6
8008197: Cross script engine function calls do not work as expected
sundar
parents:
diff
changeset
|
43 |
|
efd57dd90de6
8008197: Cross script engine function calls do not work as expected
sundar
parents:
diff
changeset
|
44 |
// try to invoke method from the other engine |
efd57dd90de6
8008197: Cross script engine function calls do not work as expected
sundar
parents:
diff
changeset
|
45 |
if (e.eval("obj.func('hello')") == null) { |
efd57dd90de6
8008197: Cross script engine function calls do not work as expected
sundar
parents:
diff
changeset
|
46 |
fail("FAILED: #1 obj.func('hello') returns null"); |
efd57dd90de6
8008197: Cross script engine function calls do not work as expected
sundar
parents:
diff
changeset
|
47 |
} |
efd57dd90de6
8008197: Cross script engine function calls do not work as expected
sundar
parents:
diff
changeset
|
48 |
|
efd57dd90de6
8008197: Cross script engine function calls do not work as expected
sundar
parents:
diff
changeset
|
49 |
// define an object in the engine |
efd57dd90de6
8008197: Cross script engine function calls do not work as expected
sundar
parents:
diff
changeset
|
50 |
e.eval("var foo = { callMe: function(callback) { return callback() } }"); |
efd57dd90de6
8008197: Cross script engine function calls do not work as expected
sundar
parents:
diff
changeset
|
51 |
|
efd57dd90de6
8008197: Cross script engine function calls do not work as expected
sundar
parents:
diff
changeset
|
52 |
// try to invoke a script method from here but callback is from this engine |
efd57dd90de6
8008197: Cross script engine function calls do not work as expected
sundar
parents:
diff
changeset
|
53 |
var res = e.invokeMethod(e.get("foo"), "callMe", function() { |
efd57dd90de6
8008197: Cross script engine function calls do not work as expected
sundar
parents:
diff
changeset
|
54 |
return /nashorn/; |
efd57dd90de6
8008197: Cross script engine function calls do not work as expected
sundar
parents:
diff
changeset
|
55 |
}); |
efd57dd90de6
8008197: Cross script engine function calls do not work as expected
sundar
parents:
diff
changeset
|
56 |
|
efd57dd90de6
8008197: Cross script engine function calls do not work as expected
sundar
parents:
diff
changeset
|
57 |
if (! res.exec("nashorn")) { |
efd57dd90de6
8008197: Cross script engine function calls do not work as expected
sundar
parents:
diff
changeset
|
58 |
fail("FAILED: #2 /nashorn/ does not match 'nashorn'"); |
efd57dd90de6
8008197: Cross script engine function calls do not work as expected
sundar
parents:
diff
changeset
|
59 |
} |
efd57dd90de6
8008197: Cross script engine function calls do not work as expected
sundar
parents:
diff
changeset
|
60 |
|
efd57dd90de6
8008197: Cross script engine function calls do not work as expected
sundar
parents:
diff
changeset
|
61 |
// invoke a script method from here with callback from this engine. |
efd57dd90de6
8008197: Cross script engine function calls do not work as expected
sundar
parents:
diff
changeset
|
62 |
// This uses JSObject.call interface |
efd57dd90de6
8008197: Cross script engine function calls do not work as expected
sundar
parents:
diff
changeset
|
63 |
res = e.get("foo").callMe(function() { |
efd57dd90de6
8008197: Cross script engine function calls do not work as expected
sundar
parents:
diff
changeset
|
64 |
return /ecmascript/; |
efd57dd90de6
8008197: Cross script engine function calls do not work as expected
sundar
parents:
diff
changeset
|
65 |
}); |
efd57dd90de6
8008197: Cross script engine function calls do not work as expected
sundar
parents:
diff
changeset
|
66 |
|
efd57dd90de6
8008197: Cross script engine function calls do not work as expected
sundar
parents:
diff
changeset
|
67 |
if (! res.exec("ecmascript")) { |
efd57dd90de6
8008197: Cross script engine function calls do not work as expected
sundar
parents:
diff
changeset
|
68 |
fail("FAILED: #3 /ecmascript/ does not match 'ecmascript'"); |
efd57dd90de6
8008197: Cross script engine function calls do not work as expected
sundar
parents:
diff
changeset
|
69 |
} |