};
+// pre-set for values that may exist in the future
+Buffer.prototype.length = undefined;
+Buffer.prototype.parent = undefined;
+
+
// toString(encoding, start=0, end=buffer.length)
Buffer.prototype.toString = function(encoding, start, end) {
encoding = !!encoding ? (encoding + '').toLowerCase() : 'utf8';
end = start;
var buf = new Buffer();
- buf.parent = sliceOnto(this, buf, start, end);
+ sliceOnto(this, buf, start, end);
+ buf.parent = this.parent === undefined ? this : this.parent;
buf.length = end - start;
return buf;
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;
}
+// make sure only top level parent propagates from allocPool
+var b = new Buffer(5);
+var c = b.slice(0, 4);
+var d = c.slice(0, 2);
+assert.equal(b.parent, c.parent);
+assert.equal(b.parent, d.parent);
+
+// also from a non-pooled instance
+var b = new SlowBuffer(5);
+var c = b.slice(0, 4);
+var d = c.slice(0, 2);
+assert.equal(b, c.parent);
+assert.equal(b, d.parent);
+
+
// Bug regression test
var testValue = '\u00F6\u65E5\u672C\u8A9E'; // ö日本語