Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(86)

Side by Side Diff: test/mjsunit/harmony/dataview-accessors.js

Issue 142813003: A64: Synchronize with r15358. (Closed) Base URL: https://v8.googlecode.com/svn/branches/experimental/a64
Patch Set: Created 6 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « test/mjsunit/fuzz-natives-part4.js ('k') | test/mjsunit/harmony/generators-iteration.js » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright 2013 the V8 project authors. All rights reserved.
2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions are
4 // met:
5 //
6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above
9 // copyright notice, this list of conditions and the following
10 // disclaimer in the documentation and/or other materials provided
11 // with the distribution.
12 // * Neither the name of Google Inc. nor the names of its
13 // contributors may be used to endorse or promote products derived
14 // from this software without specific prior written permission.
15 //
16 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
20 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27
28 // These tests are adapted from Khronos DataView tests
29
30 var intArray1 =
31 [0, 1, 2, 3, 100, 101, 102, 103, 128, 129, 130, 131, 252, 253, 254, 255];
32 var intArray2 =
33 [31, 32, 33, 0, 1, 2, 3, 100, 101, 102, 103, 128, 129, 130, 131, 252,
34 253, 254, 255];
35 var initialArray =
36 [204, 204, 204, 204, 204, 204, 204, 204, 204, 204, 204, 204, 204,
37 204, 204, 204];
38
39 var arayBuffer = null;
40 var view = null;
41 var viewStart = 0;
42 var viewLength = 0;
43
44 function getElementSize(func) {
45 switch (func) {
46 case "Int8":
47 case "Uint8":
48 return 1;
49 case "Int16":
50 case "Uint16":
51 return 2;
52 case "Int32":
53 case "Uint32":
54 case "Float32":
55 return 4;
56 case "Float64":
57 return 8;
58 default:
59 assertUnreachable(func);
60 }
61 }
62
63 function checkGet(func, index, expected, littleEndian) {
64 function doGet() {
65 return view["get" + func](index, littleEndian);
66 }
67 if (index >=0 && index + getElementSize(func) - 1 < view.byteLength)
68 assertSame(expected, doGet());
69 else
70 assertThrows(doGet, RangeError);
71 }
72
73 function checkSet(func, index, value, littleEndian) {
74 function doSet() {
75 view["set" + func](index, value, littleEndian);
76 }
77 if (index >= 0 &&
78 index + getElementSize(func) - 1 < view.byteLength) {
79 assertSame(undefined, doSet());
80 checkGet(func, index, value, littleEndian);
81 } else {
82 assertThrows(doSet, RangeError);
83 }
84 }
85
86 function test(isTestingGet, func, index, value, littleEndian) {
87 if (isTestingGet)
88 checkGet(func, index, value, littleEndian);
89 else
90 checkSet(func, index, value, littleEndian);
91 }
92
93 function createDataView(
94 array, frontPaddingNum, littleEndian, start, length) {
95 if (!littleEndian)
96 array.reverse();
97 var paddingArray = new Array(frontPaddingNum);
98 arrayBuffer = (new Uint8Array(paddingArray.concat(array))).buffer;
99 view = new DataView(arrayBuffer, viewStart, viewLength);
100 if (!littleEndian)
101 array.reverse(); // restore the array.
102 }
103
104 function runIntegerTestCases(isTestingGet, array, start, length) {
105 createDataView(array, 0, true, start, length);
106
107 test(isTestingGet, "Int8", 0, 0);
108 test(isTestingGet, "Int8", 8, -128);
109 test(isTestingGet, "Int8", 15, -1);
110
111 test(isTestingGet, "Uint8", 0, 0);
112 test(isTestingGet, "Uint8", 8, 128);
113 test(isTestingGet, "Uint8", 15, 255);
114
115 // Little endian.
116 test(isTestingGet, "Int16", 0, 256, true);
117 test(isTestingGet, "Int16", 5, 26213, true);
118 test(isTestingGet, "Int16", 9, -32127, true);
119 test(isTestingGet, "Int16", 14, -2, true);
120
121 // Big endian.
122 test(isTestingGet, "Int16", 0, 1);
123 test(isTestingGet, "Int16", 5, 25958);
124 test(isTestingGet, "Int16", 9, -32382);
125 test(isTestingGet, "Int16", 14, -257);
126
127 // Little endian.
128 test(isTestingGet, "Uint16", 0, 256, true);
129 test(isTestingGet, "Uint16", 5, 26213, true);
130 test(isTestingGet, "Uint16", 9, 33409, true);
131 test(isTestingGet, "Uint16", 14, 65534, true);
132
133 // Big endian.
134 test(isTestingGet, "Uint16", 0, 1);
135 test(isTestingGet, "Uint16", 5, 25958);
136 test(isTestingGet, "Uint16", 9, 33154);
137 test(isTestingGet, "Uint16", 14, 65279);
138
139 // Little endian.
140 test(isTestingGet, "Int32", 0, 50462976, true);
141 test(isTestingGet, "Int32", 3, 1717920771, true);
142 test(isTestingGet, "Int32", 6, -2122291354, true);
143 test(isTestingGet, "Int32", 9, -58490239, true);
144 test(isTestingGet, "Int32", 12,-66052, true);
145
146 // Big endian.
147 test(isTestingGet, "Int32", 0, 66051);
148 test(isTestingGet, "Int32", 3, 56911206);
149 test(isTestingGet, "Int32", 6, 1718059137);
150 test(isTestingGet, "Int32", 9, -2122152964);
151 test(isTestingGet, "Int32", 12, -50462977);
152
153 // Little endian.
154 test(isTestingGet, "Uint32", 0, 50462976, true);
155 test(isTestingGet, "Uint32", 3, 1717920771, true);
156 test(isTestingGet, "Uint32", 6, 2172675942, true);
157 test(isTestingGet, "Uint32", 9, 4236477057, true);
158 test(isTestingGet, "Uint32", 12,4294901244, true);
159
160 // Big endian.
161 test(isTestingGet, "Uint32", 0, 66051);
162 test(isTestingGet, "Uint32", 3, 56911206);
163 test(isTestingGet, "Uint32", 6, 1718059137);
164 test(isTestingGet, "Uint32", 9, 2172814332);
165 test(isTestingGet, "Uint32", 12, 4244504319);
166 }
167
168 function testFloat(isTestingGet, func, array, start, expected) {
169 // Little endian.
170 createDataView(array, 0, true, start);
171 test(isTestingGet, func, 0, expected, true);
172 createDataView(array, 3, true, start);
173 test(isTestingGet, func, 3, expected, true);
174 createDataView(array, 7, true, start);
175 test(isTestingGet, func, 7, expected, true);
176 createDataView(array, 10, true, start);
177 test(isTestingGet, func, 10, expected, true);
178
179 // Big endian.
180 createDataView(array, 0, false);
181 test(isTestingGet, func, 0, expected, false);
182 createDataView(array, 3, false);
183 test(isTestingGet, func, 3, expected, false);
184 createDataView(array, 7, false);
185 test(isTestingGet, func, 7, expected, false);
186 createDataView(array, 10, false);
187 test(isTestingGet, func, 10, expected, false);
188 }
189
190 function runFloatTestCases(isTestingGet, start) {
191 testFloat(isTestingGet, "Float32",
192 isTestingGet ? [0, 0, 32, 65] : initialArray, start, 10);
193
194 testFloat(isTestingGet, "Float32",
195 isTestingGet ? [164, 112, 157, 63] : initialArray,
196 start, 1.2300000190734863);
197 testFloat(isTestingGet, "Float32",
198 isTestingGet ? [95, 53, 50, 199] : initialArray,
199 start, -45621.37109375);
200 testFloat(isTestingGet, "Float32",
201 isTestingGet ? [255, 255, 255, 127] : initialArray,
202 start, NaN);
203 testFloat(isTestingGet, "Float32",
204 isTestingGet ? [255, 255, 255, 255] : initialArray,
205 start, -NaN);
206
207 testFloat(isTestingGet, "Float64",
208 isTestingGet ? [0, 0, 0, 0, 0, 0, 36, 64] : initialArray,
209 start, 10);
210 testFloat(isTestingGet, "Float64",
211 isTestingGet ? [174, 71, 225, 122, 20, 174, 243, 63] : initialArray,
212 start, 1.23);
213 testFloat(isTestingGet, "Float64",
214 isTestingGet ? [181, 55, 248, 30, 242, 179, 87, 193] : initialArray,
215 start, -6213576.4839);
216 testFloat(isTestingGet, "Float64",
217 isTestingGet ? [255, 255, 255, 255, 255, 255, 255, 127] : initialArray,
218 start, NaN);
219 testFloat(isTestingGet, "Float64",
220 isTestingGet ? [255, 255, 255, 255, 255, 255, 255, 255] : initialArray,
221 start, -NaN);
222 }
223
224 function runNegativeIndexTests(isTestingGet) {
225 createDataView(intArray1, 0, true, 0, 16);
226
227 test(isTestingGet, "Int8", -1, 0);
228 test(isTestingGet, "Int8", -2, 0);
229
230 test(isTestingGet, "Uint8", -1, 0);
231 test(isTestingGet, "Uint8", -2, 0);
232
233 test(isTestingGet, "Int16", -1, 1);
234 test(isTestingGet, "Int16", -2, 1);
235 test(isTestingGet, "Int16", -3, 1);
236
237 test(isTestingGet, "Uint16", -1, 1);
238 test(isTestingGet, "Uint16", -2, 1);
239 test(isTestingGet, "Uint16", -3, 1);
240
241 test(isTestingGet, "Int32", -1, 66051);
242 test(isTestingGet, "Int32", -3, 66051);
243 test(isTestingGet, "Int32", -5, 66051);
244
245 test(isTestingGet, "Uint32", -1, 66051);
246 test(isTestingGet, "Uint32", -3, 66051);
247 test(isTestingGet, "Uint32", -5, 66051);
248
249 createDataView([0, 0, 0, 0, 0, 0, 0, 0], 0, true, 0, 8);
250
251 test(isTestingGet, "Float32", -1, 0);
252 test(isTestingGet, "Float32", -3, 0);
253 test(isTestingGet, "Float32", -5, 0);
254
255 test(isTestingGet, "Float64", -1, 0);
256 test(isTestingGet, "Float64", -5, 0);
257 test(isTestingGet, "Float64", -9, 0);
258 }
259
260
261 function TestGetters() {
262 runIntegerTestCases(true, intArray1, 0, 16);
263 runFloatTestCases(true, 0);
264
265 runIntegerTestCases(true, intArray2, 3, 2);
266 runFloatTestCases(true, 3);
267
268 runNegativeIndexTests(true);
269 }
270
271 function TestSetters() {
272 runIntegerTestCases(false, initialArray, 0, 16);
273 runFloatTestCases(false);
274
275 runIntegerTestCases(false, initialArray, 3, 2);
276 runFloatTestCases(false, 7);
277
278 runNegativeIndexTests(false);
279
280 }
281
282 TestGetters();
283 TestSetters();
284
285 function TestGeneralAccessors() {
286 var a = new DataView(new ArrayBuffer(256));
287 function CheckAccessor(name) {
288 var f = a[name];
289 f.call(a, 0, 0); // should not throw
290 assertThrows(function() { f.call({}, 0, 0); }, TypeError);
291 }
292 CheckAccessor("getUint8");
293 CheckAccessor("setUint8");
294 CheckAccessor("getInt8");
295 CheckAccessor("setInt8");
296 CheckAccessor("getUint16");
297 CheckAccessor("setUint16");
298 CheckAccessor("getInt16");
299 CheckAccessor("setInt16");
300 CheckAccessor("getUint32");
301 CheckAccessor("setUint32");
302 CheckAccessor("getInt32");
303 CheckAccessor("setInt32");
304 CheckAccessor("getFloat32");
305 CheckAccessor("setFloat32");
306 CheckAccessor("getFloat64");
307 CheckAccessor("setFloat64");
308 }
309
310 TestGeneralAccessors();
OLDNEW
« no previous file with comments | « test/mjsunit/fuzz-natives-part4.js ('k') | test/mjsunit/harmony/generators-iteration.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698