DefaultPropertyAccess.java revision 1033:c1f651636d9c
1/* 2 * Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. Oracle designates this 8 * particular file as subject to the "Classpath" exception as provided 9 * by Oracle in the LICENSE file that accompanied this code. 10 * 11 * This code is distributed in the hope that it will be useful, but WITHOUT 12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 14 * version 2 for more details (a copy is included in the LICENSE file that 15 * accompanied this code). 16 * 17 * You should have received a copy of the GNU General Public License version 18 * 2 along with this work; if not, write to the Free Software Foundation, 19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 20 * 21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 22 * or visit www.oracle.com if you need additional information or have any 23 * questions. 24 */ 25 26package jdk.nashorn.internal.runtime; 27 28/** 29 * If your ScriptObject or similar PropertyAccess implementation only provides the most 30 * generic getters and setters and does nothing fancy with other, more primitive, types, 31 * then it is convenient to inherit this class and just fill out the methods left 32 * abstract 33 */ 34public abstract class DefaultPropertyAccess implements PropertyAccess { 35 36 @Override 37 public int getInt(final Object key, final int programPoint) { 38 return JSType.toInt32(get(key)); 39 } 40 41 @Override 42 public int getInt(final double key, final int programPoint) { 43 return getInt(JSType.toObject(key), programPoint); 44 } 45 46 @Override 47 public int getInt(final long key, final int programPoint) { 48 return getInt(JSType.toObject(key), programPoint); 49 } 50 51 @Override 52 public int getInt(final int key, final int programPoint) { 53 return getInt(JSType.toObject(key), programPoint); 54 } 55 56 @Override 57 public long getLong(final Object key, final int programPoint) { 58 return JSType.toLong(get(key)); 59 } 60 61 @Override 62 public long getLong(final double key, final int programPoint) { 63 return getLong(JSType.toObject(key), programPoint); 64 } 65 66 @Override 67 public long getLong(final long key, final int programPoint) { 68 return getLong(JSType.toObject(key), programPoint); 69 } 70 71 @Override 72 public long getLong(final int key, final int programPoint) { 73 return getLong(JSType.toObject(key), programPoint); 74 } 75 76 @Override 77 public double getDouble(final Object key, final int programPoint) { 78 return JSType.toNumber(get(key)); 79 } 80 81 @Override 82 public double getDouble(final double key, final int programPoint) { 83 return getDouble(JSType.toObject(key), programPoint); 84 } 85 86 @Override 87 public double getDouble(final long key, final int programPoint) { 88 return getDouble(JSType.toObject(key), programPoint); 89 } 90 91 @Override 92 public double getDouble(final int key, final int programPoint) { 93 return getDouble(JSType.toObject(key), programPoint); 94 } 95 96 @Override 97 public abstract Object get(Object key); 98 99 @Override 100 public Object get(final double key) { 101 return get(JSType.toObject(key)); 102 } 103 104 @Override 105 public Object get(final long key) { 106 return get(JSType.toObject(key)); 107 } 108 109 @Override 110 public Object get(final int key) { 111 return get(JSType.toObject(key)); 112 } 113 114 @Override 115 public void set(final double key, final int value, final int flags) { 116 set(JSType.toObject(key), JSType.toObject(value), flags); 117 } 118 119 @Override 120 public void set(final double key, final long value, final int flags) { 121 set(JSType.toObject(key), JSType.toObject(value), flags); 122 } 123 124 @Override 125 public void set(final double key, final double value, final int flags) { 126 set(JSType.toObject(key), JSType.toObject(value), flags); 127 } 128 129 @Override 130 public void set(final double key, final Object value, final int flags) { 131 set(JSType.toObject(key), JSType.toObject(value), flags); 132 } 133 134 @Override 135 public void set(final long key, final int value, final int flags) { 136 set(JSType.toObject(key), JSType.toObject(value), flags); 137 } 138 139 @Override 140 public void set(final long key, final long value, final int flags) { 141 set(JSType.toObject(key), JSType.toObject(value), flags); 142 } 143 144 @Override 145 public void set(final long key, final double value, final int flags) { 146 set(JSType.toObject(key), JSType.toObject(value), flags); 147 } 148 149 @Override 150 public void set(final long key, final Object value, final int flags) { 151 set(JSType.toObject(key), value, flags); 152 } 153 154 @Override 155 public void set(final int key, final int value, final int flags) { 156 set(JSType.toObject(key), JSType.toObject(value), flags); 157 } 158 159 @Override 160 public void set(final int key, final long value, final int flags) { 161 set(JSType.toObject(key), JSType.toObject(value), flags); 162 } 163 164 @Override 165 public void set(final int key, final double value, final int flags) { 166 set(JSType.toObject(key), JSType.toObject(value), flags); 167 } 168 169 @Override 170 public void set(final int key, final Object value, final int flags) { 171 set(JSType.toObject(key), value, flags); 172 } 173 174 @Override 175 public void set(final Object key, final int value, final int flags) { 176 set(key, JSType.toObject(value), flags); 177 } 178 179 @Override 180 public void set(final Object key, final long value, final int flags) { 181 set(key, JSType.toObject(value), flags); 182 } 183 184 @Override 185 public void set(final Object key, final double value, final int flags) { 186 set(key, JSType.toObject(value), flags); 187 } 188 189 @Override 190 public abstract void set(Object key, Object value, int flags); 191 192 @Override 193 public abstract boolean has(Object key); 194 195 @Override 196 public boolean has(final int key) { 197 return has(JSType.toObject(key)); 198 } 199 200 @Override 201 public boolean has(final long key) { 202 return has(JSType.toObject(key)); 203 } 204 205 @Override 206 public boolean has(final double key) { 207 return has(JSType.toObject(key)); 208 } 209 210 @Override 211 public boolean hasOwnProperty(final int key) { 212 return hasOwnProperty(JSType.toObject(key)); 213 } 214 215 @Override 216 public boolean hasOwnProperty(final long key) { 217 return hasOwnProperty(JSType.toObject(key)); 218 } 219 220 @Override 221 public boolean hasOwnProperty(final double key) { 222 return hasOwnProperty(JSType.toObject(key)); 223 } 224 225 @Override 226 public abstract boolean hasOwnProperty(Object key); 227 228 @Override 229 public boolean delete(final int key, final boolean strict) { 230 return delete(JSType.toObject(key), strict); 231 } 232 233 @Override 234 public boolean delete(final long key, final boolean strict) { 235 return delete(JSType.toObject(key), strict); 236 } 237 238 @Override 239 public boolean delete(final double key, final boolean strict) { 240 return delete(JSType.toObject(key), strict); 241 } 242 243} 244