Showing with 23 additions and 4 deletions.
  1. +2 −2 lib/buffer.js
  2. +7 −0 test/simple/test-buffer-inspect.js
  3. +10 −0 test/simple/test-buffer.js
  4. +4 −2 test/simple/test-timers-ordering.js
@@ -93,7 +93,7 @@ function Buffer(subject, encoding) {

function SlowBuffer(length) {
length = length >>> 0;
if (this.length > kMaxLength) {
if (length > kMaxLength) {
throw new RangeError('Attempt to allocate Buffer larger than maximum ' +
'size: 0x' + kMaxLength.toString(16) + ' bytes');
}
@@ -208,7 +208,7 @@ Buffer.prototype.toString = function(encoding, start, end) {
var loweredCase = false;

start = start >>> 0;
end = util.isUndefined(end) ? this.length : end >>> 0;
end = util.isUndefined(end) || end === Infinity ? this.length : end >>> 0;

if (!encoding) encoding = 'utf8';
if (start < 0) start = 0;
@@ -49,3 +49,10 @@ expected = '<Buffer 31 32>';

assert.strictEqual(util.inspect(b), expected);
assert.strictEqual(util.inspect(s), expected);

buffer.INSPECT_MAX_BYTES = Infinity;

assert.doesNotThrow(function() {
assert.strictEqual(util.inspect(b), expected);
assert.strictEqual(util.inspect(s), expected);
});
@@ -24,6 +24,7 @@ var assert = require('assert');

var Buffer = require('buffer').Buffer;
var SlowBuffer = require('buffer').SlowBuffer;
var smalloc = require('smalloc');

// counter to ensure unique value is always copied
var cntr = 0;
@@ -993,3 +994,12 @@ for (var i = 0; i < 5; i++)
b.fill('ghijk');
for (var i = 0; i < 5; i++)
assert.notEqual(d[i], b[i]);


assert.throws(function () {
new Buffer(smalloc.kMaxLength + 1);
}, RangeError);

assert.throws(function () {
new SlowBuffer(smalloc.kMaxLength + 1);
}, RangeError);
@@ -21,13 +21,15 @@

var common = require('../common');
var assert = require('assert');
var Timer = process.binding('timer_wrap').Timer;

var i;

var N = 30;

var last_i = 0;
var last_ts = 0;
var start = Date.now();
var start = Timer.now();

var f = function(i) {
if (i <= N) {
@@ -36,7 +38,7 @@ var f = function(i) {
last_i = i;

// check that this iteration is fired at least 1ms later than the previous
var now = Date.now();
var now = Timer.now();
console.log(i, now);
assert(now >= last_ts + 1, 'current ts ' + now + ' < prev ts ' + last_ts + ' + 1');
last_ts = now;