nashorn/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/objects/NativeInt32Array.java
author attila
Wed, 15 Oct 2014 15:57:46 +0200
changeset 27104 bc8ce3f84b84
parent 26768 751b0f427090
child 27209 30d8609b9561
permissions -rw-r--r--
8060242: Compile-time expression evaluator was not seeing into ArrayBufferViews Reviewed-by: hannesw, lagergren, sundar
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
     1
/*
16151
97c1e756ae1e 8005663: Update copyright year to 2013
jlaskey
parents: 16147
diff changeset
     2
 * Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved.
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
     4
 *
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    10
 *
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    15
 * accompanied this code).
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    16
 *
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    20
 *
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    23
 * questions.
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    24
 */
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    25
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    26
package jdk.nashorn.internal.objects;
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    27
24720
75f8388b79df 8035836: Array performance improvements
lagergren
parents: 19638
diff changeset
    28
import static jdk.nashorn.internal.codegen.CompilerConstants.specialCall;
27104
bc8ce3f84b84 8060242: Compile-time expression evaluator was not seeing into ArrayBufferViews
attila
parents: 26768
diff changeset
    29
24720
75f8388b79df 8035836: Array performance improvements
lagergren
parents: 19638
diff changeset
    30
import java.lang.invoke.MethodHandle;
75f8388b79df 8035836: Array performance improvements
lagergren
parents: 19638
diff changeset
    31
import java.lang.invoke.MethodHandles;
75f8388b79df 8035836: Array performance improvements
lagergren
parents: 19638
diff changeset
    32
import java.nio.ByteBuffer;
75f8388b79df 8035836: Array performance improvements
lagergren
parents: 19638
diff changeset
    33
import java.nio.IntBuffer;
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    34
import jdk.nashorn.internal.objects.annotations.Attribute;
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    35
import jdk.nashorn.internal.objects.annotations.Constructor;
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    36
import jdk.nashorn.internal.objects.annotations.Function;
17763
f30b7aa0e736 8014735: Typed Array, BYTES_PER_ELEMENT should be a class property
sundar
parents: 16226
diff changeset
    37
import jdk.nashorn.internal.objects.annotations.Property;
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    38
import jdk.nashorn.internal.objects.annotations.ScriptClass;
17763
f30b7aa0e736 8014735: Typed Array, BYTES_PER_ELEMENT should be a class property
sundar
parents: 16226
diff changeset
    39
import jdk.nashorn.internal.objects.annotations.Where;
24720
75f8388b79df 8035836: Array performance improvements
lagergren
parents: 19638
diff changeset
    40
import jdk.nashorn.internal.runtime.JSType;
18618
136279c4cbe6 8019157: Avoid calling ScriptObject.setProto() if possible
hannesw
parents: 17771
diff changeset
    41
import jdk.nashorn.internal.runtime.PropertyMap;
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    42
import jdk.nashorn.internal.runtime.ScriptObject;
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    43
import jdk.nashorn.internal.runtime.arrays.ArrayData;
24720
75f8388b79df 8035836: Array performance improvements
lagergren
parents: 19638
diff changeset
    44
import jdk.nashorn.internal.runtime.arrays.TypedArrayData;
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    45
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    46
/**
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    47
 * Int32 array for the TypedArray extension
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    48
 */
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    49
@ScriptClass("Int32Array")
16226
0e4f37e6cc40 8007915: Nashorn IR, codegen, parser packages and Context instance should be inaccessible to user code
sundar
parents: 16151
diff changeset
    50
