diff options
author | Trevor Norris <trev.norris@gmail.com> | 2013-05-15 11:01:33 -0700 |
---|---|---|
committer | Trevor Norris <trev.norris@gmail.com> | 2013-06-18 15:39:32 -0700 |
commit | fb40da822fa8bb6da588af1989aaf32ef01d0a17 (patch) | |
tree | e039eceebaff60372da7b89d3e4846898e691be1 /test/simple | |
parent | 456942a920fe313ebe0b0da366d26ef400ec177e (diff) | |
download | node-fb40da822fa8bb6da588af1989aaf32ef01d0a17.tar.gz |
buffer: expose class methods alloc and dispose
Expose the ability for users to allocate and manually dispose data on
any object. These are user-safe versions of internal smalloc functions.
Diffstat (limited to 'test/simple')
-rw-r--r-- | test/simple/test-buffer.js | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/test/simple/test-buffer.js b/test/simple/test-buffer.js index b5a76d90f..19fa4eacb 100644 --- a/test/simple/test-buffer.js +++ b/test/simple/test-buffer.js @@ -923,3 +923,40 @@ assert.equal(Buffer.byteLength('aaaa==', 'base64'), 3); assert.throws(function() { Buffer('', 'buffer'); }, TypeError); + + +// test Buffer alloc + +// arrays are unsupported by v8 +assert.throws(function() { + Buffer.alloc(0, []); +}, TypeError); + +// can't create too large an alloc +assert.throws(function() { + Buffer.alloc(0x3fffffff + 1); +}, RangeError); + +// make sure values are assigned +var b = {}; +Buffer.alloc(256, b); +for (var i = 0; i < 256; i++) + b[i] = i; +for (var i = 0; i < 256; i++) + assert.equal(b[i], i); +assert.equal(b[257], undefined); + +// several other types that shouldn't throw +Buffer.alloc(1, function() { }); +Buffer.alloc(1, /abc/); +Buffer.alloc(1, new Date()); + + +// make sure disposal works +var b = {}; +Buffer.alloc(5, b); +for (var i = 0; i < 5; i++) + b[i] = i; +Buffer.dispose(b); +for (var i = 0; i < 5; i++) + assert.equal(b[i], undefined); |