src/jdk/nashorn/internal/objects/NativeArrayBuffer.java

Print this page




  27 
  28 import java.nio.ByteBuffer;
  29 import java.util.Arrays;
  30 import jdk.nashorn.internal.objects.annotations.Attribute;
  31 import jdk.nashorn.internal.objects.annotations.Constructor;
  32 import jdk.nashorn.internal.objects.annotations.Function;
  33 import jdk.nashorn.internal.objects.annotations.Getter;
  34 import jdk.nashorn.internal.objects.annotations.ScriptClass;
  35 import jdk.nashorn.internal.runtime.JSType;
  36 import jdk.nashorn.internal.runtime.PropertyMap;
  37 import jdk.nashorn.internal.runtime.ScriptObject;
  38 import jdk.nashorn.internal.runtime.ScriptRuntime;
  39 
  40 @ScriptClass("ArrayBuffer")
  41 final class NativeArrayBuffer extends ScriptObject {
  42     private final byte[] buffer;
  43 
  44     // initialized by nasgen
  45     private static PropertyMap $nasgenmap$;
  46 
  47     static PropertyMap getInitialMap() {
  48         return $nasgenmap$;
  49     }
  50 
  51     @Constructor(arity = 1)
  52     public static Object constructor(final boolean newObj, final Object self, final Object... args) {
  53         if (args.length == 0) {
  54             throw new RuntimeException("missing length argument");
  55         }
  56 
  57         return new NativeArrayBuffer(JSType.toInt32(args[0]));
  58     }
  59 
  60     protected NativeArrayBuffer(final byte[] byteArray, final Global global) {
  61         super(global.getArrayBufferPrototype(), getInitialMap());
  62         this.buffer = byteArray;
  63     }
  64 
  65     protected NativeArrayBuffer(final byte[] byteArray) {
  66         this(byteArray, Global.instance());
  67     }
  68 
  69     protected NativeArrayBuffer(final int byteLength) {
  70         this(new byte[byteLength]);
  71     }
  72 
  73     protected NativeArrayBuffer(final NativeArrayBuffer other, final int begin, final int end) {
  74         this(Arrays.copyOfRange(other.buffer, begin, end));
  75     }
  76 
  77     @Override
  78     public String getClassName() {
  79         return "ArrayBuffer";
  80     }
  81 




  27 
  28 import java.nio.ByteBuffer;
  29 import java.util.Arrays;
  30 import jdk.nashorn.internal.objects.annotations.Attribute;
  31 import jdk.nashorn.internal.objects.annotations.Constructor;
  32 import jdk.nashorn.internal.objects.annotations.Function;
  33 import jdk.nashorn.internal.objects.annotations.Getter;
  34 import jdk.nashorn.internal.objects.annotations.ScriptClass;
  35 import jdk.nashorn.internal.runtime.JSType;
  36 import jdk.nashorn.internal.runtime.PropertyMap;
  37 import jdk.nashorn.internal.runtime.ScriptObject;
  38 import jdk.nashorn.internal.runtime.ScriptRuntime;
  39 
  40 @ScriptClass("ArrayBuffer")
  41 final class NativeArrayBuffer extends ScriptObject {
  42     private final byte[] buffer;
  43 
  44     // initialized by nasgen
  45     private static PropertyMap $nasgenmap$;
  46 




  47     @Constructor(arity = 1)
  48     public static Object constructor(final boolean newObj, final Object self, final Object... args) {
  49         if (args.length == 0) {
  50             throw new RuntimeException("missing length argument");
  51         }
  52 
  53         return new NativeArrayBuffer(JSType.toInt32(args[0]));
  54     }
  55 
  56     protected NativeArrayBuffer(final byte[] byteArray, final Global global) {
  57         super(global.getArrayBufferPrototype(), $nasgenmap$);
  58         this.buffer = byteArray;
  59     }
  60 
  61     protected NativeArrayBuffer(final byte[] byteArray) {
  62         this(byteArray, Global.instance());
  63     }
  64 
  65     protected NativeArrayBuffer(final int byteLength) {
  66         this(new byte[byteLength]);
  67     }
  68 
  69     protected NativeArrayBuffer(final NativeArrayBuffer other, final int begin, final int end) {
  70         this(Arrays.copyOfRange(other.buffer, begin, end));
  71     }
  72 
  73     @Override
  74     public String getClassName() {
  75         return "ArrayBuffer";
  76     }
  77