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  * Interface for getting and setting properties from script objects
  30  * This can be a plugin point for e.g. tagged values or alternative
  31  * array property getters.
  32  *
  33  * The interface is engineered with the combinatorially exhaustive
  34  * combination of types by purpose, for speed, as currently HotSpot is not
  35  * good enough at removing boxing.
  36  */
  37 public interface PropertyAccess {
  38     /**
  39      * Get the value for a given key and return it as an int
  40      * @param key the key
  41      * @param programPoint or INVALID_PROGRAM_POINT if pessimistic
  42      * @return the value
  43      */
  44     public int getInt(Object key, int programPoint);
  45 
  46     /**
  47      * Get the value for a given key and return it as an int
  48      * @param key the key
  49      * @param programPoint or INVALID_PROGRAM_POINT if pessimistic
  50      * @return the value
  51      */
  52     public int getInt(double key, int programPoint);
  53 
  54     /**
  55      * Get the value for a given key and return it as an int
  56      * @param key the key
  57      * @param programPoint or INVALID_PROGRAM_POINT if pessimistic
  58      * @return the value
  59      */
  60     public int getInt(int key, int programPoint);
  61 
  62     /**
  63      * Get the value for a given key and return it as a double
  64      * @param key the key
  65      * @param programPoint or INVALID_PROGRAM_POINT if pessimistic
  66      * @return the value
  67      */
  68     public double getDouble(Object key, int programPoint);
  69 
  70     /**
  71      * Get the value for a given key and return it as a double
  72      * @param key the key
  73      * @param programPoint or INVALID_PROGRAM_POINT if pessimistic
  74      * @return the value
  75      */
  76     public double getDouble(double key, int programPoint);
  77 
  78     /**
  79      * Get the value for a given key and return it as a double
  80      * @param key the key
  81      * @param programPoint or INVALID_PROGRAM_POINT if pessimistic
  82      * @return the value
  83      */
  84     public double getDouble(int key, int programPoint);
  85 
  86     /**
  87      * Get the value for a given key and return it as an Object
  88      * @param key the key
  89      * @return the value
  90      */
  91     public Object get(Object key);
  92 
  93     /**
  94      * Get the value for a given key and return it as an Object
  95      * @param key the key
  96      * @return the value
  97      */
  98     public Object get(double key);
  99 
 100     /**
 101      * Get the value for a given key and return it as an Object
 102      * @param key the key
 103      * @return the value
 104      */
 105     public Object get(int key);
 106 
 107     /**
 108      * Set the value of a given key
 109      * @param key     the key
 110      * @param value   the value
 111      * @param flags   call site flags
 112      */
 113     public void set(Object key, int value, int flags);
 114 
 115     /**
 116      * Set the value of a given key
 117      * @param key     the key
 118      * @param value   the value
 119      * @param flags   call site flags
 120      */
 121     public void set(Object key, double value, int flags);
 122 
 123     /**
 124      * Set the value of a given key
 125      * @param key     the key
 126      * @param value   the value
 127      * @param flags   call site flags
 128      */
 129     public void set(Object key, Object value, int flags);
 130 
 131     /**
 132      * Set the value of a given key
 133      * @param key     the key
 134      * @param value   the value
 135      * @param flags   call site flags
 136      */
 137     public void set(double key, int value, int flags);
 138 
 139     /**
 140      * Set the value of a given key
 141      * @param key     the key
 142      * @param value   the value
 143      * @param flags   call site flags
 144      */
 145     public void set(double key, double value, int flags);
 146 
 147     /**
 148      * Set the value of a given key
 149      * @param key     the key
 150      * @param value   the value
 151      * @param flags   call site flags
 152      */
 153     public void set(double key, Object value, int flags);
 154 
 155     /**
 156      * Set the value of a given key
 157      * @param key     the key
 158      * @param value   the value
 159      * @param flags   call site flags
 160      */
 161     public void set(int key, int value, int flags);
 162 
 163     /**
 164      * Set the value of a given key
 165      * @param key     the key
 166      * @param value   the value
 167      * @param flags   call site flags
 168      */
 169     public void set(int key, double value, int flags);
 170 
 171     /**
 172      * Set the value of a given key
 173      * @param key     the key
 174      * @param value   the value
 175      * @param flags   call site flags
 176      */
 177     public void set(int key, Object value, int flags);
 178 
 179     /**
 180      * Check if the given key exists anywhere in the proto chain
 181      * @param key the key
 182      * @return true if key exists
 183      */
 184     public boolean has(Object key);
 185 
 186     /**
 187      * Check if the given key exists anywhere in the proto chain
 188      * @param key the key
 189      * @return true if key exists
 190      */
 191     public boolean has(int key);
 192 
 193     /**
 194      * Check if the given key exists anywhere in the proto chain
 195      * @param key the key
 196      * @return true if key exists
 197      */
 198     public boolean has(double key);
 199 
 200     /**
 201      * Check if the given key exists directly in the implementor
 202      * @param key the key
 203      * @return true if key exists
 204      */
 205     public boolean hasOwnProperty(Object key);
 206 
 207     /**
 208      * Check if the given key exists directly in the implementor
 209      * @param key the key
 210      * @return true if key exists
 211      */
 212     public boolean hasOwnProperty(int key);
 213 
 214     /**
 215      * Check if the given key exists directly in the implementor
 216      * @param key the key
 217      * @return true if key exists
 218      */
 219     public boolean hasOwnProperty(double key);
 220 
 221     /**
 222      * Delete a property with the given key from the implementor
 223      * @param key    the key
 224      * @param strict are we in strict mode
 225      * @return true if deletion succeeded, false otherwise
 226      */
 227     public boolean delete(int key, boolean strict);
 228 
 229     /**
 230      * Delete a property with the given key from the implementor
 231      * @param key    the key
 232      * @param strict are we in strict mode
 233      * @return true if deletion succeeded, false otherwise
 234      */
 235     public boolean delete(double key, boolean strict);
 236 
 237     /**
 238      * Delete a property with the given key from the implementor
 239      * @param key    the key
 240      * @param strict are we in strict mode
 241      * @return true if deletion succeeded, false otherwise
 242      */
 243     public boolean delete(Object key, boolean strict);
 244 }