diff options
author | Trevor Norris <trev.norris@gmail.com> | 2012-12-22 13:06:50 -0800 |
---|---|---|
committer | isaacs <i@izs.me> | 2013-01-16 10:17:20 -0800 |
commit | 22b84e6216b86f9d5178e7d8a4d1a577209b7008 (patch) | |
tree | df7048a760d248569223a5d305b59cd6981033c0 /test/simple/test-buffer.js | |
parent | eef0ccbcafb82b1a47ce94fe257c991423a5bcdf (diff) | |
download | node-new-22b84e6216b86f9d5178e7d8a4d1a577209b7008.tar.gz |
buffer: floating point read/write improvements
Improvements:
* floating point operations are approx 4x's faster
* Now write quiet NaN's
* all read/write on floating point now done in C, so no more need for
lib/buffer_ieee754.js
* float values have more accurate min/max value checks
* add additional benchmarks for buffers read/write
* created benchmark/_bench_timer.js which is a simple library that
can be included into any benchmark and provides an intelligent tracker
for sync and async tests
* add benchmarks for DataView set methods
* add checks and tests to make sure offset is greater than 0
Diffstat (limited to 'test/simple/test-buffer.js')
-rw-r--r-- | test/simple/test-buffer.js | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/test/simple/test-buffer.js b/test/simple/test-buffer.js index 7851a002d5..534839918f 100644 --- a/test/simple/test-buffer.js +++ b/test/simple/test-buffer.js @@ -812,3 +812,47 @@ assert.throws(function() { assert.throws(function() { new Buffer(0xFFFFFFFFF); }, TypeError); + + +// attempt to overflow buffers, similar to previous bug in array buffers +assert.throws(function() { + var buf = new Buffer(8); + buf.readFloatLE(0xffffffff); +}, /Trying to access beyond buffer length/); + +assert.throws(function() { + var buf = new Buffer(8); + buf.writeFloatLE(0.0, 0xffffffff); +}, /Trying to access beyond buffer length/); + +assert.throws(function() { + var buf = new SlowBuffer(8); + buf.readFloatLE(0xffffffff); +}, /Trying to read beyond buffer length/); + +assert.throws(function() { + var buf = new SlowBuffer(8); + buf.writeFloatLE(0.0, 0xffffffff); +}, /Trying to write beyond buffer length/); + + +// ensure negative values can't get past offset +assert.throws(function() { + var buf = new Buffer(8); + buf.readFloatLE(-1); +}, /offset is not uint/); + +assert.throws(function() { + var buf = new Buffer(8); + buf.writeFloatLE(0.0, -1); +}, /offset is not uint/); + +assert.throws(function() { + var buf = new SlowBuffer(8); + buf.readFloatLE(-1); +}, /offset is not uint/); + +assert.throws(function() { + var buf = new SlowBuffer(8); + buf.writeFloatLE(0.0, -1); +}, /offset is not uint/); |