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

Side by Side Diff: test/mjsunit/harmony/typedarrays.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/harmony/generators-iteration.js ('k') | test/mjsunit/manual-parallel-recompile.js » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2013 the V8 project authors. All rights reserved. 1 // Copyright 2013 the V8 project authors. All rights reserved.
2 // Redistribution and use in source and binary forms, with or without 2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions are 3 // modification, are permitted provided that the following conditions are
4 // met: 4 // met:
5 // 5 //
6 // * Redistributions of source code must retain the above copyright 6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer. 7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above 8 // * Redistributions in binary form must reproduce the above
9 // copyright notice, this list of conditions and the following 9 // copyright notice, this list of conditions and the following
10 // disclaimer in the documentation and/or other materials provided 10 // disclaimer in the documentation and/or other materials provided
11 // with the distribution. 11 // with the distribution.
12 // * Neither the name of Google Inc. nor the names of its 12 // * Neither the name of Google Inc. nor the names of its
13 // contributors may be used to endorse or promote products derived 13 // contributors may be used to endorse or promote products derived
14 // from this software without specific prior written permission. 14 // from this software without specific prior written permission.
15 // 15 //
16 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 16 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 17 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 18 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 19 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
20 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 20 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 21 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 22 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 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. 26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 27
28 // Flags: --harmony-typed-arrays
29
30 // ArrayBuffer 28 // ArrayBuffer
31 29
32 function TestByteLength(param, expectedByteLength) { 30 function TestByteLength(param, expectedByteLength) {
33 var ab = new ArrayBuffer(param); 31 var ab = new ArrayBuffer(param);
34 assertSame(expectedByteLength, ab.byteLength); 32 assertSame(expectedByteLength, ab.byteLength);
35 } 33 }
36 34
37 function TestArrayBufferCreation() { 35 function TestArrayBufferCreation() {
38 TestByteLength(1, 1); 36 TestByteLength(1, 1);
39 TestByteLength(256, 256); 37 TestByteLength(256, 256);
40 TestByteLength(-10, 0);
41 TestByteLength(2.567, 2); 38 TestByteLength(2.567, 2);
42 TestByteLength(-2.567, 0);
43 39
44 TestByteLength("abc", 0); 40 TestByteLength("abc", 0);
45 41
46 TestByteLength(0, 0); 42 TestByteLength(0, 0);
47 43
44 assertThrows(function() { new ArrayBuffer(-10); }, RangeError);
45 assertThrows(function() { new ArrayBuffer(-2.567); }, RangeError);
46
48 /* TODO[dslomov]: Reenable the test 47 /* TODO[dslomov]: Reenable the test
49 assertThrows(function() { 48 assertThrows(function() {
50 var ab1 = new ArrayBuffer(0xFFFFFFFFFFFF) 49 var ab1 = new ArrayBuffer(0xFFFFFFFFFFFF)
51 }, RangeError); 50 }, RangeError);
52 */ 51 */
53 52
54 var ab = new ArrayBuffer(); 53 var ab = new ArrayBuffer();
55 assertSame(0, ab.byteLength); 54 assertSame(0, ab.byteLength);
56 } 55 }
57 56
(...skipping 26 matching lines...) Expand all
84 var ab = new ArrayBuffer(1024); 83 var ab = new ArrayBuffer(1024);
85 var ab1 = ab.slice(512, 1024); 84 var ab1 = ab.slice(512, 1024);
86 assertSame(512, ab1.byteLength); 85 assertSame(512, ab1.byteLength);
87 86
88 TestSlice(512, 1024, 512, 1024); 87 TestSlice(512, 1024, 512, 1024);
89 TestSlice(512, 1024, 512); 88 TestSlice(512, 1024, 512);
90 89
91 TestSlice(0, 0, 1, 20); 90 TestSlice(0, 0, 1, 20);
92 TestSlice(100, 100, 0, 100); 91 TestSlice(100, 100, 0, 100);
93 TestSlice(100, 100, 0, 1000); 92 TestSlice(100, 100, 0, 1000);
93
94 TestSlice(0, 100, 5, 1); 94 TestSlice(0, 100, 5, 1);
95 95
96 TestSlice(1, 100, -11, -10); 96 TestSlice(1, 100, -11, -10);
97 TestSlice(9, 100, -10, 99); 97 TestSlice(9, 100, -10, 99);
98 TestSlice(0, 100, -10, 80); 98 TestSlice(0, 100, -10, 80);
99 TestSlice(10, 100, 80, -10); 99 TestSlice(10, 100, 80, -10);
100 100
101 TestSlice(10, 100, 90, "100"); 101 TestSlice(10, 100, 90, "100");
102 TestSlice(10, 100, "90", "100"); 102 TestSlice(10, 100, "90", "100");
103 103
104 TestSlice(0, 100, 90, "abc"); 104 TestSlice(0, 100, 90, "abc");
105 TestSlice(10, 100, "abc", 10); 105 TestSlice(10, 100, "abc", 10);
106 106
107 TestSlice(10, 100, 0.96, 10.96); 107 TestSlice(10, 100, 0.96, 10.96);
108 TestSlice(10, 100, 0.96, 10.01); 108 TestSlice(10, 100, 0.96, 10.01);
109 TestSlice(10, 100, 0.01, 10.01); 109 TestSlice(10, 100, 0.01, 10.01);
110 TestSlice(10, 100, 0.01, 10.96); 110 TestSlice(10, 100, 0.01, 10.96);
111 111
112
113 TestSlice(10, 100, 90); 112 TestSlice(10, 100, 90);
114 TestSlice(10, 100, -10); 113 TestSlice(10, 100, -10);
115 } 114 }
116 115
117 TestArrayBufferSlice(); 116 TestArrayBufferSlice();
118 117
119 // Typed arrays 118 // Typed arrays
120 119
121 function TestTypedArray(proto, elementSize, typicalElement) { 120 function TestTypedArray(proto, elementSize, typicalElement) {
122 var ab = new ArrayBuffer(256*elementSize); 121 var ab = new ArrayBuffer(256*elementSize);
(...skipping 327 matching lines...) Expand 10 before | Expand all | Expand 10 after
450 // Invalid source 449 // Invalid source
451 var a = new Uint16Array(50); 450 var a = new Uint16Array(50);
452 assertThrows(function() { a.set(0) }, TypeError); 451 assertThrows(function() { a.set(0) }, TypeError);
453 assertThrows(function() { a.set({}) }, TypeError); 452 assertThrows(function() { a.set({}) }, TypeError);
454 assertThrows(function() { a.set.call({}) }, TypeError); 453 assertThrows(function() { a.set.call({}) }, TypeError);
455 assertThrows(function() { a.set.call([]) }, TypeError); 454 assertThrows(function() { a.set.call([]) }, TypeError);
456 } 455 }
457 456
458 TestTypedArraySet(); 457 TestTypedArraySet();
459 458
459 // DataView
460 function TestDataViewConstructor() {
461 var ab = new ArrayBuffer(256);
462
463 var d1 = new DataView(ab, 1, 255);
464 assertSame(ab, d1.buffer);
465 assertSame(1, d1.byteOffset);
466 assertSame(255, d1.byteLength);
467
468 var d2 = new DataView(ab, 2);
469 assertSame(ab, d2.buffer);
470 assertSame(2, d2.byteOffset);
471 assertSame(254, d2.byteLength);
472
473 var d3 = new DataView(ab);
474 assertSame(ab, d3.buffer);
475 assertSame(0, d3.byteOffset);
476 assertSame(256, d3.byteLength);
477
478 var d3a = new DataView(ab, 1, 0);
479 assertSame(ab, d3a.buffer);
480 assertSame(1, d3a.byteOffset);
481 assertSame(0, d3a.byteLength);
482
483 var d3b = new DataView(ab, 256, 0);
484 assertSame(ab, d3b.buffer);
485 assertSame(256, d3b.byteOffset);
486 assertSame(0, d3b.byteLength);
487
488 var d3c = new DataView(ab, 256);
489 assertSame(ab, d3c.buffer);
490 assertSame(256, d3c.byteOffset);
491 assertSame(0, d3c.byteLength);
492
493 var d4 = new DataView(ab, 1, 3.1415926);
494 assertSame(ab, d4.buffer);
495 assertSame(1, d4.byteOffset);
496 assertSame(3, d4.byteLength);
497
498
499 // error cases
500 assertThrows(function() { new DataView(ab, -1); }, RangeError);
501 assertThrows(function() { new DataView(ab, 1, -1); }, RangeError);
502 assertThrows(function() { new DataView(); }, TypeError);
503 assertThrows(function() { new DataView([]); }, TypeError);
504 assertThrows(function() { new DataView(ab, 257); }, RangeError);
505 assertThrows(function() { new DataView(ab, 1, 1024); }, RangeError);
506 }
507
508 TestDataViewConstructor();
509
510 function TestDataViewPropertyTypeChecks() {
511 var a = new DataView(new ArrayBuffer(10));
512 function CheckProperty(name) {
513 var d = Object.getOwnPropertyDescriptor(DataView.prototype, name);
514 var o = {}
515 assertThrows(function() {d.get.call(o);}, TypeError);
516 d.get.call(a); // shouldn't throw
517 }
518
519 CheckProperty("buffer");
520 CheckProperty("byteOffset");
521 CheckProperty("byteLength");
522 }
523
524
525 TestDataViewPropertyTypeChecks();
526
460 // General tests for properties 527 // General tests for properties
461 528
462 // Test property attribute [[Enumerable]] 529 // Test property attribute [[Enumerable]]
463 function TestEnumerable(func, obj) { 530 function TestEnumerable(func, obj) {
464 function props(x) { 531 function props(x) {
465 var array = []; 532 var array = [];
466 for (var p in x) array.push(p); 533 for (var p in x) array.push(p);
467 return array.sort(); 534 return array.sort();
468 } 535 }
469 assertArrayEquals([], props(func)); 536 assertArrayEquals([], props(func));
470 assertArrayEquals([], props(func.prototype)); 537 assertArrayEquals([], props(func.prototype));
471 if (obj) 538 if (obj)
472 assertArrayEquals([], props(obj)); 539 assertArrayEquals([], props(obj));
473 } 540 }
474 TestEnumerable(ArrayBuffer, new ArrayBuffer()); 541 TestEnumerable(ArrayBuffer, new ArrayBuffer());
475 for(i = 0; i < typedArrayConstructors.lenght; i++) { 542 for(i = 0; i < typedArrayConstructors.lenght; i++) {
476 TestEnumerable(typedArrayConstructors[i]); 543 TestEnumerable(typedArrayConstructors[i]);
477 } 544 }
545 TestEnumerable(DataView, new DataView(new ArrayBuffer()));
478 546
479 // Test arbitrary properties on ArrayBuffer 547 // Test arbitrary properties on ArrayBuffer
480 function TestArbitrary(m) { 548 function TestArbitrary(m) {
481 function TestProperty(map, property, value) { 549 function TestProperty(map, property, value) {
482 map[property] = value; 550 map[property] = value;
483 assertEquals(value, map[property]); 551 assertEquals(value, map[property]);
484 } 552 }
485 for (var i = 0; i < 20; i++) { 553 for (var i = 0; i < 20; i++) {
486 TestProperty(m, i, 'val' + i); 554 TestProperty(m, i, 'val' + i);
487 TestProperty(m, 'foo' + i, 'bar' + i); 555 TestProperty(m, 'foo' + i, 'bar' + i);
488 } 556 }
489 } 557 }
490 TestArbitrary(new ArrayBuffer(256)); 558 TestArbitrary(new ArrayBuffer(256));
491 for(i = 0; i < typedArrayConstructors.lenght; i++) { 559 for(i = 0; i < typedArrayConstructors.lenght; i++) {
492 TestArbitary(new typedArrayConstructors[i](10)); 560 TestArbitary(new typedArrayConstructors[i](10));
493 } 561 }
494 562 TestArbitrary(new DataView(new ArrayBuffer(256)));
495 563
496 564
497 // Test direct constructor call 565 // Test direct constructor call
498 assertTrue(ArrayBuffer() instanceof ArrayBuffer); 566 assertThrows(function() { ArrayBuffer(); }, TypeError);
567 assertThrows(function() { DataView(new ArrayBuffer()); }, TypeError);
OLDNEW
« no previous file with comments | « test/mjsunit/harmony/generators-iteration.js ('k') | test/mjsunit/manual-parallel-recompile.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698