src/jdk/nashorn/internal/runtime/DefaultPropertyAccess.java

Mon, 22 Sep 2014 13:28:28 +0200

author
hannesw
date
Mon, 22 Sep 2014 13:28:28 +0200
changeset 1020
9ee8fd4a7266
parent 963
e2497b11a021
child 1205
4112748288bb
child 1720
c09b105e7be5
permissions
-rw-r--r--

8047764: Indexed or polymorphic set on global affects Object.prototype
Reviewed-by: lagergren, attila

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

mercurial