summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorJames M Snell <jasnell@gmail.com>2016-03-21 12:38:08 -0700
committerJames M Snell <jasnell@gmail.com>2016-04-15 10:36:01 -0700
commit627524973a22c584fdd06c951fbe82364927a1ed (patch)
treeabd6cf987b5cd834bedeb3fd43c2e9b71880d920 /test
parentb488b19eaf2b2e7a3ca5eccd2445e245847a5f76 (diff)
downloadandroid-node-v8-627524973a22c584fdd06c951fbe82364927a1ed.tar.gz
android-node-v8-627524973a22c584fdd06c951fbe82364927a1ed.tar.bz2
android-node-v8-627524973a22c584fdd06c951fbe82364927a1ed.zip
buffer: add Buffer.allocUnsafeSlow(size)
Aligns the functionality of SlowBuffer with the new Buffer constructor API. Next step is to docs-only deprecate SlowBuffer. Replace the internal uses of SlowBuffer with `Buffer.allocUnsafeSlow(size)` PR-URL: https://github.com/nodejs/node/pull/5833 Reviewed-By: Сковорода Никита Андреевич <chalkerx@gmail.com> Reviewed-By: Trevor Norris <trev.norris@gmail.com> Reviewed-By: Sakthipriyan Vairamani <thechargingvolcano@gmail.com>
Diffstat (limited to 'test')
-rw-r--r--test/parallel/test-buffer-alloc.js20
1 files changed, 9 insertions, 11 deletions
diff --git a/test/parallel/test-buffer-alloc.js b/test/parallel/test-buffer-alloc.js
index 733fa10504..131fcb112f 100644
--- a/test/parallel/test-buffer-alloc.js
+++ b/test/parallel/test-buffer-alloc.js
@@ -3,7 +3,6 @@ var common = require('../common');
var assert = require('assert');
var Buffer = require('buffer').Buffer;
-var SlowBuffer = require('buffer').SlowBuffer;
// counter to ensure unique value is always copied
var cntr = 0;
@@ -428,7 +427,7 @@ for (let i = 0; i < Buffer.byteLength(utf8String); i++) {
{
// also from a non-pooled instance
- const b = new SlowBuffer(5);
+ const b = Buffer.allocUnsafeSlow(5);
const c = b.slice(0, 4);
const d = c.slice(0, 2);
assert.equal(c.parent, d.parent);
@@ -1305,7 +1304,7 @@ assert.throws(function() {
// try to slice a zero length Buffer
// see https://github.com/joyent/node/issues/5881
- SlowBuffer(0).slice(0, 1);
+ Buffer.alloc(0).slice(0, 1);
})();
// Regression test for #5482: should throw but not assert in C++ land.
@@ -1336,7 +1335,7 @@ assert.throws(function() {
}, RangeError);
assert.throws(function() {
- SlowBuffer((-1 >>> 0) + 1);
+ Buffer.allocUnsafeSlow((-1 >>> 0) + 1);
}, RangeError);
if (common.hasCrypto) {
@@ -1435,14 +1434,13 @@ assert.throws(function() {
}, regErrorMsg);
-// Test prototype getters don't throw
-assert.equal(Buffer.prototype.parent, undefined);
-assert.equal(Buffer.prototype.offset, undefined);
-assert.equal(SlowBuffer.prototype.parent, undefined);
-assert.equal(SlowBuffer.prototype.offset, undefined);
-
-
// Test that ParseArrayIndex handles full uint32
assert.throws(function() {
Buffer.from(new ArrayBuffer(0), -1 >>> 0);
}, /RangeError: 'offset' is out of bounds/);
+
+// Unpooled buffer (replaces SlowBuffer)
+const ubuf = Buffer.allocUnsafeSlow(10);
+assert(ubuf);
+assert(ubuf.buffer);
+assert.equal(ubuf.buffer.byteLength, 10);