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

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

Issue 18313007: Change DataView accessors behavior for insufficient args. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Fixed bug Created 7 years, 5 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 | « 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 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
55 return 4; 55 return 4;
56 case "Float64": 56 case "Float64":
57 return 8; 57 return 8;
58 default: 58 default:
59 assertUnreachable(func); 59 assertUnreachable(func);
60 } 60 }
61 } 61 }
62 62
63 function checkGet(func, index, expected, littleEndian) { 63 function checkGet(func, index, expected, littleEndian) {
64 function doGet() { 64 function doGet() {
65 return view["get" + func](index, littleEndian); 65 if (littleEndian != undefined)
66 return view["get" + func](index, littleEndian);
67 else
68 return view["get" + func](index);
66 } 69 }
67 if (index >=0 && index + getElementSize(func) - 1 < view.byteLength) 70 if (index >=0 && index + getElementSize(func) - 1 < view.byteLength)
68 assertSame(expected, doGet()); 71 assertSame(expected, doGet());
69 else 72 else
70 assertThrows(doGet, RangeError); 73 assertThrows(doGet, RangeError);
71 } 74 }
72 75
73 function checkSet(func, index, value, littleEndian) { 76 function checkSet(func, index, value, littleEndian) {
74 function doSet() { 77 function doSet() {
75 view["set" + func](index, value, littleEndian); 78 if (littleEndian != undefined)
79 view["set" + func](index, value, littleEndian);
80 else
81 view["set" + func](index, value);
76 } 82 }
77 if (index >= 0 && 83 if (index >= 0 &&
78 index + getElementSize(func) - 1 < view.byteLength) { 84 index + getElementSize(func) - 1 < view.byteLength) {
79 assertSame(undefined, doSet()); 85 assertSame(undefined, doSet());
80 checkGet(func, index, value, littleEndian); 86 checkGet(func, index, value, littleEndian);
81 } else { 87 } else {
82 assertThrows(doSet, RangeError); 88 assertThrows(doSet, RangeError);
83 } 89 }
84 } 90 }
85 91
(...skipping 12 matching lines...) Expand all
98 arrayBuffer = (new Uint8Array(paddingArray.concat(array))).buffer; 104 arrayBuffer = (new Uint8Array(paddingArray.concat(array))).buffer;
99 view = new DataView(arrayBuffer, viewStart, viewLength); 105 view = new DataView(arrayBuffer, viewStart, viewLength);
100 if (!littleEndian) 106 if (!littleEndian)
101 array.reverse(); // restore the array. 107 array.reverse(); // restore the array.
102 } 108 }
103 109
104 function runIntegerTestCases(isTestingGet, array, start, length) { 110 function runIntegerTestCases(isTestingGet, array, start, length) {
105 createDataView(array, 0, true, start, length); 111 createDataView(array, 0, true, start, length);
106 112
107 test(isTestingGet, "Int8", 0, 0); 113 test(isTestingGet, "Int8", 0, 0);
114 test(isTestingGet, "Int8", undefined, 0);
108 test(isTestingGet, "Int8", 8, -128); 115 test(isTestingGet, "Int8", 8, -128);
109 test(isTestingGet, "Int8", 15, -1); 116 test(isTestingGet, "Int8", 15, -1);
110 117
111 test(isTestingGet, "Uint8", 0, 0); 118 test(isTestingGet, "Uint8", 0, 0);
119 test(isTestingGet, "Uint8", undefined, 0);
112 test(isTestingGet, "Uint8", 8, 128); 120 test(isTestingGet, "Uint8", 8, 128);
113 test(isTestingGet, "Uint8", 15, 255); 121 test(isTestingGet, "Uint8", 15, 255);
114 122
115 // Little endian. 123 // Little endian.
116 test(isTestingGet, "Int16", 0, 256, true); 124 test(isTestingGet, "Int16", 0, 256, true);
125 test(isTestingGet, "Int16", undefined, 256, true);
117 test(isTestingGet, "Int16", 5, 26213, true); 126 test(isTestingGet, "Int16", 5, 26213, true);
118 test(isTestingGet, "Int16", 9, -32127, true); 127 test(isTestingGet, "Int16", 9, -32127, true);
119 test(isTestingGet, "Int16", 14, -2, true); 128 test(isTestingGet, "Int16", 14, -2, true);
120 129
121 // Big endian. 130 // Big endian.
122 test(isTestingGet, "Int16", 0, 1); 131 test(isTestingGet, "Int16", 0, 1);
132 test(isTestingGet, "Int16", undefined, 1);
123 test(isTestingGet, "Int16", 5, 25958); 133 test(isTestingGet, "Int16", 5, 25958);
124 test(isTestingGet, "Int16", 9, -32382); 134 test(isTestingGet, "Int16", 9, -32382);
125 test(isTestingGet, "Int16", 14, -257); 135 test(isTestingGet, "Int16", 14, -257);
126 136
127 // Little endian. 137 // Little endian.
128 test(isTestingGet, "Uint16", 0, 256, true); 138 test(isTestingGet, "Uint16", 0, 256, true);
139 test(isTestingGet, "Uint16", undefined, 256, true);
129 test(isTestingGet, "Uint16", 5, 26213, true); 140 test(isTestingGet, "Uint16", 5, 26213, true);
130 test(isTestingGet, "Uint16", 9, 33409, true); 141 test(isTestingGet, "Uint16", 9, 33409, true);
131 test(isTestingGet, "Uint16", 14, 65534, true); 142 test(isTestingGet, "Uint16", 14, 65534, true);
132 143
133 // Big endian. 144 // Big endian.
134 test(isTestingGet, "Uint16", 0, 1); 145 test(isTestingGet, "Uint16", 0, 1);
146 test(isTestingGet, "Uint16", undefined, 1);
135 test(isTestingGet, "Uint16", 5, 25958); 147 test(isTestingGet, "Uint16", 5, 25958);
136 test(isTestingGet, "Uint16", 9, 33154); 148 test(isTestingGet, "Uint16", 9, 33154);
137 test(isTestingGet, "Uint16", 14, 65279); 149 test(isTestingGet, "Uint16", 14, 65279);
138 150
139 // Little endian. 151 // Little endian.
140 test(isTestingGet, "Int32", 0, 50462976, true); 152 test(isTestingGet, "Int32", 0, 50462976, true);
153 test(isTestingGet, "Int32", undefined, 50462976, true);
141 test(isTestingGet, "Int32", 3, 1717920771, true); 154 test(isTestingGet, "Int32", 3, 1717920771, true);
142 test(isTestingGet, "Int32", 6, -2122291354, true); 155 test(isTestingGet, "Int32", 6, -2122291354, true);
143 test(isTestingGet, "Int32", 9, -58490239, true); 156 test(isTestingGet, "Int32", 9, -58490239, true);
144 test(isTestingGet, "Int32", 12,-66052, true); 157 test(isTestingGet, "Int32", 12,-66052, true);
145 158
146 // Big endian. 159 // Big endian.
147 test(isTestingGet, "Int32", 0, 66051); 160 test(isTestingGet, "Int32", 0, 66051);
161 test(isTestingGet, "Int32", undefined, 66051);
148 test(isTestingGet, "Int32", 3, 56911206); 162 test(isTestingGet, "Int32", 3, 56911206);
149 test(isTestingGet, "Int32", 6, 1718059137); 163 test(isTestingGet, "Int32", 6, 1718059137);
150 test(isTestingGet, "Int32", 9, -2122152964); 164 test(isTestingGet, "Int32", 9, -2122152964);
151 test(isTestingGet, "Int32", 12, -50462977); 165 test(isTestingGet, "Int32", 12, -50462977);
152 166
153 // Little endian. 167 // Little endian.
154 test(isTestingGet, "Uint32", 0, 50462976, true); 168 test(isTestingGet, "Uint32", 0, 50462976, true);
169 test(isTestingGet, "Uint32", undefined, 50462976, true);
155 test(isTestingGet, "Uint32", 3, 1717920771, true); 170 test(isTestingGet, "Uint32", 3, 1717920771, true);
156 test(isTestingGet, "Uint32", 6, 2172675942, true); 171 test(isTestingGet, "Uint32", 6, 2172675942, true);
157 test(isTestingGet, "Uint32", 9, 4236477057, true); 172 test(isTestingGet, "Uint32", 9, 4236477057, true);
158 test(isTestingGet, "Uint32", 12,4294901244, true); 173 test(isTestingGet, "Uint32", 12,4294901244, true);
159 174
160 // Big endian. 175 // Big endian.
161 test(isTestingGet, "Uint32", 0, 66051); 176 test(isTestingGet, "Uint32", 0, 66051);
177 test(isTestingGet, "Uint32", undefined, 66051);
162 test(isTestingGet, "Uint32", 3, 56911206); 178 test(isTestingGet, "Uint32", 3, 56911206);
163 test(isTestingGet, "Uint32", 6, 1718059137); 179 test(isTestingGet, "Uint32", 6, 1718059137);
164 test(isTestingGet, "Uint32", 9, 2172814332); 180 test(isTestingGet, "Uint32", 9, 2172814332);
165 test(isTestingGet, "Uint32", 12, 4244504319); 181 test(isTestingGet, "Uint32", 12, 4244504319);
166 } 182 }
167 183
168 function testFloat(isTestingGet, func, array, start, expected) { 184 function testFloat(isTestingGet, func, array, start, expected) {
169 // Little endian. 185 // Little endian.
170 createDataView(array, 0, true, start); 186 createDataView(array, 0, true, start);
171 test(isTestingGet, func, 0, expected, true); 187 test(isTestingGet, func, 0, expected, true);
188 test(isTestingGet, func, undefined, expected, true);
172 createDataView(array, 3, true, start); 189 createDataView(array, 3, true, start);
173 test(isTestingGet, func, 3, expected, true); 190 test(isTestingGet, func, 3, expected, true);
174 createDataView(array, 7, true, start); 191 createDataView(array, 7, true, start);
175 test(isTestingGet, func, 7, expected, true); 192 test(isTestingGet, func, 7, expected, true);
176 createDataView(array, 10, true, start); 193 createDataView(array, 10, true, start);
177 test(isTestingGet, func, 10, expected, true); 194 test(isTestingGet, func, 10, expected, true);
178 195
179 // Big endian. 196 // Big endian.
180 createDataView(array, 0, false); 197 createDataView(array, 0, false);
181 test(isTestingGet, func, 0, expected, false); 198 test(isTestingGet, func, 0, expected, false);
199 test(isTestingGet, func, undefined, expected, false);
182 createDataView(array, 3, false); 200 createDataView(array, 3, false);
183 test(isTestingGet, func, 3, expected, false); 201 test(isTestingGet, func, 3, expected, false);
184 createDataView(array, 7, false); 202 createDataView(array, 7, false);
185 test(isTestingGet, func, 7, expected, false); 203 test(isTestingGet, func, 7, expected, false);
186 createDataView(array, 10, false); 204 createDataView(array, 10, false);
187 test(isTestingGet, func, 10, expected, false); 205 test(isTestingGet, func, 10, expected, false);
188 } 206 }
189 207
190 function runFloatTestCases(isTestingGet, start) { 208 function runFloatTestCases(isTestingGet, start) {
191 testFloat(isTestingGet, "Float32", 209 testFloat(isTestingGet, "Float32",
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
279 297
280 } 298 }
281 299
282 TestGetters(); 300 TestGetters();
283 TestSetters(); 301 TestSetters();
284 302
285 function TestGeneralAccessors() { 303 function TestGeneralAccessors() {
286 var a = new DataView(new ArrayBuffer(256)); 304 var a = new DataView(new ArrayBuffer(256));
287 function CheckAccessor(name) { 305 function CheckAccessor(name) {
288 var f = a[name]; 306 var f = a[name];
307 assertThrows(function() { f(); }, TypeError);
289 f.call(a, 0, 0); // should not throw 308 f.call(a, 0, 0); // should not throw
290 assertThrows(function() { f.call({}, 0, 0); }, TypeError); 309 assertThrows(function() { f.call({}, 0, 0); }, TypeError);
310 assertThrows(function() { f.call(a); }, TypeError);
291 } 311 }
292 CheckAccessor("getUint8"); 312 CheckAccessor("getUint8");
293 CheckAccessor("setUint8"); 313 CheckAccessor("setUint8");
294 CheckAccessor("getInt8"); 314 CheckAccessor("getInt8");
295 CheckAccessor("setInt8"); 315 CheckAccessor("setInt8");
296 CheckAccessor("getUint16"); 316 CheckAccessor("getUint16");
297 CheckAccessor("setUint16"); 317 CheckAccessor("setUint16");
298 CheckAccessor("getInt16"); 318 CheckAccessor("getInt16");
299 CheckAccessor("setInt16"); 319 CheckAccessor("setInt16");
300 CheckAccessor("getUint32"); 320 CheckAccessor("getUint32");
301 CheckAccessor("setUint32"); 321 CheckAccessor("setUint32");
302 CheckAccessor("getInt32"); 322 CheckAccessor("getInt32");
303 CheckAccessor("setInt32"); 323 CheckAccessor("setInt32");
304 CheckAccessor("getFloat32"); 324 CheckAccessor("getFloat32");
305 CheckAccessor("setFloat32"); 325 CheckAccessor("setFloat32");
306 CheckAccessor("getFloat64"); 326 CheckAccessor("getFloat64");
307 CheckAccessor("setFloat64"); 327 CheckAccessor("setFloat64");
308 } 328 }
309 329
310 TestGeneralAccessors(); 330 TestGeneralAccessors();
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