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

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

Issue 18703007: Use corerct conversions for DataView accessors. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: CR feedback 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/runtime.cc ('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 276 matching lines...) Expand 10 before | Expand all | Expand 10 after
287 } 287 }
288 288
289 function TestSetters() { 289 function TestSetters() {
290 runIntegerTestCases(false, initialArray, 0, 16); 290 runIntegerTestCases(false, initialArray, 0, 16);
291 runFloatTestCases(false); 291 runFloatTestCases(false);
292 292
293 runIntegerTestCases(false, initialArray, 3, 2); 293 runIntegerTestCases(false, initialArray, 3, 2);
294 runFloatTestCases(false, 7); 294 runFloatTestCases(false, 7);
295 295
296 runNegativeIndexTests(false); 296 runNegativeIndexTests(false);
297
298 } 297 }
299 298
300 TestGetters(); 299 TestGetters();
301 TestSetters(); 300 TestSetters();
302 301
302 function CheckOutOfRangeInt8(value, expected) {
303 var view = new DataView(new ArrayBuffer(100));
304 assertSame(undefined, view.setInt8(0, value));
305 assertSame(expected, view.getInt8(0));
306 assertSame(undefined, view.setInt8(0, value, true));
307 assertSame(expected, view.getInt8(0, true));
308 }
309
310 function CheckOutOfRangeUint8(value, expected) {
311 var view = new DataView(new ArrayBuffer(100));
312 assertSame(undefined, view.setUint8(0, value));
313 assertSame(expected, view.getUint8(0));
314 assertSame(undefined, view.setUint8(0, value, true));
315 assertSame(expected, view.getUint8(0, true));
316 }
317
318 function CheckOutOfRangeInt16(value, expected) {
319 var view = new DataView(new ArrayBuffer(100));
320 assertSame(undefined, view.setInt16(0, value));
321 assertSame(expected, view.getInt16(0));
322 assertSame(undefined, view.setInt16(0, value, true));
323 assertSame(expected, view.getInt16(0, true));
324 }
325
326 function CheckOutOfRangeUint16(value, expected) {
327 var view = new DataView(new ArrayBuffer(100));
328 assertSame(undefined, view.setUint16(0, value));
329 assertSame(expected, view.getUint16(0));
330 assertSame(undefined, view.setUint16(0, value, true));
331 assertSame(expected, view.getUint16(0, true));
332 }
333
334 function CheckOutOfRangeInt32(value, expected) {
335 var view = new DataView(new ArrayBuffer(100));
336 assertSame(undefined, view.setInt32(0, value));
337 assertSame(expected, view.getInt32(0));
338 assertSame(undefined, view.setInt32(0, value, true));
339 assertSame(expected, view.getInt32(0, true));
340 }
341
342 function CheckOutOfRangeUint32(value, expected) {
343 var view = new DataView(new ArrayBuffer(100));
344 assertSame(undefined, view.setUint32(0, value));
345 assertSame(expected, view.getUint32(0));
346 assertSame(undefined, view.setUint32(0, value, true));
347 assertSame(expected, view.getUint32(0, true));
348 }
349
350 function TestOutOfRange() {
351 CheckOutOfRangeInt8(0x80, -0x80);
352 CheckOutOfRangeInt8(0x1000, 0);
353 CheckOutOfRangeInt8(-0x81, 0x7F);
354
355 CheckOutOfRangeUint8(0x100, 0);
356 CheckOutOfRangeUint8(0x1000, 0);
357 CheckOutOfRangeUint8(-0x80, 0x80);
358 CheckOutOfRangeUint8(-1, 0xFF);
359 CheckOutOfRangeUint8(-0xFF, 1);
360
361 CheckOutOfRangeInt16(0x8000, -0x8000);
362 CheckOutOfRangeInt16(0x10000, 0);
363 CheckOutOfRangeInt16(-0x8001, 0x7FFF);
364
365 CheckOutOfRangeUint16(0x10000, 0);
366 CheckOutOfRangeUint16(0x100000, 0);
367 CheckOutOfRangeUint16(-0x8000, 0x8000);
368 CheckOutOfRangeUint16(-1, 0xFFFF);
369 CheckOutOfRangeUint16(-0xFFFF, 1);
370
371 CheckOutOfRangeInt32(0x80000000, -0x80000000);
372 CheckOutOfRangeInt32(0x100000000, 0);
373 CheckOutOfRangeInt32(-0x80000001, 0x7FFFFFFF);
374
375 CheckOutOfRangeUint32(0x100000000, 0);
376 CheckOutOfRangeUint32(0x1000000000, 0);
377 CheckOutOfRangeUint32(-0x80000000, 0x80000000);
378 CheckOutOfRangeUint32(-1, 0xFFFFFFFF);
379 CheckOutOfRangeUint32(-0xFFFFFFFF, 1);
380 }
381
382 TestOutOfRange();
383
303 function TestGeneralAccessors() { 384 function TestGeneralAccessors() {
304 var a = new DataView(new ArrayBuffer(256)); 385 var a = new DataView(new ArrayBuffer(256));
305 function CheckAccessor(name) { 386 function CheckAccessor(name) {
306 var f = a[name]; 387 var f = a[name];
307 assertThrows(function() { f(); }, TypeError); 388 assertThrows(function() { f(); }, TypeError);
308 f.call(a, 0, 0); // should not throw 389 f.call(a, 0, 0); // should not throw
309 assertThrows(function() { f.call({}, 0, 0); }, TypeError); 390 assertThrows(function() { f.call({}, 0, 0); }, TypeError);
310 assertThrows(function() { f.call(a); }, TypeError); 391 assertThrows(function() { f.call(a); }, TypeError);
311 } 392 }
312 CheckAccessor("getUint8"); 393 CheckAccessor("getUint8");
313 CheckAccessor("setUint8"); 394 CheckAccessor("setUint8");
314 CheckAccessor("getInt8"); 395 CheckAccessor("getInt8");
315 CheckAccessor("setInt8"); 396 CheckAccessor("setInt8");
316 CheckAccessor("getUint16"); 397 CheckAccessor("getUint16");
317 CheckAccessor("setUint16"); 398 CheckAccessor("setUint16");
318 CheckAccessor("getInt16"); 399 CheckAccessor("getInt16");
319 CheckAccessor("setInt16"); 400 CheckAccessor("setInt16");
320 CheckAccessor("getUint32"); 401 CheckAccessor("getUint32");
321 CheckAccessor("setUint32"); 402 CheckAccessor("setUint32");
322 CheckAccessor("getInt32"); 403 CheckAccessor("getInt32");
323 CheckAccessor("setInt32"); 404 CheckAccessor("setInt32");
324 CheckAccessor("getFloat32"); 405 CheckAccessor("getFloat32");
325 CheckAccessor("setFloat32"); 406 CheckAccessor("setFloat32");
326 CheckAccessor("getFloat64"); 407 CheckAccessor("getFloat64");
327 CheckAccessor("setFloat64"); 408 CheckAccessor("setFloat64");
328 } 409 }
329 410
330 TestGeneralAccessors(); 411 TestGeneralAccessors();
OLDNEW
« no previous file with comments | « src/runtime.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698