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