Debian Codegraph @

rhino/testsrc/jstests/harmony/typedarrays.js

raw symbols SCIP
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 // Flags: --harmony-tostring
29
30 // ArrayBuffer
31
32 load("testsrc/assert.js");
33
34 function TestByteLength(param, expectedByteLength) {
35 var ab = new ArrayBuffer(param);
36 assertSame(expectedByteLength, ab.byteLength);
37 }
38
39 function TestArrayBufferCreation() {
40 TestByteLength(1, 1);
41 TestByteLength(256, 256);
42 TestByteLength(2.567, 2);
43
44 TestByteLength("abc", 0);
45
46 TestByteLength(0, 0);
47
48 assertThrows(function() { new ArrayBuffer(-10); }, RangeError);
49 assertThrows(function() { new ArrayBuffer(-2.567); }, RangeError);
50
51 /* TODO[dslomov]: Reenable the test
52 assertThrows(function() {
53 var ab1 = new ArrayBuffer(0xFFFFFFFFFFFF)
54 }, RangeError);
55 */
56
57 var ab = new ArrayBuffer();
58 assertSame(0, ab.byteLength);
59 assertEquals("[object ArrayBuffer]",
60 Object.prototype.toString.call(ab));
61 }
62
63 TestArrayBufferCreation();
64
65 function TestByteLengthNotWritable() {
66 var ab = new ArrayBuffer(1024);
67 assertSame(1024, ab.byteLength);
68
69 // Rhino by default doesn't throw but ignores assignment
70 //assertThrows(function() { "use strict"; ab.byteLength = 42; }, TypeError);
71 ab.byteLength = 42;
72 assertSame(1024, ab.byteLength);
73 }
74
75 TestByteLengthNotWritable();
76
77 function TestSlice(expectedResultLen, initialLen, start, end) {
78 var ab = new ArrayBuffer(initialLen);
79 var a1 = new Uint8Array(ab);
80 for (var i = 0; i < a1.length; i++) {
81 a1[i] = 0xCA;
82 }
83 var slice = ab.slice(start, end);
84 assertSame(expectedResultLen, slice.byteLength);
85 var a2 = new Uint8Array(slice);
86 for (var i = 0; i < a2.length; i++) {
87 assertSame(0xCA, a2[i]);
88 }
89 }
90
91 function TestArrayBufferSlice() {
92 var ab = new ArrayBuffer(1024);
93 var ab1 = ab.slice(512, 1024);
94 assertSame(512, ab1.byteLength);
95
96 TestSlice(512, 1024, 512, 1024);
97 TestSlice(512, 1024, 512);
98
99 TestSlice(0, 0, 1, 20);
100 TestSlice(100, 100, 0, 100);
101 TestSlice(100, 100, 0, 1000);
102
103 TestSlice(0, 100, 5, 1);
104
105 TestSlice(1, 100, -11, -10);
106 TestSlice(9, 100, -10, 99);
107 TestSlice(0, 100, -10, 80);
108 TestSlice(10, 100, 80, -10);
109
110 TestSlice(10, 100, 90, "100");
111 TestSlice(10, 100, "90", "100");
112
113 TestSlice(0, 100, 90, "abc");
114 TestSlice(10, 100, "abc", 10);
115
116 TestSlice(10, 100, 0.96, 10.96);
117 TestSlice(10, 100, 0.96, 10.01);
118 TestSlice(10, 100, 0.01, 10.01);
119 TestSlice(10, 100, 0.01, 10.96);
120
121 TestSlice(10, 100, 90);
122 TestSlice(10, 100, -10);
123 }
124
125 TestArrayBufferSlice();
126
127 // Typed arrays
128
129 function TestTypedArray(constr, elementSize, typicalElement) {
130 assertSame(elementSize, constr.BYTES_PER_ELEMENT);
131
132 var ab = new ArrayBuffer(256*elementSize);
133
134 var a0 = new constr(30);
135 assertEquals("[object " + constr.name + "]",
136 Object.prototype.toString.call(a0));
137
138 assertTrue(ArrayBuffer.isView(a0));
139 assertSame(elementSize, a0.BYTES_PER_ELEMENT);
140 assertSame(30, a0.length);
141 assertSame(30*elementSize, a0.byteLength);
142 assertSame(0, a0.byteOffset);
143 assertSame(30*elementSize, a0.buffer.byteLength);
144
145 var aLen0 = new constr(0);
146 assertSame(elementSize, aLen0.BYTES_PER_ELEMENT);
147 assertSame(0, aLen0.length);
148 assertSame(0, aLen0.byteLength);
149 assertSame(0, aLen0.byteOffset);
150 assertSame(0, aLen0.buffer.byteLength);
151
152 var aOverBufferLen0 = new constr(ab, 128*elementSize, 0);
153 assertSame(ab, aOverBufferLen0.buffer);
154 assertSame(elementSize, aOverBufferLen0.BYTES_PER_ELEMENT);
155 assertSame(0, aOverBufferLen0.length);
156 assertSame(0, aOverBufferLen0.byteLength);
157 assertSame(128*elementSize, aOverBufferLen0.byteOffset);
158
159 var a1 = new constr(ab, 128*elementSize, 128);
160 assertSame(ab, a1.buffer);
161 assertSame(elementSize, a1.BYTES_PER_ELEMENT);
162 assertSame(128, a1.length);
163 assertSame(128*elementSize, a1.byteLength);
164 assertSame(128*elementSize, a1.byteOffset);
165
166
167 var a2 = new constr(ab, 64*elementSize, 128);
168 assertSame(ab, a2.buffer);
169 assertSame(elementSize, a2.BYTES_PER_ELEMENT);
170 assertSame(128, a2.length);
171 assertSame(128*elementSize, a2.byteLength);
172 assertSame(64*elementSize, a2.byteOffset);
173
174 var a3 = new constr(ab, 192*elementSize);
175 assertSame(ab, a3.buffer);
176 assertSame(64, a3.length);
177 assertSame(64*elementSize, a3.byteLength);
178 assertSame(192*elementSize, a3.byteOffset);
179
180 var a4 = new constr(ab);
181 assertSame(ab, a4.buffer);
182 assertSame(256, a4.length);
183 assertSame(256*elementSize, a4.byteLength);
184 assertSame(0, a4.byteOffset);
185
186
187 var i;
188 for (i = 0; i < 128; i++) {
189 a1[i] = typicalElement;
190 }
191
192 for (i = 0; i < 128; i++) {
193 assertSame(typicalElement, a1[i]);
194 }
195
196 for (i = 0; i < 64; i++) {
197 assertSame(0, a2[i]);
198 }
199
200 for (i = 64; i < 128; i++) {
201 assertSame(typicalElement, a2[i]);
202 }
203
204 for (i = 0; i < 64; i++) {
205 assertSame(typicalElement, a3[i]);
206 }
207
208 for (i = 0; i < 128; i++) {
209 assertSame(0, a4[i]);
210 }
211
212 for (i = 128; i < 256; i++) {
213 assertSame(typicalElement, a4[i]);
214 }
215
216 var aAtTheEnd = new constr(ab, 256*elementSize);
217 assertSame(elementSize, aAtTheEnd.BYTES_PER_ELEMENT);
218 assertSame(0, aAtTheEnd.length);
219 assertSame(0, aAtTheEnd.byteLength);
220 assertSame(256*elementSize, aAtTheEnd.byteOffset);
221
222 assertThrows(function () { new constr(ab, 257*elementSize); }, RangeError);
223 assertThrows(
224 function () { new constr(ab, 128*elementSize, 192); },
225 RangeError);
226
227 if (elementSize !== 1) {
228 assertThrows(function() { new constr(ab, 128*elementSize - 1, 10); },
229 RangeError);
230 var unalignedArrayBuffer = new ArrayBuffer(10*elementSize + 1);
231 var goodArray = new constr(unalignedArrayBuffer, 0, 10);
232 assertSame(10, goodArray.length);
233 assertSame(10*elementSize, goodArray.byteLength);
234 assertThrows(function() { new constr(unalignedArrayBuffer)}, RangeError);
235 assertThrows(function() { new constr(unalignedArrayBuffer, 5*elementSize)},
236 RangeError);
237 }
238
239 var aFromString = new constr("30");
240 assertSame(elementSize, aFromString.BYTES_PER_ELEMENT);
241 assertSame(30, aFromString.length);
242 assertSame(30*elementSize, aFromString.byteLength);
243 assertSame(0, aFromString.byteOffset);
244 assertSame(30*elementSize, aFromString.buffer.byteLength);
245
246 var jsArray = [];
247 for (i = 0; i < 30; i++) {
248 jsArray.push(typicalElement);
249 }
250 var aFromArray = new constr(jsArray);
251 assertSame(elementSize, aFromArray.BYTES_PER_ELEMENT);
252 assertSame(30, aFromArray.length);
253 assertSame(30*elementSize, aFromArray.byteLength);
254 assertSame(0, aFromArray.byteOffset);
255 assertSame(30*elementSize, aFromArray.buffer.byteLength);
256 for (i = 0; i < 30; i++) {
257 assertSame(typicalElement, aFromArray[i]);
258 }
259
260 var abLen0 = new ArrayBuffer(0);
261 var aOverAbLen0 = new constr(abLen0);
262 assertSame(abLen0, aOverAbLen0.buffer);
263 assertSame(elementSize, aOverAbLen0.BYTES_PER_ELEMENT);
264 assertSame(0, aOverAbLen0.length);
265 assertSame(0, aOverAbLen0.byteLength);
266 assertSame(0, aOverAbLen0.byteOffset);
267
268 var aNoParam = new constr();
269 assertSame(elementSize, aNoParam.BYTES_PER_ELEMENT);
270 assertSame(0, aNoParam.length);
271 assertSame(0, aNoParam.byteLength);
272 assertSame(0, aNoParam.byteOffset);
273
274 var a = new constr(ab, 64*elementSize, 128);
275 assertEquals("[object " + constr.name + "]",
276 Object.prototype.toString.call(a));
277
278 /* No "Symbol" in Rhino yet
279 var desc = Object.getOwnPropertyDescriptor(
280 constr.prototype, Symbol.toStringTag);
281 assertTrue(desc.configurable);
282 assertFalse(desc.enumerable);
283 assertFalse(!!desc.writable);
284 assertFalse(!!desc.set);
285 assertEquals("function", typeof desc.get);
286 */
287 }
288
289 TestTypedArray(Uint8Array, 1, 0xFF);
290 TestTypedArray(Int8Array, 1, -0x7F);
291 TestTypedArray(Uint16Array, 2, 0xFFFF);
292 TestTypedArray(Int16Array, 2, -0x7FFF);
293 TestTypedArray(Uint32Array, 4, 0xFFFFFFFF);
294 TestTypedArray(Int32Array, 4, -0x7FFFFFFF);
295 TestTypedArray(Float32Array, 4, 0.5);
296 TestTypedArray(Float64Array, 8, 0.5);
297 TestTypedArray(Uint8ClampedArray, 1, 0xFF);
298
299 function SubarrayTestCase(constructor, item, expectedResultLen, expectedStartIndex,
300 initialLen, start, end) {
301 var a = new constructor(initialLen);
302 var s = a.subarray(start, end);
303 // TODO Rhino constructor doesn't seem to be "==="
304 //assertSame(constructor, s.constructor);
305 assertSame(expectedResultLen, s.length);
306 if (s.length > 0) {
307 s[0] = item;
308 assertSame(item, a[expectedStartIndex]);
309 }
310 }
311
312 function TestSubArray(constructor, item) {
313 SubarrayTestCase(constructor, item, 512, 512, 1024, 512, 1024);
314 SubarrayTestCase(constructor, item, 512, 512, 1024, 512);
315
316 SubarrayTestCase(constructor, item, 0, undefined, 0, 1, 20);
317 SubarrayTestCase(constructor, item, 100, 0, 100, 0, 100);
318 SubarrayTestCase(constructor, item, 100, 0, 100, 0, 1000);
319 SubarrayTestCase(constructor, item, 0, undefined, 100, 5, 1);
320
321 SubarrayTestCase(constructor, item, 1, 89, 100, -11, -10);
322 SubarrayTestCase(constructor, item, 9, 90, 100, -10, 99);
323 SubarrayTestCase(constructor, item, 0, undefined, 100, -10, 80);
324 SubarrayTestCase(constructor, item, 10,80, 100, 80, -10);
325
326 SubarrayTestCase(constructor, item, 10,90, 100, 90, "100");
327 SubarrayTestCase(constructor, item, 10,90, 100, "90", "100");
328
329 SubarrayTestCase(constructor, item, 0, undefined, 100, 90, "abc");
330 SubarrayTestCase(constructor, item, 10,0, 100, "abc", 10);
331
332 SubarrayTestCase(constructor, item, 10,0, 100, 0.96, 10.96);
333 SubarrayTestCase(constructor, item, 10,0, 100, 0.96, 10.01);
334 SubarrayTestCase(constructor, item, 10,0, 100, 0.01, 10.01);
335 SubarrayTestCase(constructor, item, 10,0, 100, 0.01, 10.96);
336
337
338 SubarrayTestCase(constructor, item, 10,90, 100, 90);
339 SubarrayTestCase(constructor, item, 10,90, 100, -10);
340
341 var method = constructor.prototype.subarray;
342 method.call(new constructor(100), 0, 100);
343 var o = {};
344 assertThrows(function() { method.call(o, 0, 100); }, TypeError);
345 }
346
347 TestSubArray(Uint8Array, 0xFF);
348 TestSubArray(Int8Array, -0x7F);
349 TestSubArray(Uint16Array, 0xFFFF);
350 TestSubArray(Int16Array, -0x7FFF);
351 TestSubArray(Uint32Array, 0xFFFFFFFF);
352 TestSubArray(Int32Array, -0x7FFFFFFF);
353 TestSubArray(Float32Array, 0.5);
354 TestSubArray(Float64Array, 0.5);
355 TestSubArray(Uint8ClampedArray, 0xFF);
356
357 function TestTypedArrayOutOfRange(constructor, value, result) {
358 var a = new constructor(1);
359 a[0] = value;
360 assertSame(result, a[0]);
361 }
362
363 TestTypedArrayOutOfRange(Uint8Array, 0x1FA, 0xFA);
364 TestTypedArrayOutOfRange(Uint8Array, -1, 0xFF);
365
366 TestTypedArrayOutOfRange(Int8Array, 0x1FA, 0x7A - 0x80);
367
368 TestTypedArrayOutOfRange(Uint16Array, 0x1FFFA, 0xFFFA);
369 TestTypedArrayOutOfRange(Uint16Array, -1, 0xFFFF);
370 TestTypedArrayOutOfRange(Int16Array, 0x1FFFA, 0x7FFA - 0x8000);
371
372 TestTypedArrayOutOfRange(Uint32Array, 0x1FFFFFFFA, 0xFFFFFFFA);
373 TestTypedArrayOutOfRange(Uint32Array, -1, 0xFFFFFFFF);
374 TestTypedArrayOutOfRange(Int32Array, 0x1FFFFFFFA, 0x7FFFFFFA - 0x80000000);
375
376 TestTypedArrayOutOfRange(Uint8ClampedArray, 0x1FA, 0xFF);
377 TestTypedArrayOutOfRange(Uint8ClampedArray, -1, 0);
378
379 var typedArrayConstructors = [
380 Uint8Array,
381 Int8Array,
382 Uint16Array,
383 Int16Array,
384 Uint32Array,
385 Int32Array,
386 Uint8ClampedArray,
387 Float32Array,
388 Float64Array];
389
390 /*
391 * TODO RHINO getOwnPropertyDescriptor is not there yet
392 function TestPropertyTypeChecks(constructor) {
393 function CheckProperty(name) {
394 var d = Object.getOwnPropertyDescriptor(constructor.prototype, name);
395 var o = {};
396 assertThrows(function() {d.get.call(o);}, TypeError);
397 for (var i = 0; i < typedArrayConstructors.length; i++) {
398 var ctor = typedArrayConstructors[i];
399 var a = new ctor(10);
400 if (ctor === constructor) {
401 d.get.call(a); // shouldn't throw
402 } else {
403 assertThrows(function() {d.get.call(a);}, TypeError);
404 }
405 }
406 }
407
408 CheckProperty("buffer");
409 CheckProperty("byteOffset");
410 CheckProperty("byteLength");
411 CheckProperty("length");
412 }
413
414 for(i = 0; i < typedArrayConstructors.length; i++) {
415 TestPropertyTypeChecks(typedArrayConstructors[i]);
416 }
417 */
418
419 function TestTypedArraySet() {
420 // Test array.set in different combinations.
421
422 function assertArrayPrefix(expected, array) {
423 for (var i = 0; i < expected.length; ++i) {
424 assertEquals(expected[i], array[i], 'index ' + i);
425 }
426 }
427
428 var a11 = new Int16Array([1, 2, 3, 4, 0, -1])
429 var a12 = new Uint16Array(15)
430 a12.set(a11, 3)
431 assertArrayPrefix([0, 0, 0, 1, 2, 3, 4, 0, 0xffff, 0, 0], a12)
432 assertThrows(function(){ a11.set(a12) })
433
434 var a21 = [1, undefined, 10, NaN, 0, -1, {valueOf: function() {return 3}}]
435 var a22 = new Int32Array(12)
436 a22.set(a21, 2)
437 assertArrayPrefix([0, 0, 1, 0, 10, 0, 0, -1, 3, 0], a22)
438
439 var a31 = new Float32Array([2, 4, 6, 8, 11, NaN, 1/0, -3])
440 var a32 = a31.subarray(2, 6)
441 a31.set(a32, 4)
442 assertArrayPrefix([2, 4, 6, 8, 6, 8, 11, NaN], a31)
443 // Rhino -- origin test suite was expecting two more elements beyond the end of the array
444 assertArrayPrefix([6, 8, 6, 8], a32)
445
446 var a4 = new Uint8ClampedArray([3,2,5,6])
447 a4.set(a4)
448 assertArrayPrefix([3, 2, 5, 6], a4)
449
450 // Cases with overlapping backing store but different element sizes.
451 var b = new ArrayBuffer(4)
452 var a5 = new Int16Array(b)
453 var a50 = new Int8Array(b)
454 var a51 = new Int8Array(b, 0, 2)
455 var a52 = new Int8Array(b, 1, 2)
456 var a53 = new Int8Array(b, 2, 2)
457
458 a5.set([0x5050, 0x0a0a])
459 assertArrayPrefix([0x50, 0x50, 0x0a, 0x0a], a50)
460 assertArrayPrefix([0x50, 0x50], a51)
461 assertArrayPrefix([0x50, 0x0a], a52)
462 assertArrayPrefix([0x0a, 0x0a], a53)
463
464 a50.set([0x50, 0x50, 0x0a, 0x0a])
465 a51.set(a5)
466 assertArrayPrefix([0x50, 0x0a, 0x0a, 0x0a], a50)
467
468 a50.set([0x50, 0x50, 0x0a, 0x0a])
469 a52.set(a5)
470 assertArrayPrefix([0x50, 0x50, 0x0a, 0x0a], a50)
471
472 a50.set([0x50, 0x50, 0x0a, 0x0a])
473 a53.set(a5)
474 assertArrayPrefix([0x50, 0x50, 0x50, 0x0a], a50)
475
476 a50.set([0x50, 0x51, 0x0a, 0x0b])
477 a5.set(a51)
478 assertArrayPrefix([0x0050, 0x0051], a5)
479
480 a50.set([0x50, 0x51, 0x0a, 0x0b])
481 a5.set(a52)
482 assertArrayPrefix([0x0051, 0x000a], a5)
483
484 a50.set([0x50, 0x51, 0x0a, 0x0b])
485 a5.set(a53)
486 assertArrayPrefix([0x000a, 0x000b], a5)
487
488 // Mixed types of same size.
489 var a61 = new Float32Array([1.2, 12.3])
490 var a62 = new Int32Array(2)
491 a62.set(a61)
492 assertArrayPrefix([1, 12], a62)
493 a61.set(a62)
494 assertArrayPrefix([1, 12], a61)
495
496 // Invalid source
497 var a = new Uint16Array(50);
498 var expected = [];
499 for (i = 0; i < 50; i++) {
500 a[i] = i;
501 expected.push(i);
502 }
503 a.set({});
504 // Rhino throws regular Error in this case, not TypeError
505 assertArrayPrefix(expected, a);
506 assertThrows(function() { a.set.call({}) });
507 assertThrows(function() { a.set.call([]) });
508
509 assertThrows(function() { a.set(0); });
510 assertThrows(function() { a.set(0, 1); });
511 }
512
513 TestTypedArraySet();
514
515 function TestTypedArraysWithIllegalIndices() {
516 var a = new Int32Array(100);
517
518 a[-10] = 10;
519 assertEquals(undefined, a[-10]);
520 a["-10"] = 10;
521 assertEquals(undefined, a["-10"]);
522
523 var s = " -10";
524 a[s] = 10;
525 assertEquals(10, a[s]);
526 var s1 = " -10 ";
527 a[s] = 10;
528 assertEquals(10, a[s]);
529
530 a["-1e2"] = 10;
531 assertEquals(10, a["-1e2"]);
532 assertEquals(undefined, a[-1e2]);
533
534 /* Rhino: Seems to think that "-0" is a real index. Not going to change that here.
535 a["-0"] = 256;
536 var s2 = " -0";
537 a[s2] = 255;
538 assertEquals(undefined, a["-0"]);
539 assertEquals(255, a[s2]);
540 assertEquals(0, a[-0]);
541 */
542
543 /* Chromium bug: 424619
544 * a[-Infinity] = 50;
545 * assertEquals(undefined, a[-Infinity]);
546 */
547 /* Rhino: Seems to think that 1.5 is a real index. Not going to change that here.
548 a[1.5] = 10;
549 assertEquals(undefined, a[1.5]);
550 var nan = Math.sqrt(-1);
551 a[nan] = 5;
552 assertEquals(5, a[nan]);
553 */
554
555 var x = 0;
556 var y = -0;
557 assertEquals(Infinity, 1/x);
558 assertEquals(-Infinity, 1/y);
559 a[x] = 5;
560 a[y] = 27;
561 assertEquals(27, a[x]);
562 assertEquals(27, a[y]);
563 }
564
565 TestTypedArraysWithIllegalIndices();
566
567 function TestTypedArraysWithIllegalIndicesStrict() {
568 'use strict';
569 var a = new Int32Array(100);
570
571 a[-10] = 10;
572 assertEquals(undefined, a[-10]);
573 a["-10"] = 10;
574 assertEquals(undefined, a["-10"]);
575
576 var s = " -10";
577 a[s] = 10;
578 assertEquals(10, a[s]);
579 var s1 = " -10 ";
580 a[s] = 10;
581 assertEquals(10, a[s]);
582
583 a["-1e2"] = 10;
584 assertEquals(10, a["-1e2"]);
585 assertEquals(undefined, a[-1e2]);
586
587 /* Rhino: Seems to think that "-0" is a real index. Not going to change that here.
588 a["-0"] = 256;
589 var s2 = " -0";
590 a[s2] = 255;
591 assertEquals(undefined, a["-0"]);
592 assertEquals(255, a[s2]);
593 assertEquals(0, a[-0]);
594 */
595
596 /* Chromium bug: 424619
597 * a[-Infinity] = 50;
598 * assertEquals(undefined, a[-Infinity]);
599 */
600 /* Rhino: Seems to think that 1.5 is a real index. Not going to change that here.
601 a[1.5] = 10;
602 assertEquals(undefined, a[1.5]);
603 var nan = Math.sqrt(-1);
604 a[nan] = 5;
605 assertEquals(5, a[nan]);
606 */
607
608 var x = 0;
609 var y = -0;
610 assertEquals(Infinity, 1/x);
611 assertEquals(-Infinity, 1/y);
612 a[x] = 5;
613 a[y] = 27;
614 assertEquals(27, a[x]);
615 assertEquals(27, a[y]);
616 }
617
618 TestTypedArraysWithIllegalIndicesStrict();
619
620 // DataView
621 function TestDataViewConstructor() {
622 var ab = new ArrayBuffer(256);
623
624 var d1 = new DataView(ab, 1, 255);
625 assertTrue(ArrayBuffer.isView(d1));
626 assertSame(ab, d1.buffer);
627 assertSame(1, d1.byteOffset);
628 assertSame(255, d1.byteLength);
629
630 var d2 = new DataView(ab, 2);
631 assertSame(ab, d2.buffer);
632 assertSame(2, d2.byteOffset);
633 assertSame(254, d2.byteLength);
634
635 var d3 = new DataView(ab);
636 assertSame(ab, d3.buffer);
637 assertSame(0, d3.byteOffset);
638 assertSame(256, d3.byteLength);
639
640 var d3a = new DataView(ab, 1, 0);
641 assertSame(ab, d3a.buffer);
642 assertSame(1, d3a.byteOffset);
643 assertSame(0, d3a.byteLength);
644
645 var d3b = new DataView(ab, 256, 0);
646 assertSame(ab, d3b.buffer);
647 assertSame(256, d3b.byteOffset);
648 assertSame(0, d3b.byteLength);
649
650 var d3c = new DataView(ab, 256);
651 assertSame(ab, d3c.buffer);
652 assertSame(256, d3c.byteOffset);
653 assertSame(0, d3c.byteLength);
654
655 var d4 = new DataView(ab, 1, 3.1415926);
656 assertSame(ab, d4.buffer);
657 assertSame(1, d4.byteOffset);
658 assertSame(3, d4.byteLength);
659
660
661 // error cases
662 assertThrows(function() { new DataView(ab, -1); }, RangeError);
663 assertThrows(function() { new DataView(ab, 1, -1); }, RangeError);
664 assertThrows(function() { new DataView(); }, TypeError);
665 assertThrows(function() { new DataView([]); }, TypeError);
666 assertThrows(function() { new DataView(ab, 257); }, RangeError);
667 assertThrows(function() { new DataView(ab, 1, 1024); }, RangeError);
668 }
669
670 TestDataViewConstructor();
671
672 /*
673 * Rhino: NO getOwnPropertyDescriptor yet
674 function TestDataViewPropertyTypeChecks() {
675 var a = new DataView(new ArrayBuffer(10));
676 function CheckProperty(name) {
677 var d = Object.getOwnPropertyDescriptor(DataView.prototype, name);
678 var o = {}
679 assertThrows(function() {d.get.call(o);}, TypeError);
680 d.get.call(a); // shouldn't throw
681 }
682
683 CheckProperty("buffer");
684 CheckProperty("byteOffset");
685 CheckProperty("byteLength");
686 }
687
688
689 TestDataViewPropertyTypeChecks();
690 */
691
692 function TestDataViewToStringTag() {
693 var a = new DataView(new ArrayBuffer(10));
694 assertEquals("[object DataView]", Object.prototype.toString.call(a));
695 var desc = Object.getOwnPropertyDescriptor(
696 DataView.prototype, Symbol.toStringTag);
697 assertTrue(desc.configurable);
698 assertFalse(desc.enumerable);
699 assertFalse(desc.writable);
700 assertEquals("DataView", desc.value);
701 }
702
703
704 // General tests for properties
705
706 /*
707 * Rhino: No Enumerable yet
708 // Test property attribute [[Enumerable]]
709 function TestEnumerable(func, obj) {
710 function props(x) {
711 var array = [];
712 for (var p in x) array.push(p);
713 return array.sort();
714 }
715 assertArrayEquals([], props(func));
716 assertArrayEquals([], props(func.prototype));
717 if (obj)
718 assertArrayEquals([], props(obj));
719 }
720 TestEnumerable(ArrayBuffer, new ArrayBuffer());
721 for(i = 0; i < typedArrayConstructors.length; i++) {
722 TestEnumerable(typedArrayConstructors[i]);
723 }
724 TestEnumerable(DataView, new DataView(new ArrayBuffer()));
725 */
726
727 // Test arbitrary properties on ArrayBuffer
728 function TestArbitrary(m) {
729 function TestProperty(map, property, value) {
730 map[property] = value;
731 assertEquals(value, map[property]);
732 }
733 for (var i = 0; i < 20; i++) {
734 TestProperty(m, 'key' + i, 'val' + i);
735 TestProperty(m, 'foo' + i, 'bar' + i);
736 }
737 }
738 TestArbitrary(new ArrayBuffer(256));
739 for(i = 0; i < typedArrayConstructors.length; i++) {
740 TestArbitrary(new typedArrayConstructors[i](10));
741 }
742 TestArbitrary(new DataView(new ArrayBuffer(256)));
743
744
745 // Test direct constructor call
746 /*
747 * Rhino: Not making this check yet
748 assertThrows(function() { ArrayBuffer(); }, TypeError);
749 assertThrows(function() { DataView(new ArrayBuffer()); }, TypeError);
750 */
751
752 "success";