author | mikael |
Thu, 19 Apr 2018 17:13:19 -0700 | |
changeset 49838 | b37e0785ce0b |
parent 47216 | 71c04702a3d5 |
permissions | -rw-r--r-- |
38595
6eceed1919cf
8157680: Callback parameter of any JS builtin implementation should accept any Callable
sundar
parents:
diff
changeset
|
1 |
/* |
6eceed1919cf
8157680: Callback parameter of any JS builtin implementation should accept any Callable
sundar
parents:
diff
changeset
|
2 |
* Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved. |
6eceed1919cf
8157680: Callback parameter of any JS builtin implementation should accept any Callable
sundar
parents:
diff
changeset
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
6eceed1919cf
8157680: Callback parameter of any JS builtin implementation should accept any Callable
sundar
parents:
diff
changeset
|
4 |
* |
6eceed1919cf
8157680: Callback parameter of any JS builtin implementation should accept any Callable
sundar
parents:
diff
changeset
|
5 |
* This code is free software; you can redistribute it and/or modify it |
6eceed1919cf
8157680: Callback parameter of any JS builtin implementation should accept any Callable
sundar
parents:
diff
changeset
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
6eceed1919cf
8157680: Callback parameter of any JS builtin implementation should accept any Callable
sundar
parents:
diff
changeset
|
7 |
* published by the Free Software Foundation. |
6eceed1919cf
8157680: Callback parameter of any JS builtin implementation should accept any Callable
sundar
parents:
diff
changeset
|
8 |
* |
6eceed1919cf
8157680: Callback parameter of any JS builtin implementation should accept any Callable
sundar
parents:
diff
changeset
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
6eceed1919cf
8157680: Callback parameter of any JS builtin implementation should accept any Callable
sundar
parents:
diff
changeset
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
6eceed1919cf
8157680: Callback parameter of any JS builtin implementation should accept any Callable
sundar
parents:
diff
changeset
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
6eceed1919cf
8157680: Callback parameter of any JS builtin implementation should accept any Callable
sundar
parents:
diff
changeset
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
6eceed1919cf
8157680: Callback parameter of any JS builtin implementation should accept any Callable
sundar
parents:
diff
changeset
|
13 |
* accompanied this code). |
6eceed1919cf
8157680: Callback parameter of any JS builtin implementation should accept any Callable
sundar
parents:
diff
changeset
|
14 |
* |
6eceed1919cf
8157680: Callback parameter of any JS builtin implementation should accept any Callable
sundar
parents:
diff
changeset
|
15 |
* You should have received a copy of the GNU General Public License version |
6eceed1919cf
8157680: Callback parameter of any JS builtin implementation should accept any Callable
sundar
parents:
diff
changeset
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
6eceed1919cf
8157680: Callback parameter of any JS builtin implementation should accept any Callable
sundar
parents:
diff
changeset
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
6eceed1919cf
8157680: Callback parameter of any JS builtin implementation should accept any Callable
sundar
parents:
diff
changeset
|
18 |
* |
6eceed1919cf
8157680: Callback parameter of any JS builtin implementation should accept any Callable
sundar
parents:
diff
changeset
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
6eceed1919cf
8157680: Callback parameter of any JS builtin implementation should accept any Callable
sundar
parents:
diff
changeset
|
20 |
* or visit www.oracle.com if you need additional information or have any |
6eceed1919cf
8157680: Callback parameter of any JS builtin implementation should accept any Callable
sundar
parents:
diff
changeset
|
21 |
* questions. |
6eceed1919cf
8157680: Callback parameter of any JS builtin implementation should accept any Callable
sundar
parents:
diff
changeset
|
22 |
*/ |
6eceed1919cf
8157680: Callback parameter of any JS builtin implementation should accept any Callable
sundar
parents:
diff
changeset
|
23 |
|
6eceed1919cf
8157680: Callback parameter of any JS builtin implementation should accept any Callable
sundar
parents:
diff
changeset
|
24 |
/** |
6eceed1919cf
8157680: Callback parameter of any JS builtin implementation should accept any Callable
sundar
parents:
diff
changeset
|
25 |
* JDK-8157680: Callback parameter of any JS builtin implementation should accept any Callable |
6eceed1919cf
8157680: Callback parameter of any JS builtin implementation should accept any Callable
sundar
parents:
diff
changeset
|
26 |
* |
6eceed1919cf
8157680: Callback parameter of any JS builtin implementation should accept any Callable
sundar
parents:
diff
changeset
|
27 |
* @option -scripting |
6eceed1919cf
8157680: Callback parameter of any JS builtin implementation should accept any Callable
sundar
parents:
diff
changeset
|
28 |
* @test |
6eceed1919cf
8157680: Callback parameter of any JS builtin implementation should accept any Callable
sundar
parents:
diff
changeset
|
29 |
* @run |
6eceed1919cf
8157680: Callback parameter of any JS builtin implementation should accept any Callable
sundar
parents:
diff
changeset
|
30 |
*/ |
6eceed1919cf
8157680: Callback parameter of any JS builtin implementation should accept any Callable
sundar
parents:
diff
changeset
|
31 |
|
6eceed1919cf
8157680: Callback parameter of any JS builtin implementation should accept any Callable
sundar
parents:
diff
changeset
|
32 |
var SM = Java.type("javax.script.ScriptEngineManager") |
6eceed1919cf
8157680: Callback parameter of any JS builtin implementation should accept any Callable
sundar
parents:
diff
changeset
|
33 |
var engine = new SM().getEngineByName("nashorn") |
6eceed1919cf
8157680: Callback parameter of any JS builtin implementation should accept any Callable
sundar
parents:
diff
changeset
|
34 |
|
6eceed1919cf
8157680: Callback parameter of any JS builtin implementation should accept any Callable
sundar
parents:
diff
changeset
|
35 |
engine.put("output", print); |
6eceed1919cf
8157680: Callback parameter of any JS builtin implementation should accept any Callable
sundar
parents:
diff
changeset
|
36 |
var reviver = engine.eval(<<EOF |
6eceed1919cf
8157680: Callback parameter of any JS builtin implementation should accept any Callable
sundar
parents:
diff
changeset
|
37 |
function(name, value) { |
6eceed1919cf
8157680: Callback parameter of any JS builtin implementation should accept any Callable
sundar
parents:
diff
changeset
|
38 |
if (name == "") return value |
6eceed1919cf
8157680: Callback parameter of any JS builtin implementation should accept any Callable
sundar
parents:
diff
changeset
|
39 |
output(name + " = " + value) |
6eceed1919cf
8157680: Callback parameter of any JS builtin implementation should accept any Callable
sundar
parents:
diff
changeset
|
40 |
return value |
6eceed1919cf
8157680: Callback parameter of any JS builtin implementation should accept any Callable
sundar
parents:
diff
changeset
|
41 |
} |
6eceed1919cf
8157680: Callback parameter of any JS builtin implementation should accept any Callable
sundar
parents:
diff
changeset
|
42 |
EOF) |
6eceed1919cf
8157680: Callback parameter of any JS builtin implementation should accept any Callable
sundar
parents:
diff
changeset
|
43 |
|
6eceed1919cf
8157680: Callback parameter of any JS builtin implementation should accept any Callable
sundar
parents:
diff
changeset
|
44 |
// reviver function from mirror world! |
6eceed1919cf
8157680: Callback parameter of any JS builtin implementation should accept any Callable
sundar
parents:
diff
changeset
|
45 |
JSON.parse('{ "foo" : 44, "bar" : "hello" }', reviver) |
6eceed1919cf
8157680: Callback parameter of any JS builtin implementation should accept any Callable
sundar
parents:
diff
changeset
|
46 |
|
6eceed1919cf
8157680: Callback parameter of any JS builtin implementation should accept any Callable
sundar
parents:
diff
changeset
|
47 |
var AJO = Java.type("jdk.nashorn.api.scripting.AbstractJSObject") |
6eceed1919cf
8157680: Callback parameter of any JS builtin implementation should accept any Callable
sundar
parents:
diff
changeset
|
48 |
// reviver function as a JSObject function |
6eceed1919cf
8157680: Callback parameter of any JS builtin implementation should accept any Callable
sundar
parents:
diff
changeset
|
49 |
JSON.parse('{ "nashorn" : "hello" }', new AJO() { |
6eceed1919cf
8157680: Callback parameter of any JS builtin implementation should accept any Callable
sundar
parents:
diff
changeset
|
50 |
isFunction: function() true, |
6eceed1919cf
8157680: Callback parameter of any JS builtin implementation should accept any Callable
sundar
parents:
diff
changeset
|
51 |
call: function(thiz, args) { |
6eceed1919cf
8157680: Callback parameter of any JS builtin implementation should accept any Callable
sundar
parents:
diff
changeset
|
52 |
var name = args[0], value = args[1] |
6eceed1919cf
8157680: Callback parameter of any JS builtin implementation should accept any Callable
sundar
parents:
diff
changeset
|
53 |
if (name == "") return value |
6eceed1919cf
8157680: Callback parameter of any JS builtin implementation should accept any Callable
sundar
parents:
diff
changeset
|
54 |
print(name + " -> " + value) |
6eceed1919cf
8157680: Callback parameter of any JS builtin implementation should accept any Callable
sundar
parents:
diff
changeset
|
55 |
return value |
6eceed1919cf
8157680: Callback parameter of any JS builtin implementation should accept any Callable
sundar
parents:
diff
changeset
|
56 |
} |
6eceed1919cf
8157680: Callback parameter of any JS builtin implementation should accept any Callable
sundar
parents:
diff
changeset
|
57 |
}) |
6eceed1919cf
8157680: Callback parameter of any JS builtin implementation should accept any Callable
sundar
parents:
diff
changeset
|
58 |
|
6eceed1919cf
8157680: Callback parameter of any JS builtin implementation should accept any Callable
sundar
parents:
diff
changeset
|
59 |
// compare function from the mirror world |
6eceed1919cf
8157680: Callback parameter of any JS builtin implementation should accept any Callable
sundar
parents:
diff
changeset
|
60 |
var arr = [34,567,-3, 53].sort(engine.eval(<<EOF |
6eceed1919cf
8157680: Callback parameter of any JS builtin implementation should accept any Callable
sundar
parents:
diff
changeset
|
61 |
function(x, y) x < y? -1 : ((x > y)? 1 : 0) |
6eceed1919cf
8157680: Callback parameter of any JS builtin implementation should accept any Callable
sundar
parents:
diff
changeset
|
62 |
EOF)) |
6eceed1919cf
8157680: Callback parameter of any JS builtin implementation should accept any Callable
sundar
parents:
diff
changeset
|
63 |
print(arr) |
6eceed1919cf
8157680: Callback parameter of any JS builtin implementation should accept any Callable
sundar
parents:
diff
changeset
|
64 |
|
6eceed1919cf
8157680: Callback parameter of any JS builtin implementation should accept any Callable
sundar
parents:
diff
changeset
|
65 |
// compare function as a JSObject function |
6eceed1919cf
8157680: Callback parameter of any JS builtin implementation should accept any Callable
sundar
parents:
diff
changeset
|
66 |
arr = [34,57,-3, 53, 670, 33].sort(new AJO() { |
6eceed1919cf
8157680: Callback parameter of any JS builtin implementation should accept any Callable
sundar
parents:
diff
changeset
|
67 |
isFunction: function() true, |
6eceed1919cf
8157680: Callback parameter of any JS builtin implementation should accept any Callable
sundar
parents:
diff
changeset
|
68 |
call: function(thiz, args) { |
6eceed1919cf
8157680: Callback parameter of any JS builtin implementation should accept any Callable
sundar
parents:
diff
changeset
|
69 |
var x = args[0], y = args[1] |
6eceed1919cf
8157680: Callback parameter of any JS builtin implementation should accept any Callable
sundar
parents:
diff
changeset
|
70 |
return x < y? -1 : ((x > y)? 1 : 0) |
6eceed1919cf
8157680: Callback parameter of any JS builtin implementation should accept any Callable
sundar
parents:
diff
changeset
|
71 |
} |
6eceed1919cf
8157680: Callback parameter of any JS builtin implementation should accept any Callable
sundar
parents:
diff
changeset
|
72 |
}) |
6eceed1919cf
8157680: Callback parameter of any JS builtin implementation should accept any Callable
sundar
parents:
diff
changeset
|
73 |
print(arr) |
6eceed1919cf
8157680: Callback parameter of any JS builtin implementation should accept any Callable
sundar
parents:
diff
changeset
|
74 |
|
6eceed1919cf
8157680: Callback parameter of any JS builtin implementation should accept any Callable
sundar
parents:
diff
changeset
|
75 |
// replacer function from mirror world |
6eceed1919cf
8157680: Callback parameter of any JS builtin implementation should accept any Callable
sundar
parents:
diff
changeset
|
76 |
var str = "hello".replace(/l/g, engine.eval(<<EOF |
6eceed1919cf
8157680: Callback parameter of any JS builtin implementation should accept any Callable
sundar
parents:
diff
changeset
|
77 |
function() "_" |
6eceed1919cf
8157680: Callback parameter of any JS builtin implementation should accept any Callable
sundar
parents:
diff
changeset
|
78 |
EOF)) |
6eceed1919cf
8157680: Callback parameter of any JS builtin implementation should accept any Callable
sundar
parents:
diff
changeset
|
79 |
print(str) |
6eceed1919cf
8157680: Callback parameter of any JS builtin implementation should accept any Callable
sundar
parents:
diff
changeset
|
80 |
|
6eceed1919cf
8157680: Callback parameter of any JS builtin implementation should accept any Callable
sundar
parents:
diff
changeset
|
81 |
// replacer function as a JSObject function |
6eceed1919cf
8157680: Callback parameter of any JS builtin implementation should accept any Callable
sundar
parents:
diff
changeset
|
82 |
str = "hello".replace(/[el]/g, new AJO() { |
6eceed1919cf
8157680: Callback parameter of any JS builtin implementation should accept any Callable
sundar
parents:
diff
changeset
|
83 |
isFunction: function() true, |
6eceed1919cf
8157680: Callback parameter of any JS builtin implementation should accept any Callable
sundar
parents:
diff
changeset
|
84 |
call: function(thiz, args) { |
6eceed1919cf
8157680: Callback parameter of any JS builtin implementation should accept any Callable
sundar
parents:
diff
changeset
|
85 |
var match = args[0] |
6eceed1919cf
8157680: Callback parameter of any JS builtin implementation should accept any Callable
sundar
parents:
diff
changeset
|
86 |
return match.toUpperCase() |
6eceed1919cf
8157680: Callback parameter of any JS builtin implementation should accept any Callable
sundar
parents:
diff
changeset
|
87 |
} |
6eceed1919cf
8157680: Callback parameter of any JS builtin implementation should accept any Callable
sundar
parents:
diff
changeset
|
88 |
}) |
6eceed1919cf
8157680: Callback parameter of any JS builtin implementation should accept any Callable
sundar
parents:
diff
changeset
|
89 |
print(str) |