From 579068a45e285c7d2c69b359716dd6870352f46f Mon Sep 17 00:00:00 2001 From: dcodeIO Date: Sat, 28 Jan 2017 04:57:04 +0100 Subject: [PATCH] Other: Updated test cases to use new buffer util --- bench/alloc.js | 4 ++-- bench/index.js | 11 +++-------- lib/fetch/tests/index.js | 6 +++++- 3 files changed, 10 insertions(+), 11 deletions(-) diff --git a/bench/alloc.js b/bench/alloc.js index d55c7f7c8..7dab2e9e8 100644 --- a/bench/alloc.js +++ b/bench/alloc.js @@ -2,9 +2,9 @@ "use strict"; var newSuite = require("./suite"), - pool = require("../src/util/pool"); + protobuf = require(".."); -var poolAlloc = pool(function(size) { +var poolAlloc = protobuf.util.pool(function(size) { return new Uint8Array(size); }, Uint8Array.prototype.subarray); diff --git a/bench/index.js b/bench/index.js index 8ebe43aa7..c8126e4b0 100644 --- a/bench/index.js +++ b/bench/index.js @@ -39,15 +39,10 @@ for (i = 0; i < 500000; ++i) Test.verify(data); process.stdout.write("\n"); -if (!Buffer.from) - Buffer.from = function from(str, enc) { - return new Buffer(str, enc); - }; - // give the optimizer some time to do its job setTimeout(function() { var str = JSON.stringify(data), - strbuf = Buffer.from(str, "utf8"); + strbuf = protobuf.util._Buffer_from(str, "utf8"); newSuite("encoding") .add("Type.encode to buffer", function() { @@ -57,7 +52,7 @@ setTimeout(function() { JSON.stringify(data); }) .add("JSON.stringify to buffer", function() { - Buffer.from(JSON.stringify(data), "utf8"); + protobuf.util._Buffer_from(JSON.stringify(data), "utf8"); }) .run(); @@ -81,7 +76,7 @@ setTimeout(function() { JSON.parse(JSON.stringify(data)); }) .add("JSON to/from buffer", function() { - JSON.parse(Buffer.from(JSON.stringify(data), "utf8").toString("utf8")); + JSON.parse(protobuf.util._Buffer_from(JSON.stringify(data), "utf8").toString("utf8")); }) .run(); diff --git a/lib/fetch/tests/index.js b/lib/fetch/tests/index.js index 5db515122..81b3e4875 100644 --- a/lib/fetch/tests/index.js +++ b/lib/fetch/tests/index.js @@ -144,7 +144,11 @@ function fakeXHR(status, ancient) { self.status = status; if (self.responseType === "arraybuffer" && !ancient) { var buf = new Buffer(self._path, "utf8"); - self.response = buf.buffer.slice(buf.byteOffset, buf.byteOffset + buf.byteLength); + var abuf = new ArrayBuffer(buf.length); + var view = new Uint8Array(abuf); + for (var i = 0; i < buf.length; ++i) + view[i] = buf[i]; + self.response = abuf; } else self.responseText = self._path; self.onreadystatechange();