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 getInt(final Object key, final int programPoint)37 public int getInt(final Object key, final int programPoint) { 38 return JSType.toInt32(get(key)); 39 } 40 41 @Override getInt(final double key, final int programPoint)42 public int getInt(final double key, final int programPoint) { 43 return getInt(JSType.toObject(key), programPoint); 44 } 45 46 @Override getInt(final int key, final int programPoint)47 public int getInt(final int key, final int programPoint) { 48 return getInt(JSType.toObject(key), programPoint); 49 } 50 51 @Override getDouble(final Object key, final int programPoint)52 public double getDouble(final Object key, final int programPoint) { 53 return JSType.toNumber(get(key)); 54 } 55 56 @Override getDouble(final double key, final int programPoint)57 public double getDouble(final double key, final int programPoint) { 58 return getDouble(JSType.toObject(key), programPoint); 59 } 60 61 @Override getDouble(final int key, final int programPoint)62 public double getDouble(final int key, final int programPoint) { 63 return getDouble(JSType.toObject(key), programPoint); 64 } 65 66 @Override get(Object key)67 public abstract Object get(Object key); 68 69 @Override get(final double key)70 public Object get(final double key) { 71 return get(JSType.toObject(key)); 72 } 73 74 @Override get(final int key)75 public Object get(final int key) { 76 return get(JSType.toObject(key)); 77 } 78 79 @Override set(final double key, final int value, final int flags)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 set(final double key, final double value, final int flags)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 set(final double key, final Object value, final int flags)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 set(final int key, final int value, final int flags)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 set(final int key, final double value, final int flags)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 set(final int key, final Object value, final int flags)105 public void set(final int key, final Object value, final int flags) { 106 set(JSType.toObject(key), value, flags); 107 } 108 109 @Override set(final Object key, final int value, final int flags)110 public void set(final Object key, final int value, final int flags) { 111 set(key, JSType.toObject(value), flags); 112 } 113 114 @Override set(final Object key, final double value, final int flags)115 public void set(final Object key, final double value, final int flags) { 116 set(key, JSType.toObject(value), flags); 117 } 118 119 @Override set(Object key, Object value, int flags)120 public abstract void set(Object key, Object value, int flags); 121 122 @Override has(Object key)123 public abstract boolean has(Object key); 124 125 @Override has(final int key)126 public boolean has(final int key) { 127 return has(JSType.toObject(key)); 128 } 129 130 @Override has(final double key)131 public boolean has(final double key) { 132 return has(JSType.toObject(key)); 133 } 134 135 @Override hasOwnProperty(final int key)136 public boolean hasOwnProperty(final int key) { 137 return hasOwnProperty(JSType.toObject(key)); 138 } 139 140 @Override hasOwnProperty(final double key)141 public boolean hasOwnProperty(final double key) { 142 return hasOwnProperty(JSType.toObject(key)); 143 } 144 145 @Override hasOwnProperty(Object key)146 public abstract boolean hasOwnProperty(Object key); 147 148 @Override delete(final int key, final boolean strict)149 public boolean delete(final int key, final boolean strict) { 150 return delete(JSType.toObject(key), strict); 151 } 152 153 @Override delete(final double key, final boolean strict)154 public boolean delete(final double key, final boolean strict) { 155 return delete(JSType.toObject(key), strict); 156 } 157 158 } 159