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

Print this page
rev 752 : 8011964: need indexed access to externally-managed ByteBuffer
Reviewed-by: lagergren, hannesw
rev 760 : 8037400: Remove getInitialMap getters and GlobalObject interface
Reviewed-by: lagergren, jlaskey, attila

@@ -24,11 +24,12 @@
  */
 
 package jdk.nashorn.internal.runtime.arrays;
 
 import java.lang.invoke.MethodHandle;
-import jdk.nashorn.internal.runtime.GlobalObject;
+import java.nio.ByteBuffer;
+import jdk.nashorn.internal.objects.Global;
 import jdk.nashorn.internal.runtime.JSType;
 import jdk.nashorn.internal.runtime.PropertyDescriptor;
 
 /**
  * ArrayData - abstraction for wrapping array elements

@@ -142,10 +143,20 @@
     public static ArrayData allocate(final Object[] array) {
         return new ObjectArrayData(array, array.length);
     }
 
     /**
+     * Allocate an ArrayData wrapping a given nio ByteBuffer
+     *
+     * @param buf the nio ByteBuffer to wrap
+     * @return the ArrayData
+     */
+    public static ArrayData allocate(final ByteBuffer buf) {
+        return new ByteBufferArrayData((ByteBuffer)buf);
+    }
+
+    /**
      * Apply a freeze filter to an ArrayData.
      *
      * @param underlying  the underlying ArrayData to wrap in the freeze filter
      * @return the frozen ArrayData
      */

@@ -386,11 +397,11 @@
      * @param global the global object
      * @param index  the index
      *
      * @return property descriptor for element
      */
-    public PropertyDescriptor getDescriptor(final GlobalObject global, final int index) {
+    public PropertyDescriptor getDescriptor(final Global global, final int index) {
         return global.newDataDescriptor(getObject(index), true, true, true);
     }
 
     /**
      * Delete an array value at the given index, substituting