author | hannesw |
Wed, 25 Jun 2014 14:36:24 +0200 | |
changeset 25243 | 7a1edca6ce94 |
parent 24778 | 2ff5d7041566 |
permissions | -rw-r--r-- |
19088
153f268bfa72
8021122: Not all callables are handled for toString and other function valued properties
sundar
parents:
diff
changeset
|
1 |
/* |
153f268bfa72
8021122: Not all callables are handled for toString and other function valued properties
sundar
parents:
diff
changeset
|
2 |
* Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved. |
153f268bfa72
8021122: Not all callables are handled for toString and other function valued properties
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:
19088
diff
changeset
|
4 |
* |
19088
153f268bfa72
8021122: Not all callables are handled for toString and other function valued properties
sundar
parents:
diff
changeset
|
5 |
* This code is free software; you can redistribute it and/or modify it |
153f268bfa72
8021122: Not all callables are handled for toString and other function valued properties
sundar
parents:
diff
changeset
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
153f268bfa72
8021122: Not all callables are handled for toString and other function valued properties
sundar
parents:
diff
changeset
|
7 |
* published by the Free Software Foundation. |
24778
2ff5d7041566
8044638: Tidy up Nashorn codebase for code standards
attila
parents:
19088
diff
changeset
|
8 |
* |
19088
153f268bfa72
8021122: Not all callables are handled for toString and other function valued properties
sundar
parents:
diff
changeset
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
153f268bfa72
8021122: Not all callables are handled for toString and other function valued properties
sundar
parents:
diff
changeset
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
153f268bfa72
8021122: Not all callables are handled for toString and other function valued properties
sundar
parents:
diff
changeset
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
153f268bfa72
8021122: Not all callables are handled for toString and other function valued properties
sundar
parents:
diff
changeset
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
153f268bfa72
8021122: Not all callables are handled for toString and other function valued properties
sundar
parents:
diff
changeset
|
13 |
* accompanied this code). |
24778
2ff5d7041566
8044638: Tidy up Nashorn codebase for code standards
attila
parents:
19088
diff
changeset
|
14 |
* |
19088
153f268bfa72
8021122: Not all callables are handled for toString and other function valued properties
sundar
parents:
diff
changeset
|
15 |
* You should have received a copy of the GNU General Public License version |
153f268bfa72
8021122: Not all callables are handled for toString and other function valued properties
sundar
parents:
diff
changeset
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
153f268bfa72
8021122: Not all callables are handled for toString and other function valued properties
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:
19088
diff
changeset
|
18 |
* |
19088
153f268bfa72
8021122: Not all callables are handled for toString and other function valued properties
sundar
parents:
diff
changeset
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
153f268bfa72
8021122: Not all callables are handled for toString and other function valued properties
sundar
parents:
diff
changeset
|
20 |
* or visit www.oracle.com if you need additional information or have any |
153f268bfa72
8021122: Not all callables are handled for toString and other function valued properties
sundar
parents:
diff
changeset
|
21 |
* questions. |
153f268bfa72
8021122: Not all callables are handled for toString and other function valued properties
sundar
parents:
diff
changeset
|
22 |
*/ |
153f268bfa72
8021122: Not all callables are handled for toString and other function valued properties
sundar
parents:
diff
changeset
|
23 |
|
153f268bfa72
8021122: Not all callables are handled for toString and other function valued properties
sundar
parents:
diff
changeset
|
24 |
/** |
153f268bfa72
8021122: Not all callables are handled for toString and other function valued properties
sundar
parents:
diff
changeset
|
25 |
* JDK-8021122: Not all callables are handled for toString and other function valued properties |
153f268bfa72
8021122: Not all callables are handled for toString and other function valued properties
sundar
parents:
diff
changeset
|
26 |
* |
153f268bfa72
8021122: Not all callables are handled for toString and other function valued properties
sundar
parents:
diff
changeset
|
27 |
* @test |
153f268bfa72
8021122: Not all callables are handled for toString and other function valued properties
sundar
parents:
diff
changeset
|
28 |
* @run |
153f268bfa72
8021122: Not all callables are handled for toString and other function valued properties
sundar
parents:
diff
changeset
|
29 |
*/ |
153f268bfa72
8021122: Not all callables are handled for toString and other function valued properties
sundar
parents:
diff
changeset
|
30 |
|
153f268bfa72
8021122: Not all callables are handled for toString and other function valued properties
sundar
parents:
diff
changeset
|
31 |
var a = {} |
153f268bfa72
8021122: Not all callables are handled for toString and other function valued properties
sundar
parents:
diff
changeset
|
32 |
var obj = new java.util.HashMap(); |
153f268bfa72
8021122: Not all callables are handled for toString and other function valued properties
sundar
parents:
diff
changeset
|
33 |
Object.bindProperties(a, obj); |
153f268bfa72
8021122: Not all callables are handled for toString and other function valued properties
sundar
parents:
diff
changeset
|
34 |
try { |
153f268bfa72
8021122: Not all callables are handled for toString and other function valued properties
sundar
parents:
diff
changeset
|
35 |
print(a); |
153f268bfa72
8021122: Not all callables are handled for toString and other function valued properties
sundar
parents:
diff
changeset
|
36 |
} catch (e) { |
153f268bfa72
8021122: Not all callables are handled for toString and other function valued properties
sundar
parents:
diff
changeset
|
37 |
print(e); |
153f268bfa72
8021122: Not all callables are handled for toString and other function valued properties
sundar
parents:
diff
changeset
|
38 |
} |
153f268bfa72
8021122: Not all callables are handled for toString and other function valued properties
sundar
parents:
diff
changeset
|
39 |
|
153f268bfa72
8021122: Not all callables are handled for toString and other function valued properties
sundar
parents:
diff
changeset
|
40 |
var a = {} |
153f268bfa72
8021122: Not all callables are handled for toString and other function valued properties
sundar
parents:
diff
changeset
|
41 |
var global = loadWithNewGlobal({ name:"xx", script: "this" }); |
153f268bfa72
8021122: Not all callables are handled for toString and other function valued properties
sundar
parents:
diff
changeset
|
42 |
var obj = global.eval("({ toString: function() { return 'hello'; } })"); |
153f268bfa72
8021122: Not all callables are handled for toString and other function valued properties
sundar
parents:
diff
changeset
|
43 |
Object.bindProperties(a, obj); |
153f268bfa72
8021122: Not all callables are handled for toString and other function valued properties
sundar
parents:
diff
changeset
|
44 |
try { |
153f268bfa72
8021122: Not all callables are handled for toString and other function valued properties
sundar
parents:
diff
changeset
|
45 |
print(a); |
153f268bfa72
8021122: Not all callables are handled for toString and other function valued properties
sundar
parents:
diff
changeset
|
46 |
} catch (e) { |
153f268bfa72
8021122: Not all callables are handled for toString and other function valued properties
sundar
parents:
diff
changeset
|
47 |
print(e); |
153f268bfa72
8021122: Not all callables are handled for toString and other function valued properties
sundar
parents:
diff
changeset
|
48 |
} |
153f268bfa72
8021122: Not all callables are handled for toString and other function valued properties
sundar
parents:
diff
changeset
|
49 |
|
153f268bfa72
8021122: Not all callables are handled for toString and other function valued properties
sundar
parents:
diff
changeset
|
50 |
function runLambdaTests() { |
153f268bfa72
8021122: Not all callables are handled for toString and other function valued properties
sundar
parents:
diff
changeset
|
51 |
var r = new java.lang.Runnable() { |
153f268bfa72
8021122: Not all callables are handled for toString and other function valued properties
sundar
parents:
diff
changeset
|
52 |
run: function() { print("I am runnable"); } |
153f268bfa72
8021122: Not all callables are handled for toString and other function valued properties
sundar
parents:
diff
changeset
|
53 |
}; |
153f268bfa72
8021122: Not all callables are handled for toString and other function valued properties
sundar
parents:
diff
changeset
|
54 |
|
153f268bfa72
8021122: Not all callables are handled for toString and other function valued properties
sundar
parents:
diff
changeset
|
55 |
// call any @FunctionalInterface object as though it is a function |
153f268bfa72
8021122: Not all callables are handled for toString and other function valued properties
sundar
parents:
diff
changeset
|
56 |
r(); |
153f268bfa72
8021122: Not all callables are handled for toString and other function valued properties
sundar
parents:
diff
changeset
|
57 |
|
153f268bfa72
8021122: Not all callables are handled for toString and other function valued properties
sundar
parents:
diff
changeset
|
58 |
var twice = new java.util.function.Function() { |
153f268bfa72
8021122: Not all callables are handled for toString and other function valued properties
sundar
parents:
diff
changeset
|
59 |
apply: function(x) 2*x |
153f268bfa72
8021122: Not all callables are handled for toString and other function valued properties
sundar
parents:
diff
changeset
|
60 |
}; |
153f268bfa72
8021122: Not all callables are handled for toString and other function valued properties
sundar
parents:
diff
changeset
|
61 |
|
153f268bfa72
8021122: Not all callables are handled for toString and other function valued properties
sundar
parents:
diff
changeset
|
62 |
print(twice(34)); |
153f268bfa72
8021122: Not all callables are handled for toString and other function valued properties
sundar
parents:
diff
changeset
|
63 |
|
153f268bfa72
8021122: Not all callables are handled for toString and other function valued properties
sundar
parents:
diff
changeset
|
64 |
var sum = new java.util.function.BiFunction() { |
153f268bfa72
8021122: Not all callables are handled for toString and other function valued properties
sundar
parents:
diff
changeset
|
65 |
apply: function(x, y) x + y |
153f268bfa72
8021122: Not all callables are handled for toString and other function valued properties
sundar
parents:
diff
changeset
|
66 |
}; |
153f268bfa72
8021122: Not all callables are handled for toString and other function valued properties
sundar
parents:
diff
changeset
|
67 |
|
153f268bfa72
8021122: Not all callables are handled for toString and other function valued properties
sundar
parents:
diff
changeset
|
68 |
print(sum(32, 12)) |
153f268bfa72
8021122: Not all callables are handled for toString and other function valued properties
sundar
parents:
diff
changeset
|
69 |
|
153f268bfa72
8021122: Not all callables are handled for toString and other function valued properties
sundar
parents:
diff
changeset
|
70 |
// make toString to be a @FunctionalInterface object |
153f268bfa72
8021122: Not all callables are handled for toString and other function valued properties
sundar
parents:
diff
changeset
|
71 |
var a = {}; |
153f268bfa72
8021122: Not all callables are handled for toString and other function valued properties
sundar
parents:
diff
changeset
|
72 |
a.toString = new java.util.function.Supplier() { |
153f268bfa72
8021122: Not all callables are handled for toString and other function valued properties
sundar
parents:
diff
changeset
|
73 |
get: function() { return "MyString"; } |
153f268bfa72
8021122: Not all callables are handled for toString and other function valued properties
sundar
parents:
diff
changeset
|
74 |
}; |
153f268bfa72
8021122: Not all callables are handled for toString and other function valued properties
sundar
parents:
diff
changeset
|
75 |
|
153f268bfa72
8021122: Not all callables are handled for toString and other function valued properties
sundar
parents:
diff
changeset
|
76 |
try { |
153f268bfa72
8021122: Not all callables are handled for toString and other function valued properties
sundar
parents:
diff
changeset
|
77 |
print(a); |
153f268bfa72
8021122: Not all callables are handled for toString and other function valued properties
sundar
parents:
diff
changeset
|
78 |
} catch (e) { |
153f268bfa72
8021122: Not all callables are handled for toString and other function valued properties
sundar
parents:
diff
changeset
|
79 |
print(e); |
153f268bfa72
8021122: Not all callables are handled for toString and other function valued properties
sundar
parents:
diff
changeset
|
80 |
} |
153f268bfa72
8021122: Not all callables are handled for toString and other function valued properties
sundar
parents:
diff
changeset
|
81 |
} |
153f268bfa72
8021122: Not all callables are handled for toString and other function valued properties
sundar
parents:
diff
changeset
|
82 |
|
153f268bfa72
8021122: Not all callables are handled for toString and other function valued properties
sundar
parents:
diff
changeset
|
83 |
try { |
153f268bfa72
8021122: Not all callables are handled for toString and other function valued properties
sundar
parents:
diff
changeset
|
84 |
// check for java.util.function.Function class |
153f268bfa72
8021122: Not all callables are handled for toString and other function valued properties
sundar
parents:
diff
changeset
|
85 |
Java.type("java.util.function.Function"); |
153f268bfa72
8021122: Not all callables are handled for toString and other function valued properties
sundar
parents:
diff
changeset
|
86 |
runLambdaTests(); |
153f268bfa72
8021122: Not all callables are handled for toString and other function valued properties
sundar
parents:
diff
changeset
|
87 |
} catch (e) { |
153f268bfa72
8021122: Not all callables are handled for toString and other function valued properties
sundar
parents:
diff
changeset
|
88 |
// fake output to match .EXPECTED values |
153f268bfa72
8021122: Not all callables are handled for toString and other function valued properties
sundar
parents:
diff
changeset
|
89 |
print("I am runnable"); |
153f268bfa72
8021122: Not all callables are handled for toString and other function valued properties
sundar
parents:
diff
changeset
|
90 |
print("68"); |
153f268bfa72
8021122: Not all callables are handled for toString and other function valued properties
sundar
parents:
diff
changeset
|
91 |
print("44"); |
153f268bfa72
8021122: Not all callables are handled for toString and other function valued properties
sundar
parents:
diff
changeset
|
92 |
print("MyString"); |
153f268bfa72
8021122: Not all callables are handled for toString and other function valued properties
sundar
parents:
diff
changeset
|
93 |
} |