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

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

Issue 2090353003: Amend DataView, ArrayBuffer, and TypedArray methods to use ToIndex. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: comment Created 4 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
« no previous file with comments | « src/objects.cc ('k') | test/test262/test262.status » ('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
(...skipping 382 matching lines...) Expand 10 before | Expand all | Expand 10 after
393 393
394 TestOutOfRange(); 394 TestOutOfRange();
395 395
396 function TestGeneralAccessors() { 396 function TestGeneralAccessors() {
397 var a = new DataView(new ArrayBuffer(256)); 397 var a = new DataView(new ArrayBuffer(256));
398 function CheckAccessor(name) { 398 function CheckAccessor(name) {
399 var f = a[name]; 399 var f = a[name];
400 assertThrows(function() { f(); }, TypeError); 400 assertThrows(function() { f(); }, TypeError);
401 f.call(a, 0, 0); // should not throw 401 f.call(a, 0, 0); // should not throw
402 assertThrows(function() { f.call({}, 0, 0); }, TypeError); 402 assertThrows(function() { f.call({}, 0, 0); }, TypeError);
403 assertThrows(function() { f.call(a); }, TypeError); 403 f.call(a);
404 if (name.indexOf("set") == 0) { 404 f.call(a, 1); // should not throw
405 assertThrows(function() { f.call(a, 1); }, TypeError);
406 } else {
407 f.call(a, 1); // should not throw
408 }
409 } 405 }
410 CheckAccessor("getUint8"); 406 CheckAccessor("getUint8");
411 CheckAccessor("setUint8"); 407 CheckAccessor("setUint8");
412 CheckAccessor("getInt8"); 408 CheckAccessor("getInt8");
413 CheckAccessor("setInt8"); 409 CheckAccessor("setInt8");
414 CheckAccessor("getUint16"); 410 CheckAccessor("getUint16");
415 CheckAccessor("setUint16"); 411 CheckAccessor("setUint16");
416 CheckAccessor("getInt16"); 412 CheckAccessor("getInt16");
417 CheckAccessor("setInt16"); 413 CheckAccessor("setInt16");
418 CheckAccessor("getUint32"); 414 CheckAccessor("getUint32");
419 CheckAccessor("setUint32"); 415 CheckAccessor("setUint32");
420 CheckAccessor("getInt32"); 416 CheckAccessor("getInt32");
421 CheckAccessor("setInt32"); 417 CheckAccessor("setInt32");
422 CheckAccessor("getFloat32"); 418 CheckAccessor("getFloat32");
423 CheckAccessor("setFloat32"); 419 CheckAccessor("setFloat32");
424 CheckAccessor("getFloat64"); 420 CheckAccessor("getFloat64");
425 CheckAccessor("setFloat64"); 421 CheckAccessor("setFloat64");
426 } 422 }
427 423
428 TestGeneralAccessors(); 424 TestGeneralAccessors();
429 425
430 function TestInsufficientArguments() { 426 function TestInsufficientArguments() {
431 var a = new DataView(new ArrayBuffer(256)); 427 var a = new DataView(new ArrayBuffer(256));
428 function CheckInsuficientArguments(type) {
429 var expectedValue = type === "Float32" || type === "Float64" ? NaN : 0;
430 var offset = getElementSize(type);
432 431
433 assertThrows(function() { a.getUint8(); }, TypeError); 432 assertSame(undefined, a["set" + type](0, 7));
434 assertThrows(function() { a.getInt8(); }, TypeError); 433 assertSame(undefined, a["set" + type]());
435 assertThrows(function() { a.getUint16(); }, TypeError); 434 assertSame(expectedValue, a["get" + type]());
436 assertThrows(function() { a.getInt16(); }, TypeError);
437 assertThrows(function() { a.getUint32(); }, TypeError);
438 assertThrows(function() { a.getInt32(); }, TypeError);
439 assertThrows(function() { a.getFloat32(); }, TypeError);
440 assertThrows(function() { a.getFloat64(); }, TypeError);
441 435
442 assertThrows(function() { a.setUint8(); }, TypeError); 436 assertSame(undefined, a["set" + type](offset, 7));
443 assertThrows(function() { a.setInt8(); }, TypeError); 437 assertSame(undefined, a["set" + type](offset));
444 assertThrows(function() { a.setUint16(); }, TypeError); 438 assertSame(expectedValue, a["get" + type](offset));
445 assertThrows(function() { a.setInt16(); }, TypeError); 439 }
446 assertThrows(function() { a.setUint32(); }, TypeError);
447 assertThrows(function() { a.setInt32(); }, TypeError);
448 assertThrows(function() { a.setFloat32(); }, TypeError);
449 assertThrows(function() { a.setFloat64(); }, TypeError);
450 440
451 assertThrows(function() { a.setUint8(1) }, TypeError); 441 CheckInsuficientArguments("Uint8");
452 assertThrows(function() { a.setInt8(1) }, TypeError); 442 CheckInsuficientArguments("Int8");
453 assertThrows(function() { a.setUint16(1) }, TypeError); 443 CheckInsuficientArguments("Uint16");
454 assertThrows(function() { a.setInt16(1) }, TypeError); 444 CheckInsuficientArguments("Int16");
455 assertThrows(function() { a.setUint32(1) }, TypeError); 445 CheckInsuficientArguments("Uint32");
456 assertThrows(function() { a.setInt32(1) }, TypeError); 446 CheckInsuficientArguments("Int32");
457 assertThrows(function() { a.setFloat32(1) }, TypeError); 447 CheckInsuficientArguments("Float32");
458 assertThrows(function() { a.setFloat64(1) }, TypeError); 448 CheckInsuficientArguments("Float64");
459 } 449 }
460 450
461 TestInsufficientArguments(); 451 TestInsufficientArguments();
OLDNEW
« no previous file with comments | « src/objects.cc ('k') | test/test262/test262.status » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698