8014735: Typed Array, BYTES_PER_ELEMENT should be a class property

Wed, 22 May 2013 19:33:08 +0530

author
sundar
date
Wed, 22 May 2013 19:33:08 +0530
changeset 284
66685c69bdb3
parent 283
07cefc062032
child 285
8f7553df4503

8014735: Typed Array, BYTES_PER_ELEMENT should be a class property
Reviewed-by: lagergren, jlaskey

src/jdk/nashorn/internal/objects/ArrayBufferView.java file | annotate | diff | comparison | revisions
src/jdk/nashorn/internal/objects/NativeFloat32Array.java file | annotate | diff | comparison | revisions
src/jdk/nashorn/internal/objects/NativeFloat64Array.java file | annotate | diff | comparison | revisions
src/jdk/nashorn/internal/objects/NativeInt16Array.java file | annotate | diff | comparison | revisions
src/jdk/nashorn/internal/objects/NativeInt32Array.java file | annotate | diff | comparison | revisions
src/jdk/nashorn/internal/objects/NativeInt8Array.java file | annotate | diff | comparison | revisions
src/jdk/nashorn/internal/objects/NativeUint16Array.java file | annotate | diff | comparison | revisions
src/jdk/nashorn/internal/objects/NativeUint32Array.java file | annotate | diff | comparison | revisions
src/jdk/nashorn/internal/objects/NativeUint8Array.java file | annotate | diff | comparison | revisions
src/jdk/nashorn/internal/objects/NativeUint8ClampedArray.java file | annotate | diff | comparison | revisions
test/script/basic/JDK-8014735.js file | annotate | diff | comparison | revisions
test/script/basic/JDK-8014735.js.EXPECTED file | annotate | diff | comparison | revisions
test/script/basic/NASHORN-377.js file | annotate | diff | comparison | revisions
     1.1 --- a/src/jdk/nashorn/internal/objects/ArrayBufferView.java	Wed May 22 16:39:48 2013 +0530
     1.2 +++ b/src/jdk/nashorn/internal/objects/ArrayBufferView.java	Wed May 22 19:33:08 2013 +0530
     1.3 @@ -28,6 +28,7 @@
     1.4  import jdk.nashorn.internal.objects.annotations.Attribute;
     1.5  import jdk.nashorn.internal.objects.annotations.Getter;
     1.6  import jdk.nashorn.internal.objects.annotations.ScriptClass;
     1.7 +import jdk.nashorn.internal.objects.annotations.Where;
     1.8  import jdk.nashorn.internal.runtime.JSType;
     1.9  import jdk.nashorn.internal.runtime.ScriptObject;
    1.10  import jdk.nashorn.internal.runtime.ScriptRuntime;
    1.11 @@ -59,11 +60,6 @@
    1.12      }
    1.13  
    1.14      @Getter(attributes = Attribute.NOT_ENUMERABLE | Attribute.NOT_WRITABLE | Attribute.NOT_CONFIGURABLE)
    1.15 -    public static Object BYTES_PER_ELEMENT(final Object self) {
    1.16 -        return ((ArrayBufferView)self).bytesPerElement();
    1.17 -    }
    1.18 -
    1.19 -    @Getter(attributes = Attribute.NOT_ENUMERABLE | Attribute.NOT_WRITABLE | Attribute.NOT_CONFIGURABLE)
    1.20      public static Object buffer(final Object self) {
    1.21          return ((ArrayDataImpl)((ArrayBufferView)self).getArray()).buffer;
    1.22      }
     2.1 --- a/src/jdk/nashorn/internal/objects/NativeFloat32Array.java	Wed May 22 16:39:48 2013 +0530
     2.2 +++ b/src/jdk/nashorn/internal/objects/NativeFloat32Array.java	Wed May 22 19:33:08 2013 +0530
     2.3 @@ -28,7 +28,9 @@
     2.4  import jdk.nashorn.internal.objects.annotations.Attribute;
     2.5  import jdk.nashorn.internal.objects.annotations.Constructor;
     2.6  import jdk.nashorn.internal.objects.annotations.Function;
     2.7 +import jdk.nashorn.internal.objects.annotations.Property;
     2.8  import jdk.nashorn.internal.objects.annotations.ScriptClass;
     2.9 +import jdk.nashorn.internal.objects.annotations.Where;
    2.10  import jdk.nashorn.internal.runtime.JSType;
    2.11  import jdk.nashorn.internal.runtime.ScriptObject;
    2.12  import jdk.nashorn.internal.runtime.arrays.ArrayData;
    2.13 @@ -38,7 +40,9 @@
    2.14   */
    2.15  @ScriptClass("Float32Array")
    2.16  public final class NativeFloat32Array extends ArrayBufferView {
    2.17 -    private static final int BYTES_PER_ELEMENT = 4;
    2.18 +    @Property(attributes = Attribute.NOT_ENUMERABLE | Attribute.NOT_WRITABLE | Attribute.NOT_CONFIGURABLE, where = Where.CONSTRUCTOR)
    2.19 +    public static final int BYTES_PER_ELEMENT = 4;
    2.20 +
    2.21      private static final Factory FACTORY = new Factory(BYTES_PER_ELEMENT) {
    2.22          @Override
    2.23          public ArrayBufferView construct(final NativeArrayBuffer buffer, final int byteOffset, final int length) {
     3.1 --- a/src/jdk/nashorn/internal/objects/NativeFloat64Array.java	Wed May 22 16:39:48 2013 +0530
     3.2 +++ b/src/jdk/nashorn/internal/objects/NativeFloat64Array.java	Wed May 22 19:33:08 2013 +0530
     3.3 @@ -28,7 +28,9 @@
     3.4  import jdk.nashorn.internal.objects.annotations.Attribute;
     3.5  import jdk.nashorn.internal.objects.annotations.Constructor;
     3.6  import jdk.nashorn.internal.objects.annotations.Function;
     3.7 +import jdk.nashorn.internal.objects.annotations.Property;
     3.8  import jdk.nashorn.internal.objects.annotations.ScriptClass;
     3.9 +import jdk.nashorn.internal.objects.annotations.Where;
    3.10  import jdk.nashorn.internal.runtime.JSType;
    3.11  import jdk.nashorn.internal.runtime.ScriptObject;
    3.12  import jdk.nashorn.internal.runtime.arrays.ArrayData;
    3.13 @@ -38,7 +40,9 @@
    3.14   */
    3.15  @ScriptClass("Float64Array")
    3.16  public final class NativeFloat64Array extends ArrayBufferView {
    3.17 -    private static final int BYTES_PER_ELEMENT = 8;
    3.18 +    @Property(attributes = Attribute.NOT_ENUMERABLE | Attribute.NOT_WRITABLE | Attribute.NOT_CONFIGURABLE, where = Where.CONSTRUCTOR)
    3.19 +    public static final int BYTES_PER_ELEMENT = 8;
    3.20 +
    3.21      private static final Factory FACTORY = new Factory(BYTES_PER_ELEMENT) {
    3.22          @Override
    3.23          public ArrayBufferView construct(final NativeArrayBuffer buffer, final int byteOffset, final int length) {
     4.1 --- a/src/jdk/nashorn/internal/objects/NativeInt16Array.java	Wed May 22 16:39:48 2013 +0530
     4.2 +++ b/src/jdk/nashorn/internal/objects/NativeInt16Array.java	Wed May 22 19:33:08 2013 +0530
     4.3 @@ -28,7 +28,9 @@
     4.4  import jdk.nashorn.internal.objects.annotations.Attribute;
     4.5  import jdk.nashorn.internal.objects.annotations.Constructor;
     4.6  import jdk.nashorn.internal.objects.annotations.Function;
     4.7 +import jdk.nashorn.internal.objects.annotations.Property;
     4.8  import jdk.nashorn.internal.objects.annotations.ScriptClass;
     4.9 +import jdk.nashorn.internal.objects.annotations.Where;
    4.10  import jdk.nashorn.internal.runtime.ScriptObject;
    4.11  import jdk.nashorn.internal.runtime.arrays.ArrayData;
    4.12  
    4.13 @@ -37,7 +39,9 @@
    4.14   */
    4.15  @ScriptClass("Int16Array")
    4.16  public final class NativeInt16Array extends ArrayBufferView {
    4.17 -    private static final int BYTES_PER_ELEMENT = 2;
    4.18 +    @Property(attributes = Attribute.NOT_ENUMERABLE | Attribute.NOT_WRITABLE | Attribute.NOT_CONFIGURABLE, where = Where.CONSTRUCTOR)
    4.19 +    public static final int BYTES_PER_ELEMENT = 2;
    4.20 +
    4.21      private static final Factory FACTORY = new Factory(BYTES_PER_ELEMENT) {
    4.22          @Override
    4.23          public ArrayBufferView construct(final NativeArrayBuffer buffer, final int byteOffset, final int length) {
     5.1 --- a/src/jdk/nashorn/internal/objects/NativeInt32Array.java	Wed May 22 16:39:48 2013 +0530
     5.2 +++ b/src/jdk/nashorn/internal/objects/NativeInt32Array.java	Wed May 22 19:33:08 2013 +0530
     5.3 @@ -28,7 +28,9 @@
     5.4  import jdk.nashorn.internal.objects.annotations.Attribute;
     5.5  import jdk.nashorn.internal.objects.annotations.Constructor;
     5.6  import jdk.nashorn.internal.objects.annotations.Function;
     5.7 +import jdk.nashorn.internal.objects.annotations.Property;
     5.8  import jdk.nashorn.internal.objects.annotations.ScriptClass;
     5.9 +import jdk.nashorn.internal.objects.annotations.Where;
    5.10  import jdk.nashorn.internal.runtime.ScriptObject;
    5.11  import jdk.nashorn.internal.runtime.arrays.ArrayData;
    5.12  
    5.13 @@ -37,7 +39,9 @@
    5.14   */
    5.15  @ScriptClass("Int32Array")
    5.16  public final class NativeInt32Array extends ArrayBufferView {
    5.17 -    private static final int BYTES_PER_ELEMENT = 4;
    5.18 +    @Property(attributes = Attribute.NOT_ENUMERABLE | Attribute.NOT_WRITABLE | Attribute.NOT_CONFIGURABLE, where = Where.CONSTRUCTOR)
    5.19 +    public static final int BYTES_PER_ELEMENT = 4;
    5.20 +
    5.21      private static final Factory FACTORY = new Factory(BYTES_PER_ELEMENT) {
    5.22          @Override
    5.23          public ArrayBufferView construct(final NativeArrayBuffer buffer, final int byteOffset, final int length) {
     6.1 --- a/src/jdk/nashorn/internal/objects/NativeInt8Array.java	Wed May 22 16:39:48 2013 +0530
     6.2 +++ b/src/jdk/nashorn/internal/objects/NativeInt8Array.java	Wed May 22 19:33:08 2013 +0530
     6.3 @@ -28,7 +28,9 @@
     6.4  import jdk.nashorn.internal.objects.annotations.Attribute;
     6.5  import jdk.nashorn.internal.objects.annotations.Constructor;
     6.6  import jdk.nashorn.internal.objects.annotations.Function;
     6.7 +import jdk.nashorn.internal.objects.annotations.Property;
     6.8  import jdk.nashorn.internal.objects.annotations.ScriptClass;
     6.9 +import jdk.nashorn.internal.objects.annotations.Where;
    6.10  import jdk.nashorn.internal.runtime.ScriptObject;
    6.11  import jdk.nashorn.internal.runtime.arrays.ArrayData;
    6.12  
    6.13 @@ -37,7 +39,9 @@
    6.14   */
    6.15  @ScriptClass("Int8Array")
    6.16  public final class NativeInt8Array extends ArrayBufferView {
    6.17 -    private static final int BYTES_PER_ELEMENT = 1;
    6.18 +    @Property(attributes = Attribute.NOT_ENUMERABLE | Attribute.NOT_WRITABLE | Attribute.NOT_CONFIGURABLE, where = Where.CONSTRUCTOR)
    6.19 +    public static final int BYTES_PER_ELEMENT = 1;
    6.20 +
    6.21      private static final Factory FACTORY = new Factory(BYTES_PER_ELEMENT) {
    6.22          @Override
    6.23          public ArrayBufferView construct(final NativeArrayBuffer buffer, final int byteOffset, final int length) {
     7.1 --- a/src/jdk/nashorn/internal/objects/NativeUint16Array.java	Wed May 22 16:39:48 2013 +0530
     7.2 +++ b/src/jdk/nashorn/internal/objects/NativeUint16Array.java	Wed May 22 19:33:08 2013 +0530
     7.3 @@ -28,7 +28,9 @@
     7.4  import jdk.nashorn.internal.objects.annotations.Attribute;
     7.5  import jdk.nashorn.internal.objects.annotations.Constructor;
     7.6  import jdk.nashorn.internal.objects.annotations.Function;
     7.7 +import jdk.nashorn.internal.objects.annotations.Property;
     7.8  import jdk.nashorn.internal.objects.annotations.ScriptClass;
     7.9 +import jdk.nashorn.internal.objects.annotations.Where;
    7.10  import jdk.nashorn.internal.runtime.ScriptObject;
    7.11  import jdk.nashorn.internal.runtime.arrays.ArrayData;
    7.12  
    7.13 @@ -37,7 +39,9 @@
    7.14   */
    7.15  @ScriptClass("Uint16Array")
    7.16  public final class NativeUint16Array extends ArrayBufferView {
    7.17 -    private static final int BYTES_PER_ELEMENT = 2;
    7.18 +    @Property(attributes = Attribute.NOT_ENUMERABLE | Attribute.NOT_WRITABLE | Attribute.NOT_CONFIGURABLE, where = Where.CONSTRUCTOR)
    7.19 +    public static final int BYTES_PER_ELEMENT = 2;
    7.20 +
    7.21      private static final Factory FACTORY = new Factory(BYTES_PER_ELEMENT) {
    7.22          @Override
    7.23          public ArrayBufferView construct(final NativeArrayBuffer buffer, final int byteOffset, final int length) {
     8.1 --- a/src/jdk/nashorn/internal/objects/NativeUint32Array.java	Wed May 22 16:39:48 2013 +0530
     8.2 +++ b/src/jdk/nashorn/internal/objects/NativeUint32Array.java	Wed May 22 19:33:08 2013 +0530
     8.3 @@ -28,7 +28,9 @@
     8.4  import jdk.nashorn.internal.objects.annotations.Attribute;
     8.5  import jdk.nashorn.internal.objects.annotations.Constructor;
     8.6  import jdk.nashorn.internal.objects.annotations.Function;
     8.7 +import jdk.nashorn.internal.objects.annotations.Property;
     8.8  import jdk.nashorn.internal.objects.annotations.ScriptClass;
     8.9 +import jdk.nashorn.internal.objects.annotations.Where;
    8.10  import jdk.nashorn.internal.runtime.JSType;
    8.11  import jdk.nashorn.internal.runtime.ScriptObject;
    8.12  import jdk.nashorn.internal.runtime.arrays.ArrayData;
    8.13 @@ -38,7 +40,9 @@
    8.14   */
    8.15  @ScriptClass("Uint32Array")
    8.16  public final class NativeUint32Array extends ArrayBufferView {
    8.17 -    private static final int BYTES_PER_ELEMENT = 4;
    8.18 +    @Property(attributes = Attribute.NOT_ENUMERABLE | Attribute.NOT_WRITABLE | Attribute.NOT_CONFIGURABLE, where = Where.CONSTRUCTOR)
    8.19 +    public static final int BYTES_PER_ELEMENT = 4;
    8.20 +
    8.21      private static final Factory FACTORY = new Factory(BYTES_PER_ELEMENT) {
    8.22          @Override
    8.23          public ArrayBufferView construct(final NativeArrayBuffer buffer, final int byteBegin, final int length) {
     9.1 --- a/src/jdk/nashorn/internal/objects/NativeUint8Array.java	Wed May 22 16:39:48 2013 +0530
     9.2 +++ b/src/jdk/nashorn/internal/objects/NativeUint8Array.java	Wed May 22 19:33:08 2013 +0530
     9.3 @@ -28,7 +28,9 @@
     9.4  import jdk.nashorn.internal.objects.annotations.Attribute;
     9.5  import jdk.nashorn.internal.objects.annotations.Constructor;
     9.6  import jdk.nashorn.internal.objects.annotations.Function;
     9.7 +import jdk.nashorn.internal.objects.annotations.Property;
     9.8  import jdk.nashorn.internal.objects.annotations.ScriptClass;
     9.9 +import jdk.nashorn.internal.objects.annotations.Where;
    9.10  import jdk.nashorn.internal.runtime.ScriptObject;
    9.11  import jdk.nashorn.internal.runtime.arrays.ArrayData;
    9.12  
    9.13 @@ -37,7 +39,9 @@
    9.14   */
    9.15  @ScriptClass("Uint8Array")
    9.16  public final class NativeUint8Array extends ArrayBufferView {
    9.17 -    private static final int BYTES_PER_ELEMENT = 1;
    9.18 +    @Property(attributes = Attribute.NOT_ENUMERABLE | Attribute.NOT_WRITABLE | Attribute.NOT_CONFIGURABLE, where = Where.CONSTRUCTOR)
    9.19 +    public static final int BYTES_PER_ELEMENT = 1;
    9.20 +
    9.21      private static final Factory FACTORY = new Factory(BYTES_PER_ELEMENT) {
    9.22          @Override
    9.23          public ArrayBufferView construct(final NativeArrayBuffer buffer, final int byteOffset, final int length) {
    10.1 --- a/src/jdk/nashorn/internal/objects/NativeUint8ClampedArray.java	Wed May 22 16:39:48 2013 +0530
    10.2 +++ b/src/jdk/nashorn/internal/objects/NativeUint8ClampedArray.java	Wed May 22 19:33:08 2013 +0530
    10.3 @@ -28,7 +28,9 @@
    10.4  import jdk.nashorn.internal.objects.annotations.Attribute;
    10.5  import jdk.nashorn.internal.objects.annotations.Constructor;
    10.6  import jdk.nashorn.internal.objects.annotations.Function;
    10.7 +import jdk.nashorn.internal.objects.annotations.Property;
    10.8  import jdk.nashorn.internal.objects.annotations.ScriptClass;
    10.9 +import jdk.nashorn.internal.objects.annotations.Where;
   10.10  import jdk.nashorn.internal.runtime.JSType;
   10.11  import jdk.nashorn.internal.runtime.ScriptObject;
   10.12  import jdk.nashorn.internal.runtime.arrays.ArrayData;
   10.13 @@ -38,7 +40,9 @@
   10.14   */
   10.15  @ScriptClass("Uint8ClampedArray")
   10.16  public final class NativeUint8ClampedArray extends ArrayBufferView {
   10.17 -    private static final int BYTES_PER_ELEMENT = 1;
   10.18 +    @Property(attributes = Attribute.NOT_ENUMERABLE | Attribute.NOT_WRITABLE | Attribute.NOT_CONFIGURABLE, where = Where.CONSTRUCTOR)
   10.19 +    public static final int BYTES_PER_ELEMENT = 1;
   10.20 +
   10.21      private static final Factory FACTORY = new Factory(BYTES_PER_ELEMENT) {
   10.22          @Override
   10.23          public ArrayBufferView construct(final NativeArrayBuffer buffer, final int byteOffset, final int length) {
    11.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    11.2 +++ b/test/script/basic/JDK-8014735.js	Wed May 22 19:33:08 2013 +0530
    11.3 @@ -0,0 +1,43 @@
    11.4 +/*
    11.5 + * Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved.
    11.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
    11.7 + *
    11.8 + * This code is free software; you can redistribute it and/or modify it
    11.9 + * under the terms of the GNU General Public License version 2 only, as
   11.10 + * published by the Free Software Foundation.
   11.11 + *
   11.12 + * This code is distributed in the hope that it will be useful, but WITHOUT
   11.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
   11.14 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
   11.15 + * version 2 for more details (a copy is included in the LICENSE file that
   11.16 + * accompanied this code).
   11.17 + *
   11.18 + * You should have received a copy of the GNU General Public License version
   11.19 + * 2 along with this work; if not, write to the Free Software Foundation,
   11.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
   11.21 + *
   11.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
   11.23 + * or visit www.oracle.com if you need additional information or have any
   11.24 + * questions.
   11.25 + */
   11.26 +
   11.27 +/**
   11.28 + * JDK-8014735: Typed Array, BYTES_PER_ELEMENT should be a class property
   11.29 + *
   11.30 + * @test
   11.31 + * @run
   11.32 + */
   11.33 +
   11.34 +function bytesPerElement(func) {
   11.35 +    print(func.name + ".BYTES_PER_ELEMENT = " + func.BYTES_PER_ELEMENT);
   11.36 +}
   11.37 +
   11.38 +bytesPerElement(Int8Array);
   11.39 +bytesPerElement(Int16Array);
   11.40 +bytesPerElement(Int32Array);
   11.41 +bytesPerElement(Uint8Array);
   11.42 +bytesPerElement(Uint8ClampedArray);
   11.43 +bytesPerElement(Uint16Array);
   11.44 +bytesPerElement(Uint32Array);
   11.45 +bytesPerElement(Float32Array);
   11.46 +bytesPerElement(Float64Array);
    12.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    12.2 +++ b/test/script/basic/JDK-8014735.js.EXPECTED	Wed May 22 19:33:08 2013 +0530
    12.3 @@ -0,0 +1,9 @@
    12.4 +Int8Array.BYTES_PER_ELEMENT = 1
    12.5 +Int16Array.BYTES_PER_ELEMENT = 2
    12.6 +Int32Array.BYTES_PER_ELEMENT = 4
    12.7 +Uint8Array.BYTES_PER_ELEMENT = 1
    12.8 +Uint8ClampedArray.BYTES_PER_ELEMENT = 1
    12.9 +Uint16Array.BYTES_PER_ELEMENT = 2
   12.10 +Uint32Array.BYTES_PER_ELEMENT = 4
   12.11 +Float32Array.BYTES_PER_ELEMENT = 4
   12.12 +Float64Array.BYTES_PER_ELEMENT = 8
    13.1 --- a/test/script/basic/NASHORN-377.js	Wed May 22 16:39:48 2013 +0530
    13.2 +++ b/test/script/basic/NASHORN-377.js	Wed May 22 19:33:08 2013 +0530
    13.3 @@ -43,7 +43,7 @@
    13.4  function arrstr(a, n, w) {
    13.5    var s = "";
    13.6    if (typeof n == "undefined") n = a.length;
    13.7 -  if (typeof w == "undefined") w = a.BYTES_PER_ELEMENT * 2;
    13.8 +  if (typeof w == "undefined") w = a.constructor.BYTES_PER_ELEMENT * 2;
    13.9    for (var i = 0; i < n; i++) {
   13.10      s += tohex(a[i], w);
   13.11    }
   13.12 @@ -96,7 +96,7 @@
   13.13    var b = new ArrayBuffer(8);
   13.14    for (var i in types) {
   13.15      var x = new types[i](b);
   13.16 -    print(x.byteOffset, x.byteLength, x.length, x.BYTES_PER_ELEMENT);
   13.17 +    print(x.byteOffset, x.byteLength, x.length, x.constructor.BYTES_PER_ELEMENT);
   13.18      assertTrue(function(){ return x.constructor === types[i] });
   13.19    }
   13.20  })();

mercurial