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 26 package 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 */ 34 public 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 int key, final int programPoint) { 48 return getInt(JSType.toObject(key), programPoint); 49 } 50 51 @Override 52 public double getDouble(final Object key, final int programPoint) { 53 return JSType.toNumber(get(key)); 54 } 55 56 @Override 57 public double getDouble(final double key, final int programPoint) { 58 return getDouble(JSType.toObject(key), programPoint); 59 } 60 61 @Override 62 public double getDouble(final int key, final int programPoint) { 63 return getDouble(JSType.toObject(key), programPoint); 64 } 65 66 @Override 67 public abstract Object get(Object key); 68 69 @Override 70 public Object get(final double key) { 71 return get(JSType.toObject(key)); 72 } 73 74 @Override 75 public Object get(final int key) { 76 return get(JSType.toObject(key)); 77 } 78 79 @Override 80 public void set(final double key, final int value, final int flags) { 81 set(JSType.toObject(key), JSType.toObject(value), flags); 82 } 83 84 @Override 85 public void set(final double key, final double value, final int flags) { 86 set(JSType.toObject(key), JSType.toObject(value), flags); 87 } 88 89 @Override 90 public void set(final double key, final Object value, final int flags) { 91 set(JSType.toObject(key), JSType.toObject(value), flags); 92 } 93 94 @Override 95 public void set(final int key, final int value, final int flags) { 96 set(JSType.toObject(key), JSType.toObject(value), flags); 97 } 98 99 @Override 100 public void set(final int key, final double value, final int flags) { 101 set(JSType.toObject(key), JSType.toObject(value), flags); 102 } 103 104 @Override 105 public void set(final int key, final Object value, final int flags) { 106 set(JSType.toObject(key), value, flags); 107 } 108 109 @Override 110 public void set(final Object key, final int value, final int flags) { 111 set(key, JSType.toObject(value), flags); 112 } 113 114 @Override 115 public void set(final Object key, final double value, final int flags) { 116 set(key, JSType.toObject(value), flags); 117 } 118 119 @Override 120 public abstract void set(Object key, Object value, int flags); 121 122 @Override 123 public abstract boolean has(Object key); 124 125 @Override 126 public boolean has(final int key) { 127 return has(JSType.toObject(key)); 128 } 129 130 @Override 131 public boolean has(final double key) { 132 return has(JSType.toObject(key)); 133 } 134 135 @Override 136 public boolean hasOwnProperty(final int key) { 137 return hasOwnProperty(JSType.toObject(key)); 138 } 139 140 @Override 141 public boolean hasOwnProperty(final double key) { 142 return hasOwnProperty(JSType.toObject(key)); 143 } 144 145 @Override 146 public abstract boolean hasOwnProperty(Object key); 147 148 @Override 149 public boolean delete(final int key, final boolean strict) { 150 return delete(JSType.toObject(key), strict); 151 } 152 153 @Override 154 public boolean delete(final double key, final boolean strict) { 155 return delete(JSType.toObject(key), strict); 156 } 157 158 }