From 3dd409e763656e80beebbbb3ec8bb148b943f675 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mart=C3=ADn=20Acosta?= Date: Mon, 24 Jun 2019 17:26:02 -0300 Subject: [PATCH] Fixed tests for node 4. --- tests/comp_bytes.js | 64 ++++++++++++++++++++++++--------------------- 1 file changed, 34 insertions(+), 30 deletions(-) diff --git a/tests/comp_bytes.js b/tests/comp_bytes.js index ab088ecf3..a2a649c8a 100644 --- a/tests/comp_bytes.js +++ b/tests/comp_bytes.js @@ -1,39 +1,43 @@ var tape = require("tape"); -class CustomBuffer extends Buffer { - static toCustom(b) { - b._isCustom = true; - return b; - } - - static isCustom(b) { - return !!b._isCustom; - } - - static from(...args) { - return CustomBuffer.toCustom(Buffer.from(...args)); - } - - static alloc(...args) { - return CustomBuffer.toCustom(Buffer.alloc(...args)); - } - - static allocUnsafe(...args) { - return CustomBuffer.toCustom(Buffer.allocUnsafe(...args)); - } - - static allocUnsafeSlow(...args) { - return CustomBuffer.toCustom(Buffer.allocUnsafeSlow(...args)); - } - - slice(...args) { - return CustomBuffer.toCustom(super.slice(...args)); - } +var protobuf = require(".."); + +// extends Buffer +(CustomBuffer.prototype = Object.create(Buffer.prototype)).constructor = CustomBuffer; + +function CustomBuffer() { + Buffer.call(this); +} + +CustomBuffer.isBuffer = Buffer.isBuffer.bind(Buffer); + +CustomBuffer.toCustom = function (b) { + b._isCustom = true; + return b; +} + +CustomBuffer.isCustom = function (b) { + return !!b._isCustom; +} + +CustomBuffer.from = function (valueOf, encodingOrOffset, length) { + return CustomBuffer.toCustom(Buffer.from(valueOf, encodingOrOffset, length)); +} + +CustomBuffer.alloc = function (size, fill, encoding) { + return CustomBuffer.toCustom(Buffer.alloc(size, fill, encoding)); +} + +CustomBuffer.allocUnsafe = function (size) { + return CustomBuffer.toCustom(Buffer.allocUnsafe(size)); +} + +CustomBuffer.prototype.slice = function (start, end) { + return CustomBuffer.toCustom(this.slice(start, end)); } tape.test("configure a custom encoder/decoder for bytes", function(test) { - var protobuf = require(".."); var oldBuffer = protobuf.util.Buffer; protobuf.util.Buffer = CustomBuffer;