author | sundar |
Mon, 11 Feb 2013 21:26:06 +0530 | |
changeset 16226 | 0e4f37e6cc40 |
parent 16151 | 97c1e756ae1e |
child 17763 | f30b7aa0e736 |
permissions | -rw-r--r-- |
16147 | 1 |
/* |
16151 | 2 |
* Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved. |
16147 | 3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 |
* |
|
5 |
* This code is free software; you can redistribute it and/or modify it |
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
|
7 |
* published by the Free Software Foundation. Oracle designates this |
|
8 |
* particular file as subject to the "Classpath" exception as provided |
|
9 |
* by Oracle in the LICENSE file that accompanied this code. |
|
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 |
||
26 |
package jdk.nashorn.internal.objects; |
|
27 |
||
28 |
import jdk.nashorn.internal.objects.annotations.Attribute; |
|
29 |
import jdk.nashorn.internal.objects.annotations.Constructor; |
|
30 |
import jdk.nashorn.internal.objects.annotations.Function; |
|
31 |
import jdk.nashorn.internal.objects.annotations.ScriptClass; |
|
32 |
import jdk.nashorn.internal.runtime.ScriptObject; |
|
33 |
import jdk.nashorn.internal.runtime.arrays.ArrayData; |
|
34 |
||
35 |
/** |
|
36 |
* Int8Array for the TypedArray extension |
|
37 |
*/ |
|
38 |
@ScriptClass("Int8Array") |
|
16226
0e4f37e6cc40
8007915: Nashorn IR, codegen, parser packages and Context instance should be inaccessible to user code
sundar
parents:
16151
diff
changeset
|
39 |
public final class NativeInt8Array extends ArrayBufferView { |
16147 | 40 |
private static final int BYTES_PER_ELEMENT = 1; |
41 |
private static final Factory FACTORY = new Factory(BYTES_PER_ELEMENT) { |
|
42 |
@Override |
|
43 |
public ArrayBufferView construct(final NativeArrayBuffer buffer, final int byteOffset, final int length) { |
|
44 |
return new NativeInt8Array(buffer, byteOffset, length); |
|
45 |
} |
|
46 |
||
47 |
@Override |
|
48 |
public ArrayData createArrayData(final NativeArrayBuffer buffer, final int byteOffset, final int length) { |
|
49 |
return new Int8ArrayData(buffer, byteOffset, length); |
|
50 |
} |
|
51 |
}; |
|
52 |
||
53 |
private static final class Int8ArrayData extends ArrayDataImpl { |
|
54 |
private Int8ArrayData(final NativeArrayBuffer buffer, final int byteOffset, final int elementLength) { |
|
55 |
super(buffer, byteOffset, elementLength); |
|
56 |
} |
|
57 |
||
58 |
@Override |
|
59 |
protected int byteIndex(final int index) { |
|
60 |
return index * BYTES_PER_ELEMENT + byteOffset; |
|
61 |
} |
|
62 |
||
63 |
@Override |
|
64 |
protected int getIntImpl(final int index) { |
|
65 |
return buffer.getByteArray()[byteIndex(index)]; |
|
66 |
} |
|
67 |
||
68 |
@Override |
|
69 |
protected void setImpl(final int index, final int value) { |
|
70 |
buffer.getByteArray()[byteIndex(index)] = (byte)value; |
|
71 |
} |
|
72 |
} |
|
73 |
||
74 |
/** |
|
75 |
* Constructor |
|
76 |
* |
|
77 |
* @param newObj is this typed array instantiated with the new operator |
|
78 |
* @param self self reference |
|
79 |
* @param args args |
|
80 |
* |
|
81 |
* @return new typed array |
|
82 |
*/ |
|
83 |
@Constructor(arity = 1) |
|
84 |
public static Object constructor(final boolean newObj, final Object self, final Object... args) { |
|
85 |
return constructorImpl(args, FACTORY); |
|
86 |
} |
|
87 |
||
88 |
NativeInt8Array(final NativeArrayBuffer buffer, final int byteOffset, final int length) { |
|
89 |
super(buffer, byteOffset, length); |
|
90 |
} |
|
91 |
||
92 |
@Override |
|
93 |
protected Factory factory() { |
|
94 |
return FACTORY; |
|
95 |
} |
|
96 |
||
97 |
/** |
|
98 |
* Set values |
|
99 |
* @param self self reference |
|
100 |
* @param array multiple values of array's type to set |
|
101 |
* @param offset optional start index, interpreted 0 if undefined |
|
102 |
* @return undefined |
|
103 |
*/ |
|
104 |
@Function(attributes = Attribute.NOT_ENUMERABLE) |
|
105 |
protected static Object set(final Object self, final Object array, final Object offset) { |
|
106 |
return ArrayBufferView.setImpl(self, array, offset); |
|
107 |
} |
|
108 |
||
109 |
/** |
|
110 |
* Returns a new TypedArray view of the ArrayBuffer store for this TypedArray, |
|
111 |
* referencing the elements at begin, inclusive, up to end, exclusive. If either |
|
112 |
* begin or end is negative, it refers to an index from the end of the array, |
|
113 |
* as opposed to from the beginning. |
|
114 |
* <p> |
|
115 |
* If end is unspecified, the subarray contains all elements from begin to the end |
|
116 |
* of the TypedArray. The range specified by the begin and end values is clamped to |
|
117 |
* the valid index range for the current array. If the computed length of the new |
|
118 |
* TypedArray would be negative, it is clamped to zero. |
|
119 |
* <p> |
|
120 |
* The returned TypedArray will be of the same type as the array on which this |
|
121 |
* method is invoked. |
|
122 |
* |
|
123 |
* @param self self reference |
|
124 |
* @param begin begin position |
|
125 |
* @param end end position |
|
126 |
* |
|
127 |
* @return sub array |
|
128 |
*/ |
|
129 |
@Function(attributes = Attribute.NOT_ENUMERABLE) |
|
130 |
protected static Object subarray(final Object self, final Object begin, final Object end) { |
|
131 |
return ArrayBufferView.subarrayImpl(self, begin, end); |
|
132 |
} |
|
133 |
||
134 |
@Override |
|
135 |
protected ScriptObject getPrototype() { |
|
136 |
return Global.instance().getInt8ArrayPrototype(); |
|
137 |
} |
|
138 |
} |