From 46b0bdd213c8c1cd5f1be5ed1cb44cff413b641a Mon Sep 17 00:00:00 2001 From: Valentin Gosu Date: Wed, 18 Sep 2019 13:44:16 +0000 Subject: [PATCH] Bug 1582051 - Use Buffer.from and Buffer.alloc in moz-http2.js & friends r=kershaw Differential Revision: https://phabricator.services.mozilla.com/D46260 --HG-- extra : moz-landing-system : lando --- testing/xpcshell/moz-http2/moz-http2.js | 26 +++---- testing/xpcshell/node-http2/lib/http.js | 2 +- .../node-http2/lib/protocol/compressor.js | 14 ++-- .../node-http2/lib/protocol/connection.js | 2 +- .../node-http2/lib/protocol/endpoint.js | 2 +- .../node-http2/lib/protocol/framer.js | 36 ++++----- .../node-http2/lib/protocol/stream.js | 2 +- .../xpcshell/node-http2/test/compressor.js | 76 +++++++++---------- .../xpcshell/node-http2/test/connection.js | 10 +-- testing/xpcshell/node-http2/test/flow.js | 12 +-- testing/xpcshell/node-http2/test/framer.js | 70 ++++++++--------- testing/xpcshell/node-http2/test/stream.js | 34 ++++----- testing/xpcshell/node-http2/test/util.js | 2 +- testing/xpcshell/node-ip/lib/ip.js | 8 +- testing/xpcshell/node-ip/test/api-test.js | 4 +- 15 files changed, 150 insertions(+), 150 deletions(-) diff --git a/testing/xpcshell/moz-http2/moz-http2.js b/testing/xpcshell/moz-http2/moz-http2.js index 7ba5050017ef..fe3b3629c704 100644 --- a/testing/xpcshell/moz-http2/moz-http2.js +++ b/testing/xpcshell/moz-http2/moz-http2.js @@ -64,7 +64,7 @@ var newTransform = function (frame, encoding, done) { // Insert our empty DATA frame emptyFrame = {}; emptyFrame.type = 'DATA'; - emptyFrame.data = new Buffer(0); + emptyFrame.data = Buffer.alloc(0); emptyFrame.flags = []; emptyFrame.stream = frame.stream; var buffers = []; @@ -168,7 +168,7 @@ var originalCompressHeaders = Compressor.prototype.compress; function insertSoftIllegalHpack(headers) { var originalCompressed = originalCompressHeaders.apply(this, headers); - var illegalLiteral = new Buffer([ + var illegalLiteral = Buffer.from([ 0x00, // Literal, no index 0x08, // Name: not huffman encoded, 8 bytes long 0x3a, 0x69, 0x6c, 0x6c, 0x65, 0x67, 0x61, 0x6c, // :illegal @@ -177,7 +177,7 @@ function insertSoftIllegalHpack(headers) { 0x52, 0x45, 0x41, 0x4c, 0x4c, 0x59, 0x20, 0x4e, 0x4f, 0x54, 0x20, 0x4c, 0x45, 0x47, 0x41, 0x4c ]); var newBufferLength = originalCompressed.length + illegalLiteral.length; - var concatenated = new Buffer(newBufferLength); + var concatenated = Buffer.alloc(newBufferLength); originalCompressed.copy(concatenated, 0); illegalLiteral.copy(concatenated, originalCompressed.length); return concatenated; @@ -193,7 +193,7 @@ function insertHardIllegalHpack(headers) { // Set the first bit to 1 to signal this is an indexed representation illegalIndexed[0] |= 0x80; var newBufferLength = originalCompressed.length + illegalIndexed.length; - var concatenated = new Buffer(newBufferLength); + var concatenated = Buffer.alloc(newBufferLength); originalCompressed.copy(concatenated, 0); illegalIndexed.copy(concatenated, originalCompressed.length); return concatenated; @@ -365,7 +365,7 @@ function handleRequest(req, res) { 'content-encoding' : 'br', 'X-Connection-Http2': 'yes' }); - push3.end(new Buffer([0x8b, 0x00, 0x80, 0x33, 0x0a, 0x03])); // '3\n' + push3.end(Buffer.from([0x8b, 0x00, 0x80, 0x33, 0x0a, 0x03])); // '3\n' content = '0'; } @@ -545,12 +545,12 @@ function handleRequest(req, res) { var content; if(0 == cname_confirm) { // ... this sends a CNAME back to pointing-elsewhere.example.com - content = new Buffer("00000100000100010000000005636E616D65076578616D706C6503636F6D0000050001C00C0005000100000037002012706F696E74696E672D656C73657768657265076578616D706C6503636F6D00", "hex"); + content = Buffer.from("00000100000100010000000005636E616D65076578616D706C6503636F6D0000050001C00C0005000100000037002012706F696E74696E672D656C73657768657265076578616D706C6503636F6D00", "hex"); cname_confirm++; } else { // ... this sends an A 99.88.77.66 entry back for pointing-elsewhere.example.com - content = new Buffer("00000100000100010000000012706F696E74696E672D656C73657768657265076578616D706C6503636F6D0000010001C00C0001000100000037000463584D42", "hex"); + content = Buffer.from("00000100000100010000000012706F696E74696E672D656C73657768657265076578616D706C6503636F6D0000010001C00C0001000100000037000463584D42", "hex"); } res.setHeader('Content-Type', 'application/dns-message'); res.setHeader('Content-Length', content.length); @@ -587,7 +587,7 @@ function handleRequest(req, res) { if (u.query["push"]) { // push.example.com has AAAA entry 2018::2018 - var pcontent= new Buffer("0000010000010001000000000470757368076578616D706C6503636F6D00001C0001C00C001C000100000037001020180000000000000000000000002018", "hex"); + var pcontent= Buffer.from("0000010000010001000000000470757368076578616D706C6503636F6D00001C0001C00C001C000100000037001020180000000000000000000000002018", "hex"); push = res.push({ hostname: 'foo.example.com:' + serverPort, port: serverPort, @@ -606,7 +606,7 @@ function handleRequest(req, res) { push.end(pcontent); } - let payload = new Buffer(""); + let payload = Buffer.from(""); function emitResponse(response, requestPayload) { let packet = dnsPacket.decode(requestPayload); @@ -716,7 +716,7 @@ function handleRequest(req, res) { // for here.example.com var content; - content = new Buffer("0000" + + content = Buffer.from("0000" + "0100" + "0001" + // QDCOUNT "0002" + // ANCOUNT @@ -757,7 +757,7 @@ function handleRequest(req, res) { } // for use with test_esni_dns_fetch.js else if (u.pathname === "/esni-dns") { - content = new Buffer("0000" + + content = Buffer.from("0000" + "8180" + "0001" + // QDCOUNT "0001" + // ANCOUNT @@ -784,10 +784,10 @@ function handleRequest(req, res) { // for use with test_esni_dns_fetch.js else if (u.pathname === "/esni-dns-push") { // _esni_push.example.com has A entry 127.0.0.1 - var content= new Buffer("0000010000010001000000000A5F65736E695F70757368076578616D706C6503636F6D0000010001C00C000100010000003700047F000001", "hex"); + var content= Buffer.from("0000010000010001000000000A5F65736E695F70757368076578616D706C6503636F6D0000010001C00C000100010000003700047F000001", "hex"); // _esni_push.example.com has TXT entry 2062586B67646D39705932556761584D6762586B676347467A63336476636D513D - var pcontent= new Buffer("0000818000010001000000000A5F65736E695F70757368076578616D706C6503636F6D0000100001C00C001000010000003700212062586B67646D39705932556761584D6762586B676347467A63336476636D513D", "hex"); + var pcontent= Buffer.from("0000818000010001000000000A5F65736E695F70757368076578616D706C6503636F6D0000100001C00C001000010000003700212062586B67646D39705932556761584D6762586B676347467A63336476636D513D", "hex"); push = res.push({ hostname: 'foo.example.com:' + serverPort, diff --git a/testing/xpcshell/node-http2/lib/http.js b/testing/xpcshell/node-http2/lib/http.js index aa3af05e5267..6e626df42fdd 100644 --- a/testing/xpcshell/node-http2/lib/http.js +++ b/testing/xpcshell/node-http2/lib/http.js @@ -1104,7 +1104,7 @@ OutgoingRequest.prototype._start = function _start(stream, options) { delete headers.host; if (options.auth) { - headers.authorization = 'Basic ' + new Buffer(options.auth).toString('base64'); + headers.authorization = 'Basic ' + Buffer.from(options.auth).toString('base64'); } headers[':scheme'] = options.protocol.slice(0, -1); diff --git a/testing/xpcshell/node-http2/lib/protocol/compressor.js b/testing/xpcshell/node-http2/lib/protocol/compressor.js index 3923a9107362..498468403c40 100644 --- a/testing/xpcshell/node-http2/lib/protocol/compressor.js +++ b/testing/xpcshell/node-http2/lib/protocol/compressor.js @@ -66,7 +66,7 @@ function entryFromPair(pair) { var DEFAULT_HEADER_TABLE_LIMIT = 4096; function size(entry) { - return (new Buffer(entry[0] + entry[1], 'utf8')).length + 32; + return (Buffer.from(entry[0] + entry[1], 'utf8')).length + 32; } // The `add(index, entry)` can be used to [manage the header table][tablemgmt]: @@ -396,7 +396,7 @@ HeaderSetCompressor.prototype._flush = function _flush(callback) { HeaderSetCompressor.integer = function writeInteger(I, N) { var limit = Math.pow(2,N) - 1; if (I < limit) { - return [new Buffer([I])]; + return [Buffer.from([I])]; } var bytes = []; @@ -418,7 +418,7 @@ HeaderSetCompressor.integer = function writeInteger(I, N) { I = Q; } - return [new Buffer(bytes)]; + return [Buffer.from(bytes)]; }; // The inverse algorithm: @@ -530,7 +530,7 @@ HuffmanTable.prototype.encode = function encode(buffer) { add(this.codes[256] >> (this.lengths[256] - space)); } - return new Buffer(result); + return Buffer.from(result); }; HuffmanTable.prototype.decode = function decode(buffer) { @@ -552,7 +552,7 @@ HuffmanTable.prototype.decode = function decode(buffer) { } } - return new Buffer(result); + return Buffer.from(result); }; // The initializer arrays for the Huffman tables are generated with feeding the tables from the @@ -852,7 +852,7 @@ HuffmanTable.huffmanTable = new HuffmanTable([ // +---+---+---+---+---+---+---+---+ HeaderSetCompressor.string = function writeString(str) { - str = new Buffer(str, 'utf8'); + str = Buffer.from(str, 'utf8'); var huffman = HuffmanTable.huffmanTable.encode(str); if (huffman.length < str.length) { @@ -1341,7 +1341,7 @@ function concat(buffers) { size += buffers[i].length; } - var concatenated = new Buffer(size); + var concatenated = Buffer.alloc(size); for (var cursor = 0, j = 0; j < buffers.length; cursor += buffers[j].length, j++) { buffers[j].copy(concatenated, cursor); } diff --git a/testing/xpcshell/node-http2/lib/protocol/connection.js b/testing/xpcshell/node-http2/lib/protocol/connection.js index d1e515de2711..8c203675fa36 100644 --- a/testing/xpcshell/node-http2/lib/protocol/connection.js +++ b/testing/xpcshell/node-http2/lib/protocol/connection.js @@ -515,7 +515,7 @@ Connection.prototype._generatePingId = function _generatePingId() { // Sending a ping and calling `callback` when the answer arrives Connection.prototype.ping = function ping(callback) { var id = this._generatePingId(); - var data = new Buffer(id, 'hex'); + var data = Buffer.from(id, 'hex'); this._pings[id] = callback; this._log.debug({ data: data }, 'Sending PING.'); diff --git a/testing/xpcshell/node-http2/lib/protocol/endpoint.js b/testing/xpcshell/node-http2/lib/protocol/endpoint.js index a218db040a73..127f4c4c5c89 100644 --- a/testing/xpcshell/node-http2/lib/protocol/endpoint.js +++ b/testing/xpcshell/node-http2/lib/protocol/endpoint.js @@ -78,7 +78,7 @@ Endpoint.prototype = Object.create(Duplex.prototype, { constructor: { value: End // Handshake // --------- -var CLIENT_PRELUDE = new Buffer('PRI * HTTP/2.0\r\n\r\nSM\r\n\r\n'); +var CLIENT_PRELUDE = Buffer.from('PRI * HTTP/2.0\r\n\r\nSM\r\n\r\n'); // Writing the client header is simple and synchronous. Endpoint.prototype._writePrelude = function _writePrelude() { diff --git a/testing/xpcshell/node-http2/lib/protocol/framer.js b/testing/xpcshell/node-http2/lib/protocol/framer.js index 303c6426b117..055402f8d8ad 100644 --- a/testing/xpcshell/node-http2/lib/protocol/framer.js +++ b/testing/xpcshell/node-http2/lib/protocol/framer.js @@ -81,7 +81,7 @@ Deserializer.prototype = Object.create(Transform.prototype, { constructor: { val // payload). The `_cursor` is used to track the progress. Deserializer.prototype._next = function(size) { this._cursor = 0; - this._buffer = new Buffer(size); + this._buffer = Buffer.alloc(size); this._waitingForHeader = !this._waitingForHeader; if (this._waitingForHeader) { this._frame = {}; @@ -204,7 +204,7 @@ var genericAttributes = ['type', 'flags', 'stream']; var typeSpecificAttributes = {}; Serializer.commonHeader = function writeCommonHeader(frame, buffers) { - var headerBuffer = new Buffer(COMMON_HEADER_SIZE); + var headerBuffer = Buffer.alloc(COMMON_HEADER_SIZE); var size = 0; for (var i = 0; i < buffers.length; i++) { @@ -363,7 +363,7 @@ typeSpecificAttributes.HEADERS = ['priorityDependency', 'priorityWeight', 'exclu Serializer.HEADERS = function writeHeadersPriority(frame, buffers) { if (frame.flags.PRIORITY) { - var buffer = new Buffer(5); + var buffer = Buffer.alloc(5); assert((0 <= frame.priorityDependency) && (frame.priorityDependency <= 0x7fffffff), frame.priorityDependency); buffer.writeUInt32BE(frame.priorityDependency, 0); if (frame.exclusiveDependency) { @@ -397,7 +397,7 @@ Deserializer.HEADERS = function readHeadersPriority(buffer, frame) { } if (frame.flags.PRIORITY) { - var dependencyData = new Buffer(4); + var dependencyData = Buffer.alloc(4); buffer.copy(dependencyData, 0, dataOffset, dataOffset + 4); dataOffset += 4; frame.exclusiveDependency = !!(dependencyData[0] & 0x80); @@ -442,7 +442,7 @@ typeSpecificAttributes.PRIORITY = ['priorityDependency', 'priorityWeight', 'excl // The payload of a PRIORITY frame contains an exclusive bit, a 31-bit dependency, and an 8-bit weight Serializer.PRIORITY = function writePriority(frame, buffers) { - var buffer = new Buffer(5); + var buffer = Buffer.alloc(5); assert((0 <= frame.priorityDependency) && (frame.priorityDependency <= 0x7fffffff), frame.priorityDependency); buffer.writeUInt32BE(frame.priorityDependency, 0); if (frame.exclusiveDependency) { @@ -459,7 +459,7 @@ Deserializer.PRIORITY = function readPriority(buffer, frame) { // PRIORITY frames are 5 bytes long. Bad peer! return 'FRAME_SIZE_ERROR'; } - var dependencyData = new Buffer(4); + var dependencyData = Buffer.alloc(4); buffer.copy(dependencyData, 0, 0, 4); frame.exclusiveDependency = !!(dependencyData[0] & 0x80); dependencyData[0] &= 0x7f; @@ -490,7 +490,7 @@ typeSpecificAttributes.RST_STREAM = ['error']; // code (see Error Codes). The error code indicates why the stream is being terminated. Serializer.RST_STREAM = function writeRstStream(frame, buffers) { - var buffer = new Buffer(4); + var buffer = Buffer.alloc(4); var code = errorCodes.indexOf(frame.error); assert((0 <= code) && (code <= 0xffffffff), code); buffer.writeUInt32BE(code, 0); @@ -555,7 +555,7 @@ Serializer.SETTINGS = function writeSettings(frame, buffers) { }); assert(settingsLeft.length === 0, 'Unknown settings: ' + settingsLeft.join(', ')); - var buffer = new Buffer(settings.length * 6); + var buffer = Buffer.alloc(settings.length * 6); for (var i = 0; i < settings.length; i++) { buffer.writeUInt16BE(settings[i].id & 0xffff, i*6); buffer.writeUInt32BE(settings[i].value, i*6 + 2); @@ -651,7 +651,7 @@ typeSpecificAttributes.PUSH_PROMISE = ['promised_stream', 'headers', 'data']; // additional context for the stream. Serializer.PUSH_PROMISE = function writePushPromise(frame, buffers) { - var buffer = new Buffer(4); + var buffer = Buffer.alloc(4); var promised_stream = frame.promised_stream; assert((0 <= promised_stream) && (promised_stream <= 0x7fffffff), promised_stream); @@ -745,7 +745,7 @@ typeSpecificAttributes.GOAWAY = ['last_stream', 'error']; // closing the connection. Serializer.GOAWAY = function writeGoaway(frame, buffers) { - var buffer = new Buffer(8); + var buffer = Buffer.alloc(8); var last_stream = frame.last_stream; assert((0 <= last_stream) && (last_stream <= 0x7fffffff), last_stream); @@ -790,7 +790,7 @@ typeSpecificAttributes.WINDOW_UPDATE = ['window_size']; // reserved. Serializer.WINDOW_UPDATE = function writeWindowUpdate(frame, buffers) { - var buffer = new Buffer(4); + var buffer = Buffer.alloc(4); var window_size = frame.window_size; assert((0 < window_size) && (window_size <= 0x7fffffff), window_size); @@ -880,7 +880,7 @@ function hexencode(s) { for (var i = 0; i < s.length; i++) { if (!istchar(s[i])) { t += '%'; - t += new Buffer(s[i]).toString('hex'); + t += Buffer.from(s[i]).toString('hex'); } else { t += s[i]; } @@ -889,17 +889,17 @@ function hexencode(s) { } Serializer.ALTSVC = function writeAltSvc(frame, buffers) { - var buffer = new Buffer(2); + var buffer = Buffer.alloc(2); buffer.writeUInt16BE(frame.origin.length, 0); buffers.push(buffer); - buffers.push(new Buffer(frame.origin, 'ascii')); + buffers.push(Buffer.from(frame.origin, 'ascii')); var fieldValue = hexencode(frame.protocolID) + '="' + frame.host + ':' + frame.port + '"'; if (frame.maxAge !== 86400) { // 86400 is the default fieldValue += "; ma=" + frame.maxAge; } - buffers.push(new Buffer(fieldValue, 'ascii')); + buffers.push(Buffer.from(fieldValue, 'ascii')); }; function stripquotes(s) { @@ -1023,7 +1023,7 @@ function unescape(s) { hexvalue += s[i]; } if (hexvalue.length > 0) { - t += new Buffer(hexvalue, 'hex').toString(); + t += Buffer.from(hexvalue, 'hex').toString(); } else { t += '%'; } @@ -1078,10 +1078,10 @@ typeSpecificAttributes.ORIGIN = ['originList']; Serializer.ORIGIN = function writeOrigin(frame, buffers) { for (var i = 0; i < frame.originList.length; i++) { - var buffer = new Buffer(2); + var buffer = Buffer.alloc(2); buffer.writeUInt16BE(frame.originList[i].length, 0); buffers.push(buffer); - buffers.push(new Buffer(frame.originList[i], 'ascii')); + buffers.push(Buffer.from(frame.originList[i], 'ascii')); } }; diff --git a/testing/xpcshell/node-http2/lib/protocol/stream.js b/testing/xpcshell/node-http2/lib/protocol/stream.js index e9fcc6b7db7e..b80dff0098c4 100644 --- a/testing/xpcshell/node-http2/lib/protocol/stream.js +++ b/testing/xpcshell/node-http2/lib/protocol/stream.js @@ -345,7 +345,7 @@ Stream.prototype._send = function _send() { // flag on the last frame. If there's no frame in the queue, or if it doesn't support this flag, // then we create a 0 length DATA frame. We could do this all the time, but putting the flag on an // existing frame is a nice optimization. -var emptyBuffer = new Buffer(0); +var emptyBuffer = Buffer.alloc(0); Stream.prototype._finishing = function _finishing() { var endFrame = { type: 'DATA', diff --git a/testing/xpcshell/node-http2/test/compressor.js b/testing/xpcshell/node-http2/test/compressor.js index f86baf5db926..4588b8a3fdd3 100644 --- a/testing/xpcshell/node-http2/test/compressor.js +++ b/testing/xpcshell/node-http2/test/compressor.js @@ -12,27 +12,27 @@ var Decompressor = compressor.Decompressor; var test_integers = [{ N: 5, I: 10, - buffer: new Buffer([10]) + buffer: Buffer.from([10]) }, { N: 0, I: 10, - buffer: new Buffer([10]) + buffer: Buffer.from([10]) }, { N: 5, I: 1337, - buffer: new Buffer([31, 128 + 26, 10]) + buffer: Buffer.from([31, 128 + 26, 10]) }, { N: 0, I: 1337, - buffer: new Buffer([128 + 57, 10]) + buffer: Buffer.from([128 + 57, 10]) }]; var test_strings = [{ string: 'www.foo.com', - buffer: new Buffer('89f1e3c2f29ceb90f4ff', 'hex') + buffer: Buffer.from('89f1e3c2f29ceb90f4ff', 'hex') }, { string: 'éáűőúöüó€', - buffer: new Buffer('13c3a9c3a1c5b1c591c3bac3b6c3bcc3b3e282ac', 'hex') + buffer: Buffer.from('13c3a9c3a1c5b1c591c3bac3b6c3bcc3b3e282ac', 'hex') }]; test_huffman_request = { @@ -85,7 +85,7 @@ var test_headers = [{ contextUpdate: false, newMaxSize: 0 }, - buffer: new Buffer('82', 'hex') + buffer: Buffer.from('82', 'hex') }, { // index header: { @@ -96,7 +96,7 @@ var test_headers = [{ contextUpdate: false, newMaxSize: 0 }, - buffer: new Buffer('86', 'hex') + buffer: Buffer.from('86', 'hex') }, { // index header: { @@ -107,7 +107,7 @@ var test_headers = [{ contextUpdate: false, newMaxSize: 0 }, - buffer: new Buffer('84', 'hex') + buffer: Buffer.from('84', 'hex') }, { // literal w/index, name index header: { @@ -118,7 +118,7 @@ var test_headers = [{ contextUpdate: false, newMaxSize: 0 }, - buffer: new Buffer('41' + '89f1e3c2f29ceb90f4ff', 'hex') + buffer: Buffer.from('41' + '89f1e3c2f29ceb90f4ff', 'hex') }, { // indexed header: { @@ -129,7 +129,7 @@ var test_headers = [{ contextUpdate: false, newMaxSize: 0 }, - buffer: new Buffer('82', 'hex') + buffer: Buffer.from('82', 'hex') }, { // indexed header: { @@ -140,7 +140,7 @@ var test_headers = [{ contextUpdate: false, newMaxSize: 0 }, - buffer: new Buffer('87', 'hex') + buffer: Buffer.from('87', 'hex') }, { // indexed header: { @@ -151,7 +151,7 @@ var test_headers = [{ contextUpdate: false, newMaxSize: 0 }, - buffer: new Buffer('84', 'hex') + buffer: Buffer.from('84', 'hex') }, { // literal w/index, name index header: { @@ -162,7 +162,7 @@ var test_headers = [{ contextUpdate: false, newMaxSize: 0 }, - buffer: new Buffer('41' + '89f1e3c2f18ec5c87a7f', 'hex') + buffer: Buffer.from('41' + '89f1e3c2f18ec5c87a7f', 'hex') }, { // literal w/index, name index header: { @@ -173,7 +173,7 @@ var test_headers = [{ contextUpdate: false, newMaxSize: 0 }, - buffer: new Buffer('58' + '86a8eb10649cbf', 'hex') + buffer: Buffer.from('58' + '86a8eb10649cbf', 'hex') }, { // index header: { @@ -184,7 +184,7 @@ var test_headers = [{ contextUpdate: false, newMaxSize: 0 }, - buffer: new Buffer('82', 'hex') + buffer: Buffer.from('82', 'hex') }, { // index header: { @@ -195,7 +195,7 @@ var test_headers = [{ contextUpdate: false, newMaxSize: 0 }, - buffer: new Buffer('87', 'hex') + buffer: Buffer.from('87', 'hex') }, { // literal w/index, name index header: { @@ -206,7 +206,7 @@ var test_headers = [{ contextUpdate: false, newMaxSize: 0 }, - buffer: new Buffer('44' + '8b6096a127a56ac699d72211', 'hex') + buffer: Buffer.from('44' + '8b6096a127a56ac699d72211', 'hex') }, { // index header: { @@ -217,7 +217,7 @@ var test_headers = [{ contextUpdate: false, newMaxSize: 0 }, - buffer: new Buffer('C0', 'hex') + buffer: Buffer.from('C0', 'hex') }, { // literal w/index, new name & value header: { @@ -228,7 +228,7 @@ var test_headers = [{ contextUpdate: false, newMaxSize: 0 }, - buffer: new Buffer('40' + '8825a849e95ba97d7f' + '8925a849e95bb8e8b4bf', 'hex') + buffer: Buffer.from('40' + '8825a849e95ba97d7f' + '8925a849e95bb8e8b4bf', 'hex') }, { // index header: { @@ -239,7 +239,7 @@ var test_headers = [{ contextUpdate: false, newMaxSize: 0 }, - buffer: new Buffer('82', 'hex') + buffer: Buffer.from('82', 'hex') }, { // index header: { @@ -250,7 +250,7 @@ var test_headers = [{ contextUpdate: false, newMaxSize: 0 }, - buffer: new Buffer('87', 'hex') + buffer: Buffer.from('87', 'hex') }, { // index header: { @@ -261,7 +261,7 @@ var test_headers = [{ contextUpdate: false, newMaxSize: 0 }, - buffer: new Buffer('BF', 'hex') + buffer: Buffer.from('BF', 'hex') }, { // index header: { @@ -272,7 +272,7 @@ var test_headers = [{ contextUpdate: false, newMaxSize: 0 }, - buffer: new Buffer('C2', 'hex') + buffer: Buffer.from('C2', 'hex') }, { // index header: { @@ -283,7 +283,7 @@ var test_headers = [{ contextUpdate: false, newMaxSize: 0 }, - buffer: new Buffer('C1', 'hex') + buffer: Buffer.from('C1', 'hex') }, { // index header: { @@ -294,7 +294,7 @@ var test_headers = [{ contextUpdate: false, newMaxSize: 0 }, - buffer: new Buffer('BE', 'hex') + buffer: Buffer.from('BE', 'hex') }, { // Literal w/o index, name index header: { @@ -305,7 +305,7 @@ var test_headers = [{ contextUpdate: false, newMaxSize: 0 }, - buffer: new Buffer('07' + '86f138d25ee5b3', 'hex') + buffer: Buffer.from('07' + '86f138d25ee5b3', 'hex') }, { // Literal w/o index, new name & value header: { @@ -316,7 +316,7 @@ var test_headers = [{ contextUpdate: false, newMaxSize: 0 }, - buffer: new Buffer('00' + '8294e7' + '03626172', 'hex') + buffer: Buffer.from('00' + '8294e7' + '03626172', 'hex') }, { // Literal never indexed, name index header: { @@ -327,7 +327,7 @@ var test_headers = [{ contextUpdate: false, newMaxSize: 0 }, - buffer: new Buffer('17' + '86f138d25ee5b3', 'hex') + buffer: Buffer.from('17' + '86f138d25ee5b3', 'hex') }, { // Literal never indexed, new name & value header: { @@ -338,7 +338,7 @@ var test_headers = [{ contextUpdate: false, newMaxSize: 0 }, - buffer: new Buffer('10' + '8294e7' + '03626172', 'hex') + buffer: Buffer.from('10' + '8294e7' + '03626172', 'hex') }, { header: { name: -1, @@ -348,7 +348,7 @@ var test_headers = [{ contextUpdate: true, newMaxSize: 100 }, - buffer: new Buffer('3F45', 'hex') + buffer: Buffer.from('3F45', 'hex') }]; var test_header_sets = [{ @@ -398,12 +398,12 @@ describe('compressor.js', function() { var table = HuffmanTable.huffmanTable; for (var decoded in test_huffman_request) { var encoded = test_huffman_request[decoded]; - expect(table.encode(new Buffer(decoded)).toString('hex')).to.equal(encoded); + expect(table.encode(Buffer.from(decoded)).toString('hex')).to.equal(encoded); } table = HuffmanTable.huffmanTable; for (decoded in test_huffman_response) { encoded = test_huffman_response[decoded]; - expect(table.encode(new Buffer(decoded)).toString('hex')).to.equal(encoded); + expect(table.encode(Buffer.from(decoded)).toString('hex')).to.equal(encoded); } }); }); @@ -412,12 +412,12 @@ describe('compressor.js', function() { var table = HuffmanTable.huffmanTable; for (var decoded in test_huffman_request) { var encoded = test_huffman_request[decoded]; - expect(table.decode(new Buffer(encoded, 'hex')).toString()).to.equal(decoded); + expect(table.decode(Buffer.from(encoded, 'hex')).toString()).to.equal(decoded); } table = HuffmanTable.huffmanTable; for (decoded in test_huffman_response) { encoded = test_huffman_response[decoded]; - expect(table.decode(new Buffer(encoded, 'hex')).toString()).to.equal(decoded); + expect(table.decode(Buffer.from(encoded, 'hex')).toString()).to.equal(decoded); } }); }); @@ -509,12 +509,12 @@ describe('compressor.js', function() { flags: { END_HEADERS: false }, - data: new Buffer(5) + data: Buffer.alloc(5) }); decompressor.write({ type: 'DATA', flags: {}, - data: new Buffer(5) + data: Buffer.alloc(5) }); expect(error_occured).to.be.equal(true); }); @@ -564,7 +564,7 @@ describe('compressor.js', function() { while (Math.random() > 0.1) { buffer.push(Math.floor(Math.random() * 256)) } - buffer = new Buffer(buffer); + buffer = Buffer.from(buffer); var table = HuffmanTable.huffmanTable; var result = table.decode(table.encode(buffer)); expect(result).to.deep.equal(buffer); diff --git a/testing/xpcshell/node-http2/test/connection.js b/testing/xpcshell/node-http2/test/connection.js index 2c68857f7fe3..21785d620a2b 100644 --- a/testing/xpcshell/node-http2/test/connection.js +++ b/testing/xpcshell/node-http2/test/connection.js @@ -73,7 +73,7 @@ describe('connection.js', function() { flags: { 'PONG': true }, - data: new Buffer(8) + data: Buffer.alloc(8) }); }); }); @@ -102,11 +102,11 @@ describe('connection.js', function() { ':method': 'GET', ':path': '/' }; - var request_data = new Buffer(0); + var request_data = Buffer.alloc(0); var response_headers = { ':status': '200' }; - var response_data = new Buffer('12345678', 'hex'); + var response_data = Buffer.from('12345678', 'hex'); // Setting up server s.on('stream', function(server_stream) { @@ -140,8 +140,8 @@ describe('connection.js', function() { var response_headers = { ':status': '200' }; var push_request_headers = { ':method': 'get', ':path': '/x' }; var push_response_headers = { ':status': '200' }; - var response_content = new Buffer(10); - var push_content = new Buffer(10); + var response_content = Buffer.alloc(10); + var push_content = Buffer.alloc(10); done = util.callNTimes(5, done); diff --git a/testing/xpcshell/node-http2/test/flow.js b/testing/xpcshell/node-http2/test/flow.js index a077c6845172..a64ab010c9e2 100644 --- a/testing/xpcshell/node-http2/test/flow.js +++ b/testing/xpcshell/node-http2/test/flow.js @@ -96,7 +96,7 @@ describe('flow.js', function() { expect(flow.read()).to.equal(dataFrame); }); it('should also split DATA frames when needed', function() { - var buffer = new Buffer(10); + var buffer = Buffer.alloc(10); var dataFrame = { type: 'DATA', flags: {}, stream: util.random(0, 100), data: buffer }; flow._send = util.noop; flow._window = 5; @@ -132,7 +132,7 @@ describe('flow.js', function() { callback(); }; - var buffer = new Buffer(util.random(10, 100)); + var buffer = Buffer.alloc(util.random(10, 100)); flow.write({ type: 'DATA', flags: {}, data: buffer }); flow.once('readable', function() { expect(flow.read()).to.be.deep.equal({ @@ -163,10 +163,10 @@ describe('flow.js', function() { var input = []; flow1._send = function _send() { if (input.length >= frameNumber) { - this.push({ type: 'DATA', flags: { END_STREAM: true }, data: new Buffer(0) }); + this.push({ type: 'DATA', flags: { END_STREAM: true }, data: Buffer.alloc(0) }); this.push(null); } else { - var buffer = new Buffer(util.random(1000, 100000)); + var buffer = Buffer.allocUnsafe(util.random(1000, 100000)); input.push(buffer); this.push({ type: 'DATA', flags: {}, data: buffer }); } @@ -207,10 +207,10 @@ describe('flow.js', function() { var input = []; flow1._send = function _send() { if (input.length >= frameNumber) { - this.push({ type: 'DATA', flags: { END_STREAM: true }, data: new Buffer(0) }); + this.push({ type: 'DATA', flags: { END_STREAM: true }, data: Buffer.alloc(0) }); this.push(null); } else { - var buffer = new Buffer(util.random(1000, 100000)); + var buffer = Buffer.allocUnsafe(util.random(1000, 100000)); input.push(buffer); this.push({ type: 'DATA', flags: {}, data: buffer }); } diff --git a/testing/xpcshell/node-http2/test/framer.js b/testing/xpcshell/node-http2/test/framer.js index 59cc711ba023..e2eb69366547 100644 --- a/testing/xpcshell/node-http2/test/framer.js +++ b/testing/xpcshell/node-http2/test/framer.js @@ -26,10 +26,10 @@ var test_frames = [{ PADDED: false }, stream: 10, - data: new Buffer('12345678', 'hex') + data: Buffer.from('12345678', 'hex') }, // length + type + flags + stream + content - buffer: new Buffer('000004' + '00' + '00' + '0000000A' + '12345678', 'hex') + buffer: Buffer.from('000004' + '00' + '00' + '0000000A' + '12345678', 'hex') }, { frame: { @@ -38,9 +38,9 @@ var test_frames = [{ PADDED: false, RESERVED5: false, PRIORITY: false }, stream: 15, - data: new Buffer('12345678', 'hex') + data: Buffer.from('12345678', 'hex') }, - buffer: new Buffer('000004' + '01' + '00' + '0000000F' + '12345678', 'hex') + buffer: Buffer.from('000004' + '01' + '00' + '0000000F' + '12345678', 'hex') }, { frame: { @@ -52,9 +52,9 @@ var test_frames = [{ priorityWeight: 5, exclusiveDependency: false, - data: new Buffer('12345678', 'hex') + data: Buffer.from('12345678', 'hex') }, - buffer: new Buffer('000009' + '01' + '20' + '0000000F' + '0000000A' + '05' + '12345678', 'hex') + buffer: Buffer.from('000009' + '01' + '20' + '0000000F' + '0000000A' + '05' + '12345678', 'hex') }, { @@ -67,9 +67,9 @@ var test_frames = [{ priorityWeight: 5, exclusiveDependency: true, - data: new Buffer('12345678', 'hex') + data: Buffer.from('12345678', 'hex') }, - buffer: new Buffer('000009' + '01' + '20' + '0000000F' + '8000000A' + '05' + '12345678', 'hex') + buffer: Buffer.from('000009' + '01' + '20' + '0000000F' + '8000000A' + '05' + '12345678', 'hex') }, { frame: { @@ -81,7 +81,7 @@ var test_frames = [{ priorityWeight: 5, exclusiveDependency: false }, - buffer: new Buffer('000005' + '02' + '00' + '0000000A' + '00000009' + '05', 'hex') + buffer: Buffer.from('000005' + '02' + '00' + '0000000A' + '00000009' + '05', 'hex') }, { frame: { @@ -93,7 +93,7 @@ var test_frames = [{ priorityWeight: 5, exclusiveDependency: true }, - buffer: new Buffer('000005' + '02' + '00' + '0000000A' + '80000009' + '05', 'hex') + buffer: Buffer.from('000005' + '02' + '00' + '0000000A' + '80000009' + '05', 'hex') }, { frame: { @@ -103,7 +103,7 @@ var test_frames = [{ error: 'INTERNAL_ERROR' }, - buffer: new Buffer('000004' + '03' + '00' + '0000000A' + '00000002', 'hex') + buffer: Buffer.from('000004' + '03' + '00' + '0000000A' + '00000002', 'hex') }, { frame: { @@ -119,7 +119,7 @@ var test_frames = [{ SETTINGS_MAX_FRAME_SIZE: 0x00010000 } }, - buffer: new Buffer('00001E' + '04' + '00' + '0000000A' + '0001' + '12345678' + + buffer: Buffer.from('00001E' + '04' + '00' + '0000000A' + '0001' + '12345678' + '0002' + '00000001' + '0003' + '01234567' + '0004' + '89ABCDEF' + @@ -133,9 +133,9 @@ var test_frames = [{ stream: 15, promised_stream: 3, - data: new Buffer('12345678', 'hex') + data: Buffer.from('12345678', 'hex') }, - buffer: new Buffer('000008' + '05' + '00' + '0000000F' + '00000003' + '12345678', 'hex') + buffer: Buffer.from('000008' + '05' + '00' + '0000000F' + '00000003' + '12345678', 'hex') }, { frame: { @@ -143,9 +143,9 @@ var test_frames = [{ flags: { ACK: false }, stream: 15, - data: new Buffer('1234567887654321', 'hex') + data: Buffer.from('1234567887654321', 'hex') }, - buffer: new Buffer('000008' + '06' + '00' + '0000000F' + '1234567887654321', 'hex') + buffer: Buffer.from('000008' + '06' + '00' + '0000000F' + '1234567887654321', 'hex') }, { frame: { @@ -156,7 +156,7 @@ var test_frames = [{ last_stream: 0x12345678, error: 'PROTOCOL_ERROR' }, - buffer: new Buffer('000008' + '07' + '00' + '0000000A' + '12345678' + '00000001', 'hex') + buffer: Buffer.from('000008' + '07' + '00' + '0000000A' + '12345678' + '00000001', 'hex') }, { frame: { @@ -166,17 +166,17 @@ var test_frames = [{ window_size: 0x12345678 }, - buffer: new Buffer('000004' + '08' + '00' + '0000000A' + '12345678', 'hex') + buffer: Buffer.from('000004' + '08' + '00' + '0000000A' + '12345678', 'hex') }, { frame: { type: 'CONTINUATION', flags: { RESERVED1: false, RESERVED2: false, END_HEADERS: true }, stream: 10, - data: new Buffer('12345678', 'hex') + data: Buffer.from('12345678', 'hex') }, // length + type + flags + stream + content - buffer: new Buffer('000004' + '09' + '04' + '0000000A' + '12345678', 'hex') + buffer: Buffer.from('000004' + '09' + '04' + '0000000A' + '12345678', 'hex') }, { frame: { type: 'ALTSVC', @@ -189,7 +189,7 @@ var test_frames = [{ host: "altsvc.example.com", origin: "" }, - buffer: new Buffer(new Buffer('00002B' + '0A' + '00' + '00000000' + '0000', 'hex') + new Buffer('h2="altsvc.example.com:4443"; ma=31536000', 'ascii')) + buffer: Buffer.from(Buffer.from('00002B' + '0A' + '00' + '00000000' + '0000', 'hex') + Buffer.from('h2="altsvc.example.com:4443"; ma=31536000', 'ascii')) }, { frame: { type: 'ALTSVC', @@ -202,7 +202,7 @@ var test_frames = [{ host: "altsvc.example.com", origin: "https://onlyme.example.com" }, - buffer: new Buffer(new Buffer('000045' + '0A' + '00' + '00000000' + '001A', 'hex') + new Buffer('https://onlyme.example.comh2="altsvc.example.com:4443"; ma=31536000', 'ascii')) + buffer: Buffer.from(Buffer.from('000045' + '0A' + '00' + '00000000' + '001A', 'hex') + Buffer.from('https://onlyme.example.comh2="altsvc.example.com:4443"; ma=31536000', 'ascii')) }, { frame: { @@ -210,7 +210,7 @@ var test_frames = [{ flags: { }, stream: 10 }, - buffer: new Buffer('000000' + '0B' + '00' + '0000000A', 'hex') + buffer: Buffer.from('000000' + '0B' + '00' + '0000000A', 'hex') }]; var deserializer_test_frames = test_frames.slice(0); @@ -220,10 +220,10 @@ var padded_test_frames = [{ flags: { END_STREAM: false, RESERVED2: false, RESERVED4: false, PADDED: true }, stream: 10, - data: new Buffer('12345678', 'hex') + data: Buffer.from('12345678', 'hex') }, // length + type + flags + stream + pad length + content + padding - buffer: new Buffer('00000B' + '00' + '08' + '0000000A' + '06' + '12345678' + '000000000000', 'hex') + buffer: Buffer.from('00000B' + '00' + '08' + '0000000A' + '06' + '12345678' + '000000000000', 'hex') }, { frame: { @@ -232,10 +232,10 @@ var padded_test_frames = [{ PADDED: true, RESERVED5: false, PRIORITY: false }, stream: 15, - data: new Buffer('12345678', 'hex') + data: Buffer.from('12345678', 'hex') }, // length + type + flags + stream + pad length + data + padding - buffer: new Buffer('00000B' + '01' + '08' + '0000000F' + '06' + '12345678' + '000000000000', 'hex') + buffer: Buffer.from('00000B' + '01' + '08' + '0000000F' + '06' + '12345678' + '000000000000', 'hex') }, { frame: { @@ -247,10 +247,10 @@ var padded_test_frames = [{ priorityWeight: 5, exclusiveDependency: false, - data: new Buffer('12345678', 'hex') + data: Buffer.from('12345678', 'hex') }, // length + type + flags + stream + pad length + priority dependency + priority weight + data + padding - buffer: new Buffer('000010' + '01' + '28' + '0000000F' + '06' + '0000000A' + '05' + '12345678' + '000000000000', 'hex') + buffer: Buffer.from('000010' + '01' + '28' + '0000000F' + '06' + '0000000A' + '05' + '12345678' + '000000000000', 'hex') }, { frame: { @@ -262,10 +262,10 @@ var padded_test_frames = [{ priorityWeight: 5, exclusiveDependency: true, - data: new Buffer('12345678', 'hex') + data: Buffer.from('12345678', 'hex') }, // length + type + flags + stream + pad length + priority dependency + priority weight + data + padding - buffer: new Buffer('000010' + '01' + '28' + '0000000F' + '06' + '8000000A' + '05' + '12345678' + '000000000000', 'hex') + buffer: Buffer.from('000010' + '01' + '28' + '0000000F' + '06' + '8000000A' + '05' + '12345678' + '000000000000', 'hex') }, { frame: { @@ -275,10 +275,10 @@ var padded_test_frames = [{ stream: 15, promised_stream: 3, - data: new Buffer('12345678', 'hex') + data: Buffer.from('12345678', 'hex') }, // length + type + flags + stream + pad length + promised stream + data + padding - buffer: new Buffer('00000F' + '05' + '08' + '0000000F' + '06' + '00000003' + '12345678' + '000000000000', 'hex') + buffer: Buffer.from('00000F' + '05' + '08' + '0000000F' + '06' + '00000003' + '12345678' + '000000000000', 'hex') }]; for (var idx = 0; idx < padded_test_frames.length; idx++) { @@ -322,7 +322,7 @@ describe('framer.js', function() { for (var i = 0; i < test_frames.length; i++) { var test = test_frames[i]; stream.write(test.frame); - var chunk, buffer = new Buffer(0); + var chunk, buffer = Buffer.alloc(0); while (chunk = stream.read()) { buffer = util.concat([buffer, chunk]); } @@ -384,7 +384,7 @@ describe('framer.js', function() { describe('`frame`', function() { var format = framer.serializers.frame; it('should assign a unique ID to each frame', function() { - var frame1 = { type: 'DATA', data: new Buffer(10) }; + var frame1 = { type: 'DATA', data: Buffer.alloc(10) }; var frame2 = { type: 'PRIORITY', priority: 1 }; expect(format(frame1).id).to.be.equal(format(frame1)); expect(format(frame2).id).to.be.equal(format(frame2)); diff --git a/testing/xpcshell/node-http2/test/stream.js b/testing/xpcshell/node-http2/test/stream.js index 90e0ef64b0f5..9e60932b8e1d 100644 --- a/testing/xpcshell/node-http2/test/stream.js +++ b/testing/xpcshell/node-http2/test/stream.js @@ -105,25 +105,25 @@ var example_frames = [ { type: 'WINDOW_UPDATE', flags: {}, settings: {} }, { type: 'RST_STREAM', flags: {}, error: 'CANCEL' }, { type: 'HEADERS', flags: {}, headers: {}, priority: undefined }, - { type: 'DATA', flags: {}, data: new Buffer(5) }, + { type: 'DATA', flags: {}, data: Buffer.alloc(5) }, { type: 'PUSH_PROMISE', flags: {}, headers: {}, promised_stream: new Stream(util.log, null) } ]; var invalid_incoming_frames = { IDLE: [ - { type: 'DATA', flags: {}, data: new Buffer(5) }, + { type: 'DATA', flags: {}, data: Buffer.alloc(5) }, { type: 'WINDOW_UPDATE', flags: {}, settings: {} }, { type: 'PUSH_PROMISE', flags: {}, headers: {} }, { type: 'RST_STREAM', flags: {}, error: 'CANCEL' } ], RESERVED_LOCAL: [ - { type: 'DATA', flags: {}, data: new Buffer(5) }, + { type: 'DATA', flags: {}, data: Buffer.alloc(5) }, { type: 'HEADERS', flags: {}, headers: {}, priority: undefined }, { type: 'PUSH_PROMISE', flags: {}, headers: {} }, { type: 'WINDOW_UPDATE', flags: {}, settings: {} } ], RESERVED_REMOTE: [ - { type: 'DATA', flags: {}, data: new Buffer(5) }, + { type: 'DATA', flags: {}, data: Buffer.alloc(5) }, { type: 'PUSH_PROMISE', flags: {}, headers: {} }, { type: 'WINDOW_UPDATE', flags: {}, settings: {} } ], @@ -132,7 +132,7 @@ var invalid_incoming_frames = { HALF_CLOSED_LOCAL: [ ], HALF_CLOSED_REMOTE: [ - { type: 'DATA', flags: {}, data: new Buffer(5) }, + { type: 'DATA', flags: {}, data: Buffer.alloc(5) }, { type: 'HEADERS', flags: {}, headers: {}, priority: undefined }, { type: 'PUSH_PROMISE', flags: {}, headers: {} } ] @@ -140,17 +140,17 @@ var invalid_incoming_frames = { var invalid_outgoing_frames = { IDLE: [ - { type: 'DATA', flags: {}, data: new Buffer(5) }, + { type: 'DATA', flags: {}, data: Buffer.alloc(5) }, { type: 'WINDOW_UPDATE', flags: {}, settings: {} }, { type: 'PUSH_PROMISE', flags: {}, headers: {} } ], RESERVED_LOCAL: [ - { type: 'DATA', flags: {}, data: new Buffer(5) }, + { type: 'DATA', flags: {}, data: Buffer.alloc(5) }, { type: 'PUSH_PROMISE', flags: {}, headers: {} }, { type: 'WINDOW_UPDATE', flags: {}, settings: {} } ], RESERVED_REMOTE: [ - { type: 'DATA', flags: {}, data: new Buffer(5) }, + { type: 'DATA', flags: {}, data: Buffer.alloc(5) }, { type: 'HEADERS', flags: {}, headers: {}, priority: undefined }, { type: 'PUSH_PROMISE', flags: {}, headers: {} }, { type: 'WINDOW_UPDATE', flags: {}, settings: {} } @@ -158,7 +158,7 @@ var invalid_outgoing_frames = { OPEN: [ ], HALF_CLOSED_LOCAL: [ - { type: 'DATA', flags: {}, data: new Buffer(5) }, + { type: 'DATA', flags: {}, data: Buffer.alloc(5) }, { type: 'HEADERS', flags: {}, headers: {}, priority: undefined }, { type: 'PUSH_PROMISE', flags: {}, headers: {} } ], @@ -167,7 +167,7 @@ var invalid_outgoing_frames = { CLOSED: [ { type: 'WINDOW_UPDATE', flags: {}, settings: {} }, { type: 'HEADERS', flags: {}, headers: {}, priority: undefined }, - { type: 'DATA', flags: {}, data: new Buffer(5) }, + { type: 'DATA', flags: {}, data: Buffer.alloc(5) }, { type: 'PUSH_PROMISE', flags: {}, headers: {}, promised_stream: new Stream(util.log, null) } ] }; @@ -260,11 +260,11 @@ describe('stream.js', function() { { wait : 5 }, { method : { name: 'end', arguments: [] } }, { event : { name: 'state', data: ['HALF_CLOSED_LOCAL'] } }, - { outgoing: { type: 'DATA', flags: { END_STREAM: true }, data: new Buffer(0) } }, + { outgoing: { type: 'DATA', flags: { END_STREAM: true }, data: Buffer.alloc(0) } }, { wait : 10 }, { incoming: { type: 'HEADERS', flags: { }, headers: { ':status': 200 } } }, - { incoming: { type: 'DATA' , flags: { END_STREAM: true }, data: new Buffer(5) } }, + { incoming: { type: 'DATA' , flags: { END_STREAM: true }, data: Buffer.alloc(5) } }, { event : { name: 'headers', data: [{ ':status': 200 }] } }, { event : { name: 'state', data: ['CLOSED'] } }, @@ -274,15 +274,15 @@ describe('stream.js', function() { }); describe('answering request', function() { it('should trigger the appropriate state transitions and outgoing frames', function(done) { - var payload = new Buffer(5); + var payload = Buffer.alloc(5); execute_sequence([ { incoming: { type: 'HEADERS', flags: { }, headers: { ':path': '/' } } }, { event : { name: 'state', data: ['OPEN'] } }, { event : { name: 'headers', data: [{ ':path': '/' }] } }, { wait : 5 }, - { incoming: { type: 'DATA', flags: { }, data: new Buffer(5) } }, - { incoming: { type: 'DATA', flags: { END_STREAM: true }, data: new Buffer(10) } }, + { incoming: { type: 'DATA', flags: { }, data: Buffer.alloc(5) } }, + { incoming: { type: 'DATA', flags: { END_STREAM: true }, data: Buffer.alloc(10) } }, { event : { name: 'state', data: ['HALF_CLOSED_REMOTE'] } }, { wait : 5 }, @@ -300,7 +300,7 @@ describe('stream.js', function() { }); describe('sending push stream', function() { it('should trigger the appropriate state transitions and outgoing frames', function(done) { - var payload = new Buffer(5); + var payload = Buffer.alloc(5); var pushStream; execute_sequence([ @@ -348,7 +348,7 @@ describe('stream.js', function() { }); describe('receiving push stream', function() { it('should trigger the appropriate state transitions and outgoing frames', function(done) { - var payload = new Buffer(5); + var payload = Buffer.alloc(5); var original_stream = createStream(); var promised_stream = createStream(); diff --git a/testing/xpcshell/node-http2/test/util.js b/testing/xpcshell/node-http2/test/util.js index 52c6a1be3696..c612e38b14be 100644 --- a/testing/xpcshell/node-http2/test/util.js +++ b/testing/xpcshell/node-http2/test/util.js @@ -63,7 +63,7 @@ exports.concat = function concat(buffers) { size += buffers[i].length; } - var concatenated = new Buffer(size); + var concatenated = Buffer.alloc(size); for (var cursor = 0, j = 0; j < buffers.length; cursor += buffers[j].length, j++) { buffers[j].copy(concatenated, cursor); } diff --git a/testing/xpcshell/node-ip/lib/ip.js b/testing/xpcshell/node-ip/lib/ip.js index c1799a8c50f4..a66a2555c665 100644 --- a/testing/xpcshell/node-ip/lib/ip.js +++ b/testing/xpcshell/node-ip/lib/ip.js @@ -10,7 +10,7 @@ ip.toBuffer = function(ip, buff, offset) { var result; if (this.isV4Format(ip)) { - result = buff || new Buffer(offset + 4); + result = buff || Buffer.alloc(offset + 4); ip.split(/\./g).map(function(byte) { result[offset++] = parseInt(byte, 10) & 0xff; }); @@ -45,7 +45,7 @@ ip.toBuffer = function(ip, buff, offset) { sections.splice.apply(sections, argv); } - result = buff || new Buffer(offset + 16); + result = buff || Buffer.alloc(offset + 16); for (i = 0; i < sections.length; i++) { var word = parseInt(sections[i], 16); result[offset++] = (word >> 8) & 0xff; @@ -110,7 +110,7 @@ ip.fromPrefixLen = function(prefixlen, family) { if (family === 'ipv6') { len = 16; } - var buff = new Buffer(len); + var buff = Buffer.alloc(len); for (var i = 0, n = buff.length; i < n; ++i) { var bits = 8; @@ -129,7 +129,7 @@ ip.mask = function(addr, mask) { addr = ip.toBuffer(addr); mask = ip.toBuffer(mask); - var result = new Buffer(Math.max(addr.length, mask.length)); + var result = Buffer.alloc(Math.max(addr.length, mask.length)); var i = 0; // Same protocol - do bitwise and diff --git a/testing/xpcshell/node-ip/test/api-test.js b/testing/xpcshell/node-ip/test/api-test.js index 2e390f986d0b..1af09a4f6f2c 100644 --- a/testing/xpcshell/node-ip/test/api-test.js +++ b/testing/xpcshell/node-ip/test/api-test.js @@ -14,7 +14,7 @@ describe('IP library for node.js', function() { }); it('should convert to buffer IPv4 address in-place', function() { - var buf = new Buffer(128); + var buf = Buffer.alloc(128); var offset = 64; ip.toBuffer('127.0.0.1', buf, offset); assert.equal(buf.toString('hex', offset, offset + 4), '7f000001'); @@ -30,7 +30,7 @@ describe('IP library for node.js', function() { }); it('should convert to buffer IPv6 address in-place', function() { - var buf = new Buffer(128); + var buf = Buffer.alloc(128); var offset = 64; ip.toBuffer('::1', buf, offset); assert(/(00){15,15}01/.test(buf.toString('hex', offset, offset + 16)));