summaryrefslogtreecommitdiff
path: root/test/simple
diff options
context:
space:
mode:
authorTrevor Norris <trev.norris@gmail.com>2013-05-15 11:01:33 -0700
committerTrevor Norris <trev.norris@gmail.com>2013-06-18 15:39:32 -0700
commitfb40da822fa8bb6da588af1989aaf32ef01d0a17 (patch)
treee039eceebaff60372da7b89d3e4846898e691be1 /test/simple
parent456942a920fe313ebe0b0da366d26ef400ec177e (diff)
downloadnode-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.js37
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);