< prev index next >

src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/objects/NativeFloat64Array.java

Print this page




 107         private double getElem(final int index) {
 108             try {
 109                 return nb.get(index);
 110             } catch (final IndexOutOfBoundsException e) {
 111                 throw new ClassCastException(); //force relink - this works for unoptimistic too
 112             }
 113         }
 114 
 115         private void setElem(final int index, final double elem) {
 116             try {
 117                 if (index < nb.limit()) {
 118                     nb.put(index, elem);
 119                 }
 120             } catch (final IndexOutOfBoundsException e) {
 121                 throw new ClassCastException();
 122              }
 123         }
 124 
 125         @Override
 126         public MethodHandle getElementGetter(final Class<?> returnType, final int programPoint) {
 127             if (returnType == int.class || returnType == long.class) {
 128                 return null;
 129             }
 130             return getContinuousElementGetter(getClass(), GET_ELEM, returnType, programPoint);
 131         }
 132 
 133         @Override
 134         public int getInt(final int index) {
 135             return (int)getDouble(index);
 136         }
 137 
 138         @Override
 139         public long getLong(final int index) {
 140             return (long)getDouble(index);
 141         }
 142 
 143         @Override
 144         public double getDouble(final int index) {
 145             return getElem(index);
 146         }
 147 
 148         @Override
 149         public double getDoubleOptimistic(final int index, final int programPoint) {
 150             return getElem(index);
 151         }
 152 
 153         @Override
 154         public Object getObject(final int index) {
 155             return getDouble(index);
 156         }
 157 
 158         @Override
 159         public ArrayData set(final int index, final Object value, final boolean strict) {
 160             return set(index, JSType.toNumber(value), strict);
 161         }
 162 
 163         @Override
 164         public ArrayData set(final int index, final int value, final boolean strict) {
 165             return set(index, (double)value, strict);
 166         }
 167 
 168         @Override
 169         public ArrayData set(final int index, final long value, final boolean strict) {
 170             return set(index, (double)value, strict);
 171         }
 172 
 173         @Override
 174         public ArrayData set(final int index, final double value, final boolean strict) {
 175             setElem(index, value);
 176             return this;
 177         }
 178     }
 179 
 180     /**
 181      * Constructor
 182      *
 183      * @param newObj is this typed array instantiated with the new operator
 184      * @param self   self reference
 185      * @param args   args
 186      *
 187      * @return new typed array
 188      */
 189     @Constructor(arity = 1)




 107         private double getElem(final int index) {
 108             try {
 109                 return nb.get(index);
 110             } catch (final IndexOutOfBoundsException e) {
 111                 throw new ClassCastException(); //force relink - this works for unoptimistic too
 112             }
 113         }
 114 
 115         private void setElem(final int index, final double elem) {
 116             try {
 117                 if (index < nb.limit()) {
 118                     nb.put(index, elem);
 119                 }
 120             } catch (final IndexOutOfBoundsException e) {
 121                 throw new ClassCastException();
 122              }
 123         }
 124 
 125         @Override
 126         public MethodHandle getElementGetter(final Class<?> returnType, final int programPoint) {
 127             if (returnType == int.class) {
 128                 return null;
 129             }
 130             return getContinuousElementGetter(getClass(), GET_ELEM, returnType, programPoint);
 131         }
 132 
 133         @Override
 134         public int getInt(final int index) {
 135             return (int)getDouble(index);
 136         }
 137 
 138         @Override





 139         public double getDouble(final int index) {
 140             return getElem(index);
 141         }
 142 
 143         @Override
 144         public double getDoubleOptimistic(final int index, final int programPoint) {
 145             return getElem(index);
 146         }
 147 
 148         @Override
 149         public Object getObject(final int index) {
 150             return getDouble(index);
 151         }
 152 
 153         @Override
 154         public ArrayData set(final int index, final Object value, final boolean strict) {
 155             return set(index, JSType.toNumber(value), strict);
 156         }
 157 
 158         @Override
 159         public ArrayData set(final int index, final int value, final boolean strict) {





 160             return set(index, (double)value, strict);
 161         }
 162 
 163         @Override
 164         public ArrayData set(final int index, final double value, final boolean strict) {
 165             setElem(index, value);
 166             return this;
 167         }
 168     }
 169 
 170     /**
 171      * Constructor
 172      *
 173      * @param newObj is this typed array instantiated with the new operator
 174      * @param self   self reference
 175      * @param args   args
 176      *
 177      * @return new typed array
 178      */
 179     @Constructor(arity = 1)


< prev index next >