OLD | NEW |
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 Loading... |
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 f.call(a); | 403 assertThrows(function() { f.call(a); }, TypeError); |
404 f.call(a, 1); // should not throw | 404 if (name.indexOf("set") == 0) { |
| 405 assertThrows(function() { f.call(a, 1); }, TypeError); |
| 406 } else { |
| 407 f.call(a, 1); // should not throw |
| 408 } |
405 } | 409 } |
406 CheckAccessor("getUint8"); | 410 CheckAccessor("getUint8"); |
407 CheckAccessor("setUint8"); | 411 CheckAccessor("setUint8"); |
408 CheckAccessor("getInt8"); | 412 CheckAccessor("getInt8"); |
409 CheckAccessor("setInt8"); | 413 CheckAccessor("setInt8"); |
410 CheckAccessor("getUint16"); | 414 CheckAccessor("getUint16"); |
411 CheckAccessor("setUint16"); | 415 CheckAccessor("setUint16"); |
412 CheckAccessor("getInt16"); | 416 CheckAccessor("getInt16"); |
413 CheckAccessor("setInt16"); | 417 CheckAccessor("setInt16"); |
414 CheckAccessor("getUint32"); | 418 CheckAccessor("getUint32"); |
415 CheckAccessor("setUint32"); | 419 CheckAccessor("setUint32"); |
416 CheckAccessor("getInt32"); | 420 CheckAccessor("getInt32"); |
417 CheckAccessor("setInt32"); | 421 CheckAccessor("setInt32"); |
418 CheckAccessor("getFloat32"); | 422 CheckAccessor("getFloat32"); |
419 CheckAccessor("setFloat32"); | 423 CheckAccessor("setFloat32"); |
420 CheckAccessor("getFloat64"); | 424 CheckAccessor("getFloat64"); |
421 CheckAccessor("setFloat64"); | 425 CheckAccessor("setFloat64"); |
422 } | 426 } |
423 | 427 |
424 TestGeneralAccessors(); | 428 TestGeneralAccessors(); |
425 | 429 |
426 function TestInsufficientArguments() { | 430 function TestInsufficientArguments() { |
427 var a = new DataView(new ArrayBuffer(256)); | 431 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); | |
431 | 432 |
432 assertSame(undefined, a["set" + type](0, 7)); | 433 assertThrows(function() { a.getUint8(); }, TypeError); |
433 assertSame(undefined, a["set" + type]()); | 434 assertThrows(function() { a.getInt8(); }, TypeError); |
434 assertSame(expectedValue, a["get" + type]()); | 435 assertThrows(function() { a.getUint16(); }, TypeError); |
| 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); |
435 | 441 |
436 assertSame(undefined, a["set" + type](offset, 7)); | 442 assertThrows(function() { a.setUint8(); }, TypeError); |
437 assertSame(undefined, a["set" + type](offset)); | 443 assertThrows(function() { a.setInt8(); }, TypeError); |
438 assertSame(expectedValue, a["get" + type](offset)); | 444 assertThrows(function() { a.setUint16(); }, TypeError); |
439 } | 445 assertThrows(function() { a.setInt16(); }, TypeError); |
| 446 assertThrows(function() { a.setUint32(); }, TypeError); |
| 447 assertThrows(function() { a.setInt32(); }, TypeError); |
| 448 assertThrows(function() { a.setFloat32(); }, TypeError); |
| 449 assertThrows(function() { a.setFloat64(); }, TypeError); |
440 | 450 |
441 CheckInsuficientArguments("Uint8"); | 451 assertThrows(function() { a.setUint8(1) }, TypeError); |
442 CheckInsuficientArguments("Int8"); | 452 assertThrows(function() { a.setInt8(1) }, TypeError); |
443 CheckInsuficientArguments("Uint16"); | 453 assertThrows(function() { a.setUint16(1) }, TypeError); |
444 CheckInsuficientArguments("Int16"); | 454 assertThrows(function() { a.setInt16(1) }, TypeError); |
445 CheckInsuficientArguments("Uint32"); | 455 assertThrows(function() { a.setUint32(1) }, TypeError); |
446 CheckInsuficientArguments("Int32"); | 456 assertThrows(function() { a.setInt32(1) }, TypeError); |
447 CheckInsuficientArguments("Float32"); | 457 assertThrows(function() { a.setFloat32(1) }, TypeError); |
448 CheckInsuficientArguments("Float64"); | 458 assertThrows(function() { a.setFloat64(1) }, TypeError); |
449 } | 459 } |
450 | 460 |
451 TestInsufficientArguments(); | 461 TestInsufficientArguments(); |
OLD | NEW |