author | sundar |
Wed, 21 Aug 2013 17:28:53 +0530 | |
changeset 19619 | 4085b74056ee |
parent 18876 | ada98218aaae |
child 24778 | 2ff5d7041566 |
permissions | -rw-r--r-- |
18876
ada98218aaae
8020324: Implement Object.bindProperties(target, source) for beans
attila
parents:
diff
changeset
|
1 |
/* |
ada98218aaae
8020324: Implement Object.bindProperties(target, source) for beans
attila
parents:
diff
changeset
|
2 |
* Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved. |
ada98218aaae
8020324: Implement Object.bindProperties(target, source) for beans
attila
parents:
diff
changeset
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
ada98218aaae
8020324: Implement Object.bindProperties(target, source) for beans
attila
parents:
diff
changeset
|
4 |
* |
ada98218aaae
8020324: Implement Object.bindProperties(target, source) for beans
attila
parents:
diff
changeset
|
5 |
* This code is free software; you can redistribute it and/or modify it |
ada98218aaae
8020324: Implement Object.bindProperties(target, source) for beans
attila
parents:
diff
changeset
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
ada98218aaae
8020324: Implement Object.bindProperties(target, source) for beans
attila
parents:
diff
changeset
|
7 |
* published by the Free Software Foundation. |
ada98218aaae
8020324: Implement Object.bindProperties(target, source) for beans
attila
parents:
diff
changeset
|
8 |
* |
ada98218aaae
8020324: Implement Object.bindProperties(target, source) for beans
attila
parents:
diff
changeset
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
ada98218aaae
8020324: Implement Object.bindProperties(target, source) for beans
attila
parents:
diff
changeset
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
ada98218aaae
8020324: Implement Object.bindProperties(target, source) for beans
attila
parents:
diff
changeset
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
ada98218aaae
8020324: Implement Object.bindProperties(target, source) for beans
attila
parents:
diff
changeset
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
ada98218aaae
8020324: Implement Object.bindProperties(target, source) for beans
attila
parents:
diff
changeset
|
13 |
* accompanied this code). |
ada98218aaae
8020324: Implement Object.bindProperties(target, source) for beans
attila
parents:
diff
changeset
|
14 |
* |
ada98218aaae
8020324: Implement Object.bindProperties(target, source) for beans
attila
parents:
diff
changeset
|
15 |
* You should have received a copy of the GNU General Public License version |
ada98218aaae
8020324: Implement Object.bindProperties(target, source) for beans
attila
parents:
diff
changeset
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
ada98218aaae
8020324: Implement Object.bindProperties(target, source) for beans
attila
parents:
diff
changeset
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
ada98218aaae
8020324: Implement Object.bindProperties(target, source) for beans
attila
parents:
diff
changeset
|
18 |
* |
ada98218aaae
8020324: Implement Object.bindProperties(target, source) for beans
attila
parents:
diff
changeset
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
ada98218aaae
8020324: Implement Object.bindProperties(target, source) for beans
attila
parents:
diff
changeset
|
20 |
* or visit www.oracle.com if you need additional information or have any |
ada98218aaae
8020324: Implement Object.bindProperties(target, source) for beans
attila
parents:
diff
changeset
|
21 |
* questions. |
ada98218aaae
8020324: Implement Object.bindProperties(target, source) for beans
attila
parents:
diff
changeset
|
22 |
*/ |
ada98218aaae
8020324: Implement Object.bindProperties(target, source) for beans
attila
parents:
diff
changeset
|
23 |
|
ada98218aaae
8020324: Implement Object.bindProperties(target, source) for beans
attila
parents:
diff
changeset
|
24 |
/** |
ada98218aaae
8020324: Implement Object.bindProperties(target, source) for beans
attila
parents:
diff
changeset
|
25 |
* JDK-8020324: Implement Object.bindProperties(target, source) for beans |
ada98218aaae
8020324: Implement Object.bindProperties(target, source) for beans
attila
parents:
diff
changeset
|
26 |
* |
ada98218aaae
8020324: Implement Object.bindProperties(target, source) for beans
attila
parents:
diff
changeset
|
27 |
* @test |
ada98218aaae
8020324: Implement Object.bindProperties(target, source) for beans
attila
parents:
diff
changeset
|
28 |
* @run |
ada98218aaae
8020324: Implement Object.bindProperties(target, source) for beans
attila
parents:
diff
changeset
|
29 |
*/ |
ada98218aaae
8020324: Implement Object.bindProperties(target, source) for beans
attila
parents:
diff
changeset
|
30 |
|
ada98218aaae
8020324: Implement Object.bindProperties(target, source) for beans
attila
parents:
diff
changeset
|
31 |
var PropertyBind = Java.type("jdk.nashorn.test.models.PropertyBind") |
ada98218aaae
8020324: Implement Object.bindProperties(target, source) for beans
attila
parents:
diff
changeset
|
32 |
var bean = new PropertyBind |
ada98218aaae
8020324: Implement Object.bindProperties(target, source) for beans
attila
parents:
diff
changeset
|
33 |
|
ada98218aaae
8020324: Implement Object.bindProperties(target, source) for beans
attila
parents:
diff
changeset
|
34 |
var obj1 = {} |
ada98218aaae
8020324: Implement Object.bindProperties(target, source) for beans
attila
parents:
diff
changeset
|
35 |
Object.bindProperties(obj1, bean) |
ada98218aaae
8020324: Implement Object.bindProperties(target, source) for beans
attila
parents:
diff
changeset
|
36 |
|
ada98218aaae
8020324: Implement Object.bindProperties(target, source) for beans
attila
parents:
diff
changeset
|
37 |
printBanner("Two-way read-write instance field") |
ada98218aaae
8020324: Implement Object.bindProperties(target, source) for beans
attila
parents:
diff
changeset
|
38 |
printEval("obj1.publicInt = 13") |
ada98218aaae
8020324: Implement Object.bindProperties(target, source) for beans
attila
parents:
diff
changeset
|
39 |
printEval("bean.publicInt") |
ada98218aaae
8020324: Implement Object.bindProperties(target, source) for beans
attila
parents:
diff
changeset
|
40 |
printEval("bean.publicInt = 15") |
ada98218aaae
8020324: Implement Object.bindProperties(target, source) for beans
attila
parents:
diff
changeset
|
41 |
printEval("obj1.publicInt") |
ada98218aaae
8020324: Implement Object.bindProperties(target, source) for beans
attila
parents:
diff
changeset
|
42 |
|
ada98218aaae
8020324: Implement Object.bindProperties(target, source) for beans
attila
parents:
diff
changeset
|
43 |
printBanner("Read only public instance field") |
ada98218aaae
8020324: Implement Object.bindProperties(target, source) for beans
attila
parents:
diff
changeset
|
44 |
printEval("obj1.publicFinalInt") |
ada98218aaae
8020324: Implement Object.bindProperties(target, source) for beans
attila
parents:
diff
changeset
|
45 |
printEval("obj1.publicFinalInt = 16") |
ada98218aaae
8020324: Implement Object.bindProperties(target, source) for beans
attila
parents:
diff
changeset
|
46 |
printEval("obj1.publicFinalInt") |
ada98218aaae
8020324: Implement Object.bindProperties(target, source) for beans
attila
parents:
diff
changeset
|
47 |
printEval("bean.publicFinalInt") |
ada98218aaae
8020324: Implement Object.bindProperties(target, source) for beans
attila
parents:
diff
changeset
|
48 |
|
ada98218aaae
8020324: Implement Object.bindProperties(target, source) for beans
attila
parents:
diff
changeset
|
49 |
printBanner("Two-way read-write instance property") |
ada98218aaae
8020324: Implement Object.bindProperties(target, source) for beans
attila
parents:
diff
changeset
|
50 |
printEval("obj1.readWrite = 17") |
ada98218aaae
8020324: Implement Object.bindProperties(target, source) for beans
attila
parents:
diff
changeset
|
51 |
printEval("bean.readWrite") |
ada98218aaae
8020324: Implement Object.bindProperties(target, source) for beans
attila
parents:
diff
changeset
|
52 |
printEval("bean.readWrite = 18") |
ada98218aaae
8020324: Implement Object.bindProperties(target, source) for beans
attila
parents:
diff
changeset
|
53 |
printEval("obj1.readWrite") |
ada98218aaae
8020324: Implement Object.bindProperties(target, source) for beans
attila
parents:
diff
changeset
|
54 |
printEval("obj1.getReadWrite()") |
ada98218aaae
8020324: Implement Object.bindProperties(target, source) for beans
attila
parents:
diff
changeset
|
55 |
printEval("obj1.setReadWrite(19)") |
ada98218aaae
8020324: Implement Object.bindProperties(target, source) for beans
attila
parents:
diff
changeset
|
56 |
printEval("obj1.readWrite") |
ada98218aaae
8020324: Implement Object.bindProperties(target, source) for beans
attila
parents:
diff
changeset
|
57 |
printEval("bean.readWrite") |
ada98218aaae
8020324: Implement Object.bindProperties(target, source) for beans
attila
parents:
diff
changeset
|
58 |
|
ada98218aaae
8020324: Implement Object.bindProperties(target, source) for beans
attila
parents:
diff
changeset
|
59 |
printBanner("Read only instance property") |
ada98218aaae
8020324: Implement Object.bindProperties(target, source) for beans
attila
parents:
diff
changeset
|
60 |
printEval("obj1.readOnly") |
ada98218aaae
8020324: Implement Object.bindProperties(target, source) for beans
attila
parents:
diff
changeset
|
61 |
printEval("obj1.readOnly = 20") |
ada98218aaae
8020324: Implement Object.bindProperties(target, source) for beans
attila
parents:
diff
changeset
|
62 |
printEval("obj1.readOnly") |
ada98218aaae
8020324: Implement Object.bindProperties(target, source) for beans
attila
parents:
diff
changeset
|
63 |
printEval("obj1.getReadOnly()") |
ada98218aaae
8020324: Implement Object.bindProperties(target, source) for beans
attila
parents:
diff
changeset
|
64 |
printEval("bean.getReadOnly()") |
ada98218aaae
8020324: Implement Object.bindProperties(target, source) for beans
attila
parents:
diff
changeset
|
65 |
|
ada98218aaae
8020324: Implement Object.bindProperties(target, source) for beans
attila
parents:
diff
changeset
|
66 |
printBanner("Write only instance property") |
ada98218aaae
8020324: Implement Object.bindProperties(target, source) for beans
attila
parents:
diff
changeset
|
67 |
printEval("obj1.writeOnly = 21") |
ada98218aaae
8020324: Implement Object.bindProperties(target, source) for beans
attila
parents:
diff
changeset
|
68 |
printEval("obj1.writeOnly") |
ada98218aaae
8020324: Implement Object.bindProperties(target, source) for beans
attila
parents:
diff
changeset
|
69 |
printEval("bean.writeOnly") |
ada98218aaae
8020324: Implement Object.bindProperties(target, source) for beans
attila
parents:
diff
changeset
|
70 |
printEval("bean.peekWriteOnly()") |
ada98218aaae
8020324: Implement Object.bindProperties(target, source) for beans
attila
parents:
diff
changeset
|
71 |
|
ada98218aaae
8020324: Implement Object.bindProperties(target, source) for beans
attila
parents:
diff
changeset
|
72 |
var obj2 = {} |
ada98218aaae
8020324: Implement Object.bindProperties(target, source) for beans
attila
parents:
diff
changeset
|
73 |
Object.bindProperties(obj2, PropertyBind) |
ada98218aaae
8020324: Implement Object.bindProperties(target, source) for beans
attila
parents:
diff
changeset
|
74 |
|
ada98218aaae
8020324: Implement Object.bindProperties(target, source) for beans
attila
parents:
diff
changeset
|
75 |
printBanner("Two-way read-write public static field") |
ada98218aaae
8020324: Implement Object.bindProperties(target, source) for beans
attila
parents:
diff
changeset
|
76 |
printEval("obj2.publicStaticInt = 22") |
ada98218aaae
8020324: Implement Object.bindProperties(target, source) for beans
attila
parents:
diff
changeset
|
77 |
printEval("PropertyBind.publicStaticInt") |
ada98218aaae
8020324: Implement Object.bindProperties(target, source) for beans
attila
parents:
diff
changeset
|
78 |
printEval("PropertyBind.publicStaticInt = 23") |
ada98218aaae
8020324: Implement Object.bindProperties(target, source) for beans
attila
parents:
diff
changeset
|
79 |
printEval("obj2.publicStaticInt") |
ada98218aaae
8020324: Implement Object.bindProperties(target, source) for beans
attila
parents:
diff
changeset
|
80 |
|
ada98218aaae
8020324: Implement Object.bindProperties(target, source) for beans
attila
parents:
diff
changeset
|
81 |
printBanner("Read only public static field") |
ada98218aaae
8020324: Implement Object.bindProperties(target, source) for beans
attila
parents:
diff
changeset
|
82 |
printEval("obj2.publicStaticFinalInt") |
ada98218aaae
8020324: Implement Object.bindProperties(target, source) for beans
attila
parents:
diff
changeset
|
83 |
printEval("obj2.publicStaticFinalInt = 24") |
ada98218aaae
8020324: Implement Object.bindProperties(target, source) for beans
attila
parents:
diff
changeset
|
84 |
printEval("obj2.publicStaticFinalInt") |
ada98218aaae
8020324: Implement Object.bindProperties(target, source) for beans
attila
parents:
diff
changeset
|
85 |
printEval("PropertyBind.publicStaticFinalInt") |
ada98218aaae
8020324: Implement Object.bindProperties(target, source) for beans
attila
parents:
diff
changeset
|
86 |
|
ada98218aaae
8020324: Implement Object.bindProperties(target, source) for beans
attila
parents:
diff
changeset
|
87 |
printBanner("Two-way read-write static property") |
ada98218aaae
8020324: Implement Object.bindProperties(target, source) for beans
attila
parents:
diff
changeset
|
88 |
printEval("obj2.staticReadWrite = 25") |
ada98218aaae
8020324: Implement Object.bindProperties(target, source) for beans
attila
parents:
diff
changeset
|
89 |
printEval("PropertyBind.staticReadWrite") |
ada98218aaae
8020324: Implement Object.bindProperties(target, source) for beans
attila
parents:
diff
changeset
|
90 |
printEval("PropertyBind.staticReadWrite = 26") |
ada98218aaae
8020324: Implement Object.bindProperties(target, source) for beans
attila
parents:
diff
changeset
|
91 |
printEval("obj2.staticReadWrite") |
ada98218aaae
8020324: Implement Object.bindProperties(target, source) for beans
attila
parents:
diff
changeset
|
92 |
printEval("obj2.getStaticReadWrite()") |
ada98218aaae
8020324: Implement Object.bindProperties(target, source) for beans
attila
parents:
diff
changeset
|
93 |
printEval("obj2.setStaticReadWrite(27)") |
ada98218aaae
8020324: Implement Object.bindProperties(target, source) for beans
attila
parents:
diff
changeset
|
94 |
printEval("obj2.staticReadWrite") |
ada98218aaae
8020324: Implement Object.bindProperties(target, source) for beans
attila
parents:
diff
changeset
|
95 |
printEval("PropertyBind.staticReadWrite") |
ada98218aaae
8020324: Implement Object.bindProperties(target, source) for beans
attila
parents:
diff
changeset
|
96 |
|
ada98218aaae
8020324: Implement Object.bindProperties(target, source) for beans
attila
parents:
diff
changeset
|
97 |
printBanner("Read only static property") |
ada98218aaae
8020324: Implement Object.bindProperties(target, source) for beans
attila
parents:
diff
changeset
|
98 |
printEval("obj2.staticReadOnly") |
ada98218aaae
8020324: Implement Object.bindProperties(target, source) for beans
attila
parents:
diff
changeset
|
99 |
printEval("obj2.staticReadOnly = 28") |
ada98218aaae
8020324: Implement Object.bindProperties(target, source) for beans
attila
parents:
diff
changeset
|
100 |
printEval("obj2.staticReadOnly") |
ada98218aaae
8020324: Implement Object.bindProperties(target, source) for beans
attila
parents:
diff
changeset
|
101 |
printEval("obj2.getStaticReadOnly()") |
ada98218aaae
8020324: Implement Object.bindProperties(target, source) for beans
attila
parents:
diff
changeset
|
102 |
printEval("PropertyBind.getStaticReadOnly()") |
ada98218aaae
8020324: Implement Object.bindProperties(target, source) for beans
attila
parents:
diff
changeset
|
103 |
|
ada98218aaae
8020324: Implement Object.bindProperties(target, source) for beans
attila
parents:
diff
changeset
|
104 |
printBanner("Write only static property") |
ada98218aaae
8020324: Implement Object.bindProperties(target, source) for beans
attila
parents:
diff
changeset
|
105 |
printEval("obj2.staticWriteOnly = 29") |
ada98218aaae
8020324: Implement Object.bindProperties(target, source) for beans
attila
parents:
diff
changeset
|
106 |
printEval("obj2.staticWriteOnly") |
ada98218aaae
8020324: Implement Object.bindProperties(target, source) for beans
attila
parents:
diff
changeset
|
107 |
printEval("PropertyBind.staticWriteOnly") |
ada98218aaae
8020324: Implement Object.bindProperties(target, source) for beans
attila
parents:
diff
changeset
|
108 |
printEval("PropertyBind.peekStaticWriteOnly()") |
ada98218aaae
8020324: Implement Object.bindProperties(target, source) for beans
attila
parents:
diff
changeset
|
109 |
|
ada98218aaae
8020324: Implement Object.bindProperties(target, source) for beans
attila
parents:
diff
changeset
|
110 |
printBanner("Sanity check to ensure property values remained what they were") |
ada98218aaae
8020324: Implement Object.bindProperties(target, source) for beans
attila
parents:
diff
changeset
|
111 |
printEval("obj1.publicInt") |
ada98218aaae
8020324: Implement Object.bindProperties(target, source) for beans
attila
parents:
diff
changeset
|
112 |
printEval("bean.publicInt") |
ada98218aaae
8020324: Implement Object.bindProperties(target, source) for beans
attila
parents:
diff
changeset
|
113 |
printEval("obj1.publicFinalInt") |
ada98218aaae
8020324: Implement Object.bindProperties(target, source) for beans
attila
parents:
diff
changeset
|
114 |
printEval("bean.publicFinalInt") |
ada98218aaae
8020324: Implement Object.bindProperties(target, source) for beans
attila
parents:
diff
changeset
|
115 |
printEval("obj1.readWrite") |
ada98218aaae
8020324: Implement Object.bindProperties(target, source) for beans
attila
parents:
diff
changeset
|
116 |
printEval("bean.readWrite") |
ada98218aaae
8020324: Implement Object.bindProperties(target, source) for beans
attila
parents:
diff
changeset
|
117 |
printEval("obj1.readOnly") |
ada98218aaae
8020324: Implement Object.bindProperties(target, source) for beans
attila
parents:
diff
changeset
|
118 |
printEval("bean.readOnly") |
ada98218aaae
8020324: Implement Object.bindProperties(target, source) for beans
attila
parents:
diff
changeset
|
119 |
printEval("bean.peekWriteOnly()") |
ada98218aaae
8020324: Implement Object.bindProperties(target, source) for beans
attila
parents:
diff
changeset
|
120 |
|
ada98218aaae
8020324: Implement Object.bindProperties(target, source) for beans
attila
parents:
diff
changeset
|
121 |
printEval("obj2.publicStaticInt") |
ada98218aaae
8020324: Implement Object.bindProperties(target, source) for beans
attila
parents:
diff
changeset
|
122 |
printEval("PropertyBind.publicStaticInt") |
ada98218aaae
8020324: Implement Object.bindProperties(target, source) for beans
attila
parents:
diff
changeset
|
123 |
printEval("obj2.publicStaticFinalInt") |
ada98218aaae
8020324: Implement Object.bindProperties(target, source) for beans
attila
parents:
diff
changeset
|
124 |
printEval("PropertyBind.publicStaticFinalInt") |
ada98218aaae
8020324: Implement Object.bindProperties(target, source) for beans
attila
parents:
diff
changeset
|
125 |
printEval("obj2.staticReadWrite") |
ada98218aaae
8020324: Implement Object.bindProperties(target, source) for beans
attila
parents:
diff
changeset
|
126 |
printEval("PropertyBind.staticReadWrite") |
ada98218aaae
8020324: Implement Object.bindProperties(target, source) for beans
attila
parents:
diff
changeset
|
127 |
printEval("obj2.staticReadOnly") |
ada98218aaae
8020324: Implement Object.bindProperties(target, source) for beans
attila
parents:
diff
changeset
|
128 |
printEval("PropertyBind.staticReadOnly") |
ada98218aaae
8020324: Implement Object.bindProperties(target, source) for beans
attila
parents:
diff
changeset
|
129 |
printEval("PropertyBind.peekStaticWriteOnly()") |
ada98218aaae
8020324: Implement Object.bindProperties(target, source) for beans
attila
parents:
diff
changeset
|
130 |
|
ada98218aaae
8020324: Implement Object.bindProperties(target, source) for beans
attila
parents:
diff
changeset
|
131 |
|
ada98218aaae
8020324: Implement Object.bindProperties(target, source) for beans
attila
parents:
diff
changeset
|
132 |
function printEval(s) { |
ada98218aaae
8020324: Implement Object.bindProperties(target, source) for beans
attila
parents:
diff
changeset
|
133 |
print(s + ": " + eval(s)) |
ada98218aaae
8020324: Implement Object.bindProperties(target, source) for beans
attila
parents:
diff
changeset
|
134 |
} |
ada98218aaae
8020324: Implement Object.bindProperties(target, source) for beans
attila
parents:
diff
changeset
|
135 |
|
ada98218aaae
8020324: Implement Object.bindProperties(target, source) for beans
attila
parents:
diff
changeset
|
136 |
function printBanner(s) { |
ada98218aaae
8020324: Implement Object.bindProperties(target, source) for beans
attila
parents:
diff
changeset
|
137 |
print() |
ada98218aaae
8020324: Implement Object.bindProperties(target, source) for beans
attila
parents:
diff
changeset
|
138 |
print("==== " + s + " ====") |
ada98218aaae
8020324: Implement Object.bindProperties(target, source) for beans
attila
parents:
diff
changeset
|
139 |
} |