From b806e733726ce47b641e3b5a400d3bafec45abe0 Mon Sep 17 00:00:00 2001 From: pawelrychlik Date: Wed, 9 Nov 2016 22:49:33 +0100 Subject: [PATCH] bytebuffer.js - this.view is never null --- src/bytebuffer.js | 4 ++-- src/methods/compact.js | 2 +- tests/suite.js | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/bytebuffer.js b/src/bytebuffer.js index 73f75cc..95351dc 100644 --- a/src/bytebuffer.js +++ b/src/bytebuffer.js @@ -51,11 +51,11 @@ var ByteBuffer = function(capacity, littleEndian, noAssert) { this.view = capacity === 0 ? null : new DataView(this.buffer); //? } else { /** - * Uint8Array utilized to manipulate the backing buffer. Becomes `null` if the backing buffer has a capacity of `0`. + * Uint8Array utilized to manipulate the backing buffer. * @type {?Uint8Array} * @expose */ - this.view = capacity === 0 ? null : new Uint8Array(this.buffer); + this.view = new Uint8Array(this.buffer); //? } //? } diff --git a/src/methods/compact.js b/src/methods/compact.js index 8888378..a2881f7 100644 --- a/src/methods/compact.js +++ b/src/methods/compact.js @@ -19,7 +19,7 @@ ByteBufferPrototype.compact = function(begin, end) { if (len === 0) { this.buffer = EMPTY_BUFFER; //? if (!NODE) - this.view = null; + this.view = new Uint8Array(this.buffer); if (this.markedOffset >= 0) this.markedOffset -= begin; this.offset = 0; this.limit = 0; diff --git a/tests/suite.js b/tests/suite.js index 1e3829c..58fad4d 100644 --- a/tests/suite.js +++ b/tests/suite.js @@ -415,7 +415,7 @@ function makeSuite(ByteBuffer) { test.notStrictEqual(bb.buffer, prevBuffer); test.strictEqual(bb.buffer, new ByteBuffer(0).buffer); // EMPTY_BUFFER if (type === ArrayBuffer) { - test.strictEqual(bb.view, null); + test.equal(bb.view.length, 0); } test.equal(bb.capacity(), 0); test.equal(bb.offset, 0);