src/jdk/nashorn/internal/runtime/arrays/ByteBufferArrayData.java

Print this page




  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 package jdk.nashorn.internal.runtime.arrays;
  26 
  27 import static jdk.nashorn.internal.runtime.ECMAErrors.typeError;
  28 
  29 import java.nio.ByteBuffer;
  30 import jdk.nashorn.internal.runtime.GlobalObject;
  31 import jdk.nashorn.internal.runtime.PropertyDescriptor;
  32 import jdk.nashorn.internal.runtime.ScriptRuntime;
  33 
  34 /**
  35  * Implementation of {@link ArrayData} that wraps a nio ByteBuffer
  36  */
  37 final class ByteBufferArrayData extends ArrayData {
  38     private final ByteBuffer buf;
  39 
  40     ByteBufferArrayData(final int length) {
  41         super(length);
  42         this.buf = ByteBuffer.allocateDirect(length);
  43     }
  44 
  45     /**
  46      * Constructor
  47      *
  48      * @param buf ByteBuffer to create array data with.
  49      */
  50     ByteBufferArrayData(final ByteBuffer buf) {
  51         super(buf.capacity());
  52         this.buf = buf;
  53     }
  54 
  55     /**
  56      * Returns property descriptor for element at a given index
  57      *
  58      * @param global the global object
  59      * @param index  the index
  60      *
  61      * @return property descriptor for element
  62      */
  63     public PropertyDescriptor getDescriptor(final GlobalObject global, final int index) {

  64         // make the index properties not configurable
  65         return global.newDataDescriptor(getObject(index), false, true, true);
  66     }
  67 
  68     @Override
  69     public ArrayData copy() {
  70         throw unsupported("copy");
  71     }
  72 
  73     @Override
  74     public Object[] asObjectArray() {
  75         throw unsupported("asObjectArray");
  76     }
  77 
  78     @Override
  79     public void setLength(final long length) {
  80         throw new UnsupportedOperationException("setLength");
  81     }
  82 
  83     @Override




  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 package jdk.nashorn.internal.runtime.arrays;
  26 
  27 import static jdk.nashorn.internal.runtime.ECMAErrors.typeError;
  28 
  29 import java.nio.ByteBuffer;
  30 import jdk.nashorn.internal.objects.Global;
  31 import jdk.nashorn.internal.runtime.PropertyDescriptor;
  32 import jdk.nashorn.internal.runtime.ScriptRuntime;
  33 
  34 /**
  35  * Implementation of {@link ArrayData} that wraps a nio ByteBuffer
  36  */
  37 final class ByteBufferArrayData extends ArrayData {
  38     private final ByteBuffer buf;
  39 
  40     ByteBufferArrayData(final int length) {
  41         super(length);
  42         this.buf = ByteBuffer.allocateDirect(length);
  43     }
  44 
  45     /**
  46      * Constructor
  47      *
  48      * @param buf ByteBuffer to create array data with.
  49      */
  50     ByteBufferArrayData(final ByteBuffer buf) {
  51         super(buf.capacity());
  52         this.buf = buf;
  53     }
  54 
  55     /**
  56      * Returns property descriptor for element at a given index
  57      *
  58      * @param global the global object
  59      * @param index  the index
  60      *
  61      * @return property descriptor for element
  62      */
  63     @Override
  64     public PropertyDescriptor getDescriptor(final Global global, final int index) {
  65         // make the index properties not configurable
  66         return global.newDataDescriptor(getObject(index), false, true, true);
  67     }
  68 
  69     @Override
  70     public ArrayData copy() {
  71         throw unsupported("copy");
  72     }
  73 
  74     @Override
  75     public Object[] asObjectArray() {
  76         throw unsupported("asObjectArray");
  77     }
  78 
  79     @Override
  80     public void setLength(final long length) {
  81         throw new UnsupportedOperationException("setLength");
  82     }
  83 
  84     @Override