public final class NativeInt32Array extends ArrayBufferView {
17771
9fedae4933e4 8015354: JSON.parse should not use [[Put]] but use [[DefineOwnProperty]] instead
sundar
parents: 17763
diff changeset
    51
    /**
9fedae4933e4 8015354: JSON.parse should not use [[Put]] but use [[DefineOwnProperty]] instead
sundar
parents: 17763
diff changeset
    52
     * The size in bytes of each element in the array.
9fedae4933e4 8015354: JSON.parse should not use [[Put]] but use [[DefineOwnProperty]] instead
sundar
parents: 17763
diff changeset
    53
     */
17763
f30b7aa0e736 8014735: Typed Array, BYTES_PER_ELEMENT should be a class property
sundar
parents: 16226
diff changeset
    54
    @Property(attributes = Attribute.NOT_ENUMERABLE | Attribute.NOT_WRITABLE | Attribute.NOT_CONFIGURABLE, where = Where.CONSTRUCTOR)
f30b7aa0e736 8014735: Typed Array, BYTES_PER_ELEMENT should be a class property
sundar
parents: 16226
diff changeset
    55
    public static final int BYTES_PER_ELEMENT = 4;
f30b7aa0e736 8014735: Typed Array, BYTES_PER_ELEMENT should be a class property
sundar
parents: 16226
diff changeset
    56
18618
136279c4cbe6 8019157: Avoid calling ScriptObject.setProto() if possible
hannesw
parents: 17771
diff changeset
    57
    // initialized by nasgen
18842
3c3be808b593 8019585: Sometimes a var declaration using itself in its init wasn't declared as canBeUndefined, causing erroneous bytecode
lagergren
parents: 18618
diff changeset
    58
    @SuppressWarnings("unused")
18618
136279c4cbe6 8019157: Avoid calling ScriptObject.setProto() if possible
hannesw
parents: 17771
diff changeset
    59
    private static PropertyMap $nasgenmap$;
136279c4cbe6 8019157: Avoid calling ScriptObject.setProto() if possible
hannesw
parents: 17771
diff changeset
    60
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    61
    private static final Factory FACTORY = new Factory(BYTES_PER_ELEMENT) {
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    62
        @Override
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    63
        public ArrayBufferView construct(final NativeArrayBuffer buffer, final int byteOffset, final int length) {
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    64
            return new NativeInt32Array(buffer, byteOffset, length);
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    65
        }
24720
75f8388b79df 8035836: Array performance improvements
lagergren
parents: 19638
diff changeset
    66
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    67
        @Override
24720
75f8388b79df 8035836: Array performance improvements
lagergren
parents: 19638
diff changeset
    68
        public Int32ArrayData createArrayData(final ByteBuffer nb, final int start, final int length) {
75f8388b79df 8035836: Array performance improvements
lagergren
parents: 19638
diff changeset
    69
            return new Int32ArrayData(nb.asIntBuffer(), start, length);
75f8388b79df 8035836: Array performance improvements
lagergren
parents: 19638
diff changeset
    70
        }
75f8388b79df 8035836: Array performance improvements
lagergren
parents: 19638
diff changeset
    71
75f8388b79df 8035836: Array performance improvements
lagergren
parents: 19638
diff changeset
    72
        @Override
75f8388b79df 8035836: Array performance improvements
lagergren
parents: 19638
diff changeset
    73
        public String getClassName() {
75f8388b79df 8035836: Array performance improvements
lagergren
parents: 19638
diff changeset
    74
            return "Int32Array";
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    75
        }
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    76
    };
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    77
24720
75f8388b79df 8035836: Array performance improvements
lagergren
parents: 19638
diff changeset
    78
    private static final class Int32ArrayData extends TypedArrayData<IntBuffer> {
75f8388b79df 8035836: Array performance improvements
lagergren
parents: 19638
diff changeset
    79
75f8388b79df 8035836: Array performance improvements
lagergren
parents: 19638
diff changeset
    80
        private static final MethodHandle GET_ELEM = specialCall(MethodHandles.lookup(), Int32ArrayData.class, "getElem", int.class, int.class).methodHandle();
75f8388b79df 8035836: Array performance improvements
lagergren
parents: 19638
diff changeset
    81
        private static final MethodHandle SET_ELEM = specialCall(MethodHandles.lookup(), Int32ArrayData.class, "setElem", void.class, int.class, int.class).methodHandle();
75f8388b79df 8035836: Array performance improvements
lagergren
parents: 19638
diff changeset
    82
75f8388b79df 8035836: Array performance improvements
lagergren
parents: 19638
diff changeset
    83
        private Int32ArrayData(final IntBuffer nb, final int start, final int end) {
75f8388b79df 8035836: Array performance improvements
lagergren
parents: 19638
diff changeset
    84
            super(((IntBuffer)nb.position(start).limit(end)).slice(), end - start);
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    85
        }
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    86
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    87
        @Override
24720
75f8388b79df 8035836: Array performance improvements
lagergren
parents: 19638
diff changeset
    88
        protected MethodHandle getGetElem() {
75f8388b79df 8035836: Array performance improvements
lagergren
parents: 19638
diff changeset
    89
            return GET_ELEM;
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    90
        }
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    91
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    92
        @Override
24720
75f8388b79df 8035836: Array performance improvements
lagergren
parents: 19638
diff changeset
    93
        protected MethodHandle getSetElem() {
75f8388b79df 8035836: Array performance improvements
lagergren
parents: 19638
diff changeset
    94
            return SET_ELEM;
75f8388b79df 8035836: Array performance improvements
lagergren
parents: 19638
diff changeset
    95
        }
75f8388b79df 8035836: Array performance improvements
lagergren
parents: 19638
diff changeset
    96
75f8388b79df 8035836: Array performance improvements
lagergren
parents: 19638
diff changeset
    97
        private int getElem(final int index) {
75f8388b79df 8035836: Array performance improvements
lagergren
parents: 19638
diff changeset
    98
            try {
75f8388b79df 8035836: Array performance improvements
lagergren
parents: 19638
diff changeset
    99
                return nb.get(index);
75f8388b79df 8035836: Array performance improvements
lagergren
parents: 19638
diff changeset
   100
            } catch (final IndexOutOfBoundsException e) {
75f8388b79df 8035836: Array performance improvements
lagergren
parents: 19638
diff changeset
   101
                throw new ClassCastException(); //force relink - this works for unoptimistic too
75f8388b79df 8035836: Array performance improvements
lagergren
parents: 19638
diff changeset
   102
            }
75f8388b79df 8035836: Array performance improvements
lagergren
parents: 19638
diff changeset
   103
        }
75f8388b79df 8035836: Array performance improvements
lagergren
parents: 19638
diff changeset
   104
75f8388b79df 8035836: Array performance improvements
lagergren
parents: 19638
diff changeset
   105
        private void setElem(final int index, final int elem) {
75f8388b79df 8035836: Array performance improvements
lagergren
parents: 19638
diff changeset
   106
            try {
75f8388b79df 8035836: Array performance improvements
lagergren
parents: 19638
diff changeset
   107
                nb.put(index, elem);
75f8388b79df 8035836: Array performance improvements
lagergren
parents: 19638
diff changeset
   108
               } catch (final IndexOutOfBoundsException e) {
75f8388b79df 8035836: Array performance improvements
lagergren
parents: 19638
diff changeset
   109
                   if (index < 0) {
75f8388b79df 8035836: Array performance improvements
lagergren
parents: 19638
diff changeset
   110
                      throw new ClassCastException();
75f8388b79df 8035836: Array performance improvements
lagergren
parents: 19638
diff changeset
   111
                 }
75f8388b79df 8035836: Array performance improvements
lagergren
parents: 19638
diff changeset
   112
            }
75f8388b79df 8035836: Array performance improvements
lagergren
parents: 19638
diff changeset
   113
        }
75f8388b79df 8035836: Array performance improvements
lagergren
parents: 19638
diff changeset
   114
75f8388b79df 8035836: Array performance improvements
lagergren
parents: 19638
diff changeset
   115
        @Override
26768
751b0f427090 8025435: Optimistic builtins support, implemented initial optimistic versions of push, pop, and charCodeAt
lagergren
parents: 25865
diff changeset
   116
        public Class<?> getElementType() {
751b0f427090 8025435: Optimistic builtins support, implemented initial optimistic versions of push, pop, and charCodeAt
lagergren
parents: 25865
diff changeset
   117
            return int.class;
751b0f427090 8025435: Optimistic builtins support, implemented initial optimistic versions of push, pop, and charCodeAt
lagergren
parents: 25865
diff changeset
   118
        }
751b0f427090 8025435: Optimistic builtins support, implemented initial optimistic versions of push, pop, and charCodeAt
lagergren
parents: 25865
diff changeset
   119
751b0f427090 8025435: Optimistic builtins support, implemented initial optimistic versions of push, pop, and charCodeAt
lagergren
parents: 25865
diff changeset
   120
        @Override
24778
2ff5d7041566 8044638: Tidy up Nashorn codebase for code standards
attila
parents: 24769
diff changeset
   121
        public int getInt(final int index) {
24720
75f8388b79df 8035836: Array performance improvements
lagergren
parents: 19638
diff changeset
   122
            return getElem(index);
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   123
        }
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   124
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   125
        @Override
27104
bc8ce3f84b84 8060242: Compile-time expression evaluator was not seeing into ArrayBufferViews
attila
parents: 26768
diff changeset
   126
        public int getIntOptimistic(final int index, final int programPoint) {
bc8ce3f84b84 8060242: Compile-time expression evaluator was not seeing into ArrayBufferViews
attila
parents: 26768
diff changeset
   127
            return getElem(index);
bc8ce3f84b84 8060242: Compile-time expression evaluator was not seeing into ArrayBufferViews
attila
parents: 26768
diff changeset
   128
        }
bc8ce3f84b84 8060242: Compile-time expression evaluator was not seeing into ArrayBufferViews
attila
parents: 26768
diff changeset
   129
bc8ce3f84b84 8060242: Compile-time expression evaluator was not seeing into ArrayBufferViews
attila
parents: 26768
diff changeset
   130
        @Override
24778
2ff5d7041566 8044638: Tidy up Nashorn codebase for code standards
attila
parents: 24769
diff changeset
   131
        public long getLong(final int index) {
24720
75f8388b79df 8035836: Array performance improvements
lagergren
parents: 19638
diff changeset
   132
            return getInt(index);
75f8388b79df 8035836: Array performance improvements
lagergren
parents: 19638
diff changeset
   133
        }
75f8388b79df 8035836: Array performance improvements
lagergren
parents: 19638
diff changeset
   134
75f8388b79df 8035836: Array performance improvements
lagergren
parents: 19638
diff changeset
   135
        @Override
27104
bc8ce3f84b84 8060242: Compile-time expression evaluator was not seeing into ArrayBufferViews
attila
parents: 26768
diff changeset
   136
        public long getLongOptimistic(final int index, final int programPoint) {
bc8ce3f84b84 8060242: Compile-time expression evaluator was not seeing into ArrayBufferViews
attila
parents: 26768
diff changeset
   137
            return getElem(index);
bc8ce3f84b84 8060242: Compile-time expression evaluator was not seeing into ArrayBufferViews
attila
parents: 26768
diff changeset
   138
        }
bc8ce3f84b84 8060242: Compile-time expression evaluator was not seeing into ArrayBufferViews
attila
parents: 26768
diff changeset
   139
bc8ce3f84b84 8060242: Compile-time expression evaluator was not seeing into ArrayBufferViews
attila
parents: 26768
diff changeset
   140
        @Override
24778
2ff5d7041566 8044638: Tidy up Nashorn codebase for code standards
attila
parents: 24769
diff changeset
   141
        public double getDouble(final int index) {
24720
75f8388b79df 8035836: Array performance improvements
lagergren
parents: 19638
diff changeset
   142
            return getInt(index);
75f8388b79df 8035836: Array performance improvements
lagergren
parents: 19638
diff changeset
   143
        }
75f8388b79df 8035836: Array performance improvements
lagergren
parents: 19638
diff changeset
   144
75f8388b79df 8035836: Array performance improvements
lagergren
parents: 19638
diff changeset
   145
        @Override
27104
bc8ce3f84b84 8060242: Compile-time expression evaluator was not seeing into ArrayBufferViews
attila
parents: 26768
diff changeset
   146
        public double getDoubleOptimistic(final int index, final int programPoint) {
bc8ce3f84b84 8060242: Compile-time expression evaluator was not seeing into ArrayBufferViews
attila
parents: 26768
diff changeset
   147
            return getElem(index);
bc8ce3f84b84 8060242: Compile-time expression evaluator was not seeing into ArrayBufferViews
attila
parents: 26768
diff changeset
   148
        }
bc8ce3f84b84 8060242: Compile-time expression evaluator was not seeing into ArrayBufferViews
attila
parents: 26768
diff changeset
   149
bc8ce3f84b84 8060242: Compile-time expression evaluator was not seeing into ArrayBufferViews
attila
parents: 26768
diff changeset
   150
        @Override
24778
2ff5d7041566 8044638: Tidy up Nashorn codebase for code standards
attila
parents: 24769
diff changeset
   151
        public Object getObject(final int index) {
24720
75f8388b79df 8035836: Array performance improvements
lagergren
parents: 19638
diff changeset
   152
            return getInt(index);
75f8388b79df 8035836: Array performance improvements
lagergren
parents: 19638
diff changeset
   153
        }
75f8388b79df 8035836: Array performance improvements
lagergren
parents: 19638
diff changeset
   154
75f8388b79df 8035836: Array performance improvements
lagergren
parents: 19638
diff changeset
   155
        @Override
24778
2ff5d7041566 8044638: Tidy up Nashorn codebase for code standards
attila
parents: 24769
diff changeset
   156
        public ArrayData set(final int index, final Object value, final boolean strict) {
24720
75f8388b79df 8035836: Array performance improvements
lagergren
parents: 19638
diff changeset
   157
            return set(index, JSType.toInt32(value), strict);
75f8388b79df 8035836: Array performance improvements
lagergren
parents: 19638
diff changeset
   158
        }
75f8388b79df 8035836: Array performance improvements
lagergren
parents: 19638
diff changeset
   159
75f8388b79df 8035836: Array performance improvements
lagergren
parents: 19638
diff changeset
   160
        @Override
24778
2ff5d7041566 8044638: Tidy up Nashorn codebase for code standards
attila
parents: 24769
diff changeset
   161
        public ArrayData set(final int index, final int value, final boolean strict) {
24720
75f8388b79df 8035836: Array performance improvements
lagergren
parents: 19638
diff changeset
   162
            setElem(index, value);
75f8388b79df 8035836: Array performance improvements
lagergren
parents: 19638
diff changeset
   163
            return this;
75f8388b79df 8035836: Array performance improvements
lagergren
parents: 19638
diff changeset
   164
        }
75f8388b79df 8035836: Array performance improvements
lagergren
parents: 19638
diff changeset
   165
75f8388b79df 8035836: Array performance improvements
lagergren
parents: 19638
diff changeset
   166
        @Override
24778
2ff5d7041566 8044638: Tidy up Nashorn codebase for code standards
attila
parents: 24769
diff changeset
   167
        public ArrayData set(final int index, final long value, final boolean strict) {
24720
75f8388b79df 8035836: Array performance improvements
lagergren
parents: 19638
diff changeset
   168
            return set(index, (int)value, strict);
75f8388b79df 8035836: Array performance improvements
lagergren
parents: 19638
diff changeset
   169
        }
75f8388b79df 8035836: Array performance improvements
lagergren
parents: 19638
diff changeset
   170
75f8388b79df 8035836: Array performance improvements
lagergren
parents: 19638
diff changeset
   171
        @Override
24778
2ff5d7041566 8044638: Tidy up Nashorn codebase for code standards
attila
parents: 24769
diff changeset
   172
        public ArrayData set(final int index, final double value, final boolean strict) {
24720
75f8388b79df 8035836: Array performance improvements
lagergren
parents: 19638
diff changeset
   173
            return set(index, (int)value, strict);
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   174
        }
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   175
    }
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   176
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   177
    /**
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   178
     * Constructor
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   179
     *
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   180
     * @param newObj is this typed array instantiated with the new operator
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   181
     * @param self   self reference
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   182
     * @param args   args
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   183
     *
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   184
     * @return new typed array
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   185
     */
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   186
    @Constructor(arity = 1)
23763
950d8bc0554f 8038456: improve nasgen type checks and use specific return type for @Function, @SpecializedFunctio methods
sundar
parents: 19638
diff changeset
   187
    public static NativeInt32Array constructor(final boolean newObj, final Object self, final Object... args) {
24769
attila
parents: 24720 23763
diff changeset
   188
        return (NativeInt32Array)constructorImpl(newObj, args, FACTORY);
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   189
    }
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   190
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   191
    NativeInt32Array(final NativeArrayBuffer buffer, final int byteOffset, final int length) {
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   192
        super(buffer, byteOffset, length);
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   193
    }
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   194
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   195
    @Override
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   196
    protected Factory factory() {
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   197
        return FACTORY;
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   198
    }
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   199
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   200
    /**
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   201
     * Set values
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   202
     * @param self   self reference
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   203
     * @param array  multiple values of array's type to set
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   204
     * @param offset optional start index, interpreted  0 if undefined
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   205
     * @return undefined
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   206
     */
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   207
    @Function(attributes = Attribute.NOT_ENUMERABLE)
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   208
    protected static Object set(final Object self, final Object array, final Object offset) {
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   209
        return ArrayBufferView.setImpl(self, array, offset);
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   210
    }
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   211
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   212
    /**
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   213
     * Returns a new TypedArray view of the ArrayBuffer store for this TypedArray,
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   214
     * referencing the elements at begin, inclusive, up to end, exclusive. If either
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   215
     * begin or end is negative, it refers to an index from the end of the array,
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   216
     * as opposed to from the beginning.
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   217
     * <p>
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   218
     * If end is unspecified, the subarray contains all elements from begin to the end
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   219
     * of the TypedArray. The range specified by the begin and end values is clamped to
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   220
     * the valid index range for the current array. If the computed length of the new
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   221
     * TypedArray would be negative, it is clamped to zero.
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   222
     * <p>
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   223
     * The returned TypedArray will be of the same type as the array on which this
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   224
     * method is invoked.
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   225
     *
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   226
     * @param self self reference
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   227
     * @param begin begin position
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   228
     * @param end end position
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   229
     *
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   230
     * @return sub array
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   231
     */
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   232
    @Function(attributes = Attribute.NOT_ENUMERABLE)
23763
950d8bc0554f 8038456: improve nasgen type checks and use specific return type for @Function, @SpecializedFunctio methods
sundar
parents: 19638
diff changeset
   233
    protected static NativeInt32Array subarray(final Object self, final Object begin, final Object end) {
950d8bc0554f 8038456: improve nasgen type checks and use specific return type for @Function, @SpecializedFunctio methods
sundar
parents: 19638
diff changeset
   234
        return (NativeInt32Array)ArrayBufferView.subarrayImpl(self, begin, end);
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   235
    }
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   236
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   237
    @Override
18851
bdb92c95f886 8019947: inherited property invalidation does not work with two globals in same context
sundar
parents: 18842
diff changeset
   238
    protected ScriptObject getPrototype(final Global global) {
bdb92c95f886 8019947: inherited property invalidation does not work with two globals in same context
sundar
parents: 18842
diff changeset
   239
        return global.getInt32ArrayPrototype();
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   240
    }
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   241
}