Use parent SlowBuffer, if any, when Buffer is sliced

Closes #3416
Closes #3477
This commit is contained in:
Karl Skomski 2012-06-18 11:03:32 +02:00 committed by Bert Belder
parent 81a889fd88
commit 57d53a47e8
2 changed files with 8 additions and 1 deletions

View File

@ -210,8 +210,12 @@ function Buffer(subject, encoding, offset) {
// Are we slicing?
if (typeof offset === 'number') {
if (!Buffer.isBuffer(subject)) {
throw new Error('First argument must be a Buffer when slicing');
}
this.length = coerce(encoding);
this.parent = subject;
this.parent = subject.parent ? subject.parent : subject;
this.offset = offset;
} else {
// Find the length

View File

@ -724,3 +724,6 @@ var a = Buffer(3);
var b = Buffer('xxx');
a.write('aaaaaaaa', 'base64');
assert.equal(b.toString(), 'xxx');
// issue GH-3416
Buffer(Buffer(0), 0, 0);