Skip to content

Commit 579068a

Browse files
committed
Other: Updated test cases to use new buffer util
1 parent 0be01a1 commit 579068a

File tree

3 files changed

+10
-11
lines changed

3 files changed

+10
-11
lines changed

bench/alloc.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22
"use strict";
33

44
var newSuite = require("./suite"),
5-
pool = require("../src/util/pool");
5+
protobuf = require("..");
66

7-
var poolAlloc = pool(function(size) {
7+
var poolAlloc = protobuf.util.pool(function(size) {
88
return new Uint8Array(size);
99
}, Uint8Array.prototype.subarray);
1010

bench/index.js

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -39,15 +39,10 @@ for (i = 0; i < 500000; ++i)
3939
Test.verify(data);
4040
process.stdout.write("\n");
4141

42-
if (!Buffer.from)
43-
Buffer.from = function from(str, enc) {
44-
return new Buffer(str, enc);
45-
};
46-
4742
// give the optimizer some time to do its job
4843
setTimeout(function() {
4944
var str = JSON.stringify(data),
50-
strbuf = Buffer.from(str, "utf8");
45+
strbuf = protobuf.util._Buffer_from(str, "utf8");
5146

5247
newSuite("encoding")
5348
.add("Type.encode to buffer", function() {
@@ -57,7 +52,7 @@ setTimeout(function() {
5752
JSON.stringify(data);
5853
})
5954
.add("JSON.stringify to buffer", function() {
60-
Buffer.from(JSON.stringify(data), "utf8");
55+
protobuf.util._Buffer_from(JSON.stringify(data), "utf8");
6156
})
6257
.run();
6358

@@ -81,7 +76,7 @@ setTimeout(function() {
8176
JSON.parse(JSON.stringify(data));
8277
})
8378
.add("JSON to/from buffer", function() {
84-
JSON.parse(Buffer.from(JSON.stringify(data), "utf8").toString("utf8"));
79+
JSON.parse(protobuf.util._Buffer_from(JSON.stringify(data), "utf8").toString("utf8"));
8580
})
8681
.run();
8782

lib/fetch/tests/index.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,11 @@ function fakeXHR(status, ancient) {
144144
self.status = status;
145145
if (self.responseType === "arraybuffer" && !ancient) {
146146
var buf = new Buffer(self._path, "utf8");
147-
self.response = buf.buffer.slice(buf.byteOffset, buf.byteOffset + buf.byteLength);
147+
var abuf = new ArrayBuffer(buf.length);
148+
var view = new Uint8Array(abuf);
149+
for (var i = 0; i < buf.length; ++i)
150+
view[i] = buf[i];
151+
self.response = abuf;
148152
} else
149153
self.responseText = self._path;
150154
self.onreadystatechange();

0 commit comments

Comments
 (0)