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

Side by Side Diff: test/mjsunit/harmony/typedarrays.js

Issue 955963002: Add version macros. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Implement TypedArray.slice(). Created 5 years, 7 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
« no previous file with comments | « src/typedarray.js ('k') | no next file » | 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
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
62 62
63 function TestByteLengthNotWritable() { 63 function TestByteLengthNotWritable() {
64 var ab = new ArrayBuffer(1024); 64 var ab = new ArrayBuffer(1024);
65 assertSame(1024, ab.byteLength); 65 assertSame(1024, ab.byteLength);
66 66
67 assertThrows(function() { "use strict"; ab.byteLength = 42; }, TypeError); 67 assertThrows(function() { "use strict"; ab.byteLength = 42; }, TypeError);
68 } 68 }
69 69
70 TestByteLengthNotWritable(); 70 TestByteLengthNotWritable();
71 71
72 function TestSlice(expectedResultLen, initialLen, start, end) { 72 function TestArrayBufferSlice() {
73 var ab = new ArrayBuffer(initialLen); 73 function TestSlice(expectedResultLen, initialLen, start, end) {
74 var a1 = new Uint8Array(ab); 74 var ab = new ArrayBuffer(initialLen);
75 for (var i = 0; i < a1.length; i++) { 75 var a1 = new Uint8Array(ab);
76 a1[i] = 0xCA; 76 for (var i = 0; i < a1.length; i++) {
77 a1[i] = 0xCA;
78 }
79 var slice = ab.slice(start, end);
80 assertSame(expectedResultLen, slice.byteLength);
81 var a2 = new Uint8Array(slice);
82 for (var i = 0; i < a2.length; i++) {
83 assertSame(0xCA, a2[i]);
84 }
77 } 85 }
78 var slice = ab.slice(start, end);
79 assertSame(expectedResultLen, slice.byteLength);
80 var a2 = new Uint8Array(slice);
81 for (var i = 0; i < a2.length; i++) {
82 assertSame(0xCA, a2[i]);
83 }
84 }
85 86
86 function TestArrayBufferSlice() {
87 var ab = new ArrayBuffer(1024); 87 var ab = new ArrayBuffer(1024);
88 var ab1 = ab.slice(512, 1024); 88 var ab1 = ab.slice(512, 1024);
89 assertSame(512, ab1.byteLength); 89 assertSame(512, ab1.byteLength);
90 90
91 TestSlice(512, 1024, 512, 1024); 91 TestSlice(512, 1024, 512, 1024);
92 TestSlice(512, 1024, 512); 92 TestSlice(512, 1024, 512);
93 93
94 TestSlice(0, 0, 1, 20); 94 TestSlice(0, 0, 1, 20);
95 TestSlice(100, 100, 0, 100); 95 TestSlice(100, 100, 0, 100);
96 TestSlice(100, 100, 0, 1000); 96 TestSlice(100, 100, 0, 1000);
(...skipping 15 matching lines...) Expand all
112 TestSlice(10, 100, 0.96, 10.01); 112 TestSlice(10, 100, 0.96, 10.01);
113 TestSlice(10, 100, 0.01, 10.01); 113 TestSlice(10, 100, 0.01, 10.01);
114 TestSlice(10, 100, 0.01, 10.96); 114 TestSlice(10, 100, 0.01, 10.96);
115 115
116 TestSlice(10, 100, 90); 116 TestSlice(10, 100, 90);
117 TestSlice(10, 100, -10); 117 TestSlice(10, 100, -10);
118 } 118 }
119 119
120 TestArrayBufferSlice(); 120 TestArrayBufferSlice();
121 121
122 function TestTypedArraySlice() {
123 function TestSlice(expectedResultLen, initialLen, start, end) {
124 var a1 = new Uint32Array(initialLen);
125 for (var i = 0; i < a1.length; i++) {
126 a1[i] = 0x12345678;
127 }
128 var slice = a1.slice(start, end);
129 assertSame(expectedResultLen, slice.length);
130 var a2 = new Uint32Array(slice);
131 for (var i = 0; i < a2.length; i++) {
132 assertSame(0x12345678, a2[i]);
133 }
134 }
135
136 var ab = new Uint32Array(1024);
137 var ab1 = ab.slice(512, 1024);
138 assertSame(512, ab1.length);
139
140 TestSlice(512, 1024, 512, 1024);
141 TestSlice(512, 1024, 512);
142
143 TestSlice(0, 0, 1, 20);
144 TestSlice(100, 100, 0, 100);
145 TestSlice(100, 100, 0, 1000);
146
147 TestSlice(0, 100, 5, 1);
148
149 TestSlice(1, 100, -11, -10);
150 TestSlice(9, 100, -10, 99);
151 TestSlice(0, 100, -10, 80);
152 TestSlice(10, 100, 80, -10);
153
154 TestSlice(10, 100, 90, "100");
155 TestSlice(10, 100, "90", "100");
156
157 TestSlice(0, 100, 90, "abc");
158 TestSlice(10, 100, "abc", 10);
159
160 TestSlice(10, 100, 0.96, 10.96);
161 TestSlice(10, 100, 0.96, 10.01);
162 TestSlice(10, 100, 0.01, 10.01);
163 TestSlice(10, 100, 0.01, 10.96);
164
165 TestSlice(10, 100, 90);
166 TestSlice(10, 100, -10);
167 }
168
169 TestTypedArraySlice();
170
122 // Typed arrays 171 // Typed arrays
123 172
124 function TestTypedArray(constr, elementSize, typicalElement) { 173 function TestTypedArray(constr, elementSize, typicalElement) {
125 assertSame(elementSize, constr.BYTES_PER_ELEMENT); 174 assertSame(elementSize, constr.BYTES_PER_ELEMENT);
126 175
127 var ab = new ArrayBuffer(256*elementSize); 176 var ab = new ArrayBuffer(256*elementSize);
128 177
129 var a0 = new constr(30); 178 var a0 = new constr(30);
130 assertEquals("[object " + constr.name + "]", 179 assertEquals("[object " + constr.name + "]",
131 Object.prototype.toString.call(a0)); 180 Object.prototype.toString.call(a0));
(...skipping 580 matching lines...) Expand 10 before | Expand all | Expand 10 after
712 TestArbitrary(new ArrayBuffer(256)); 761 TestArbitrary(new ArrayBuffer(256));
713 for(i = 0; i < typedArrayConstructors.length; i++) { 762 for(i = 0; i < typedArrayConstructors.length; i++) {
714 TestArbitrary(new typedArrayConstructors[i](10)); 763 TestArbitrary(new typedArrayConstructors[i](10));
715 } 764 }
716 TestArbitrary(new DataView(new ArrayBuffer(256))); 765 TestArbitrary(new DataView(new ArrayBuffer(256)));
717 766
718 767
719 // Test direct constructor call 768 // Test direct constructor call
720 assertThrows(function() { ArrayBuffer(); }, TypeError); 769 assertThrows(function() { ArrayBuffer(); }, TypeError);
721 assertThrows(function() { DataView(new ArrayBuffer()); }, TypeError); 770 assertThrows(function() { DataView(new ArrayBuffer()); }, TypeError);
OLDNEW
« no previous file with comments | « src/typedarray.js ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698