Skip to content

Remove fallbacks for unsupported Node versions #1304

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Jun 8, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 0 additions & 8 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,6 @@ addons:

matrix:
include:
- node_js: "0.10"
addons:
postgresql: "9.6"
env: []
- node_js: "0.12"
addons:
postgresql: "9.6"
env: []
- node_js: "4"
addons:
postgresql: "9.6"
Expand Down
2 changes: 1 addition & 1 deletion lib/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ Client.prototype.connect = function(callback) {
//password request handling
con.on('authenticationMD5Password', checkPgPass(function(msg) {
var inner = Client.md5(self.password + self.user);
var outer = Client.md5(Buffer.concat([new Buffer(inner), msg.salt]));
var outer = Client.md5(Buffer.concat([Buffer.from(inner), msg.salt]));
var md5password = "md5" + outer;
con.password(md5password);
}));
Expand Down
21 changes: 3 additions & 18 deletions lib/connection.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,21 +13,6 @@ var util = require('util');
var Writer = require('buffer-writer');
var Reader = require('packet-reader');

var indexOf =
'indexOf' in Buffer.prototype ?
function indexOf(buffer, value, start) {
return buffer.indexOf(value, start);
} :
function indexOf(buffer, value, start) {
for (var i = start, len = buffer.length; i < len; i++) {
if (buffer[i] === value) {
return i;
}
}

return -1;
};

var TEXT_MODE = 0;
var BINARY_MODE = 1;
var Connection = function(config) {
Expand Down Expand Up @@ -311,7 +296,7 @@ Connection.prototype.execute = function(config, more) {
this._send(0x45, more);
};

var emptyBuffer = Buffer(0);
var emptyBuffer = Buffer.alloc(0);

Connection.prototype.flush = function() {
//0x48 = 'H'
Expand Down Expand Up @@ -450,7 +435,7 @@ Connection.prototype.parseR = function(buffer, length) {
code = this.parseInt32(buffer);
if(code === 5) { //md5 required
msg.name = 'authenticationMD5Password';
msg.salt = new Buffer(4);
msg.salt = Buffer.alloc(4);
buffer.copy(msg.salt, 0, this.offset, this.offset + 4);
this.offset += 4;
return msg;
Expand Down Expand Up @@ -665,7 +650,7 @@ Connection.prototype.readBytes = function(buffer, length) {

Connection.prototype.parseCString = function(buffer) {
var start = this.offset;
var end = indexOf(buffer, 0, start);
var end = buffer.indexOf(0, start);
this.offset = end + 1;
return buffer.toString(this.encoding, start, end);
};
Expand Down
4 changes: 1 addition & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,7 @@
"async": "0.9.0",
"co": "4.6.0",
"jshint": "2.5.2",
"lodash": "4.13.1",
"pg-copy-streams": "0.3.0",
"promise-polyfill": "5.2.1"
"pg-copy-streams": "0.3.0"
},
"minNativeVersion": "1.7.0",
"scripts": {
Expand Down
10 changes: 5 additions & 5 deletions test/buffer-list.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ p.add = function(buffer, front) {
};

p.addInt16 = function(val, front) {
return this.add(Buffer([(val >>> 8),(val >>> 0)]),front);
return this.add(Buffer.from([(val >>> 8),(val >>> 0)]),front);
};

p.getByteLength = function(initial) {
Expand All @@ -19,7 +19,7 @@ p.getByteLength = function(initial) {
};

p.addInt32 = function(val, first) {
return this.add(Buffer([
return this.add(Buffer.from([
(val >>> 24 & 0xFF),
(val >>> 16 & 0xFF),
(val >>> 8 & 0xFF),
Expand All @@ -29,14 +29,14 @@ p.addInt32 = function(val, first) {

p.addCString = function(val, front) {
var len = Buffer.byteLength(val);
var buffer = new Buffer(len+1);
var buffer = Buffer.alloc(len+1);
buffer.write(val);
buffer[len] = 0;
return this.add(buffer, front);
};

p.addChar = function(char, first) {
return this.add(Buffer(char,'utf8'), first);
return this.add(Buffer.from(char,'utf8'), first);
};

p.join = function(appendLength, char) {
Expand All @@ -49,7 +49,7 @@ p.join = function(appendLength, char) {
this.addChar(char, true);
length++;
}
var result = Buffer(length);
var result = Buffer.alloc(length);
var index = 0;
this.buffers.forEach(function(buffer) {
buffer.copy(result, index, 0);
Expand Down
5 changes: 0 additions & 5 deletions test/integration/client/query-as-promise-tests.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@
var helper = require(__dirname + '/../test-helper');
var pg = helper.pg;
var semver = require('semver')

if (semver.lt(process.version, '0.12.0')) {
return console.log('promises are not supported in node < v0.10')
}

process.on('unhandledRejection', function(e) {
console.error(e, e.stack)
Expand Down
3 changes: 1 addition & 2 deletions test/integration/connection-pool/idle-timeout-tests.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
var helper = require(__dirname + '/test-helper');
var _ = require('lodash')

const config = _.extend({ }, helper.config, { idleTimeoutMillis: 50 })
const config = Object.assign({ }, helper.config, { idleTimeoutMillis: 50 })

test('idle timeout', function() {
helper.pg.connect(config, assert.calls(function(err, client, done) {
Expand Down
28 changes: 0 additions & 28 deletions test/integration/connection-pool/yield-support-body.js

This file was deleted.

33 changes: 28 additions & 5 deletions test/integration/connection-pool/yield-support-tests.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,28 @@
var semver = require('semver')
if (semver.lt(process.version, '1.0.0')) {
return console.log('yield is not supported in node <= v0.12')
}
require('./yield-support-body')
var helper = require('./test-helper')
var co = require('co')

var tid = setTimeout(function() {
throw new Error('Tests did not complete in time')
}, 1000)

co(function * () {
var client = yield helper.pg.connect()
var res = yield client.query('SELECT $1::text as name', ['foo'])
assert.equal(res.rows[0].name, 'foo')

var threw = false
try {
yield client.query('SELECT LKDSJDSLKFJ')
} catch(e) {
threw = true
}
assert(threw)
client.release()
helper.pg.end()
clearTimeout(tid)
})
.catch(function(e) {
setImmediate(function() {
throw e
})
})
4 changes: 2 additions & 2 deletions test/integration/gh-issues/675-tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@ helper.pg.connect(helper.config, function(err, client, done) {

c = 'INSERT INTO posts (body) VALUES ($1) RETURNING *';

var body = new Buffer('foo');
var body = Buffer.from('foo');
client.query(c, [body], function(err) {
if (err) throw err;

body = new Buffer([]);
body = Buffer.from([]);
client.query(c, [body], function(err, res) {
done();

Expand Down
8 changes: 4 additions & 4 deletions test/test-buffers.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ require(__dirname+'/test-helper');
var buffers = {};
buffers.readyForQuery = function() {
return new BufferList()
.add(Buffer('I'))
.add(Buffer.from('I'))
.join(true,'Z');
};

Expand All @@ -23,7 +23,7 @@ buffers.authenticationCleartextPassword = function() {
buffers.authenticationMD5Password = function() {
return new BufferList()
.addInt32(5)
.add(Buffer([1,2,3,4]))
.add(Buffer.from([1,2,3,4]))
.join(true, 'R');
};

Expand Down Expand Up @@ -71,7 +71,7 @@ buffers.dataRow = function(columns) {
if(col == null) {
buf.addInt32(-1);
} else {
var strBuf = new Buffer(col, 'utf8');
var strBuf = Buffer.from(col, 'utf8');
buf.addInt32(strBuf.length);
buf.add(strBuf);
}
Expand All @@ -94,7 +94,7 @@ var errorOrNotice = function(fields) {
buf.addChar(field.type);
buf.addCString(field.value);
});
return buf.add(Buffer([0]));//terminator
return buf.add(Buffer.from([0]));//terminator
}

buffers.parseComplete = function() {
Expand Down
5 changes: 0 additions & 5 deletions test/test-helper.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,6 @@
//make assert a global...
assert = require('assert');

//support for [email protected]
if (typeof Promise == 'undefined') {
global.Promise = require('promise-polyfill')
}

var EventEmitter = require('events').EventEmitter;
var sys = require('util');
var BufferList = require(__dirname+'/buffer-list')
Expand Down
2 changes: 1 addition & 1 deletion test/unit/client/md5-password-tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ require(__dirname + '/test-helper');
test('md5 authentication', function() {
var client = createClient();
client.password = "!";
var salt = Buffer([1, 2, 3, 4]);
var salt = Buffer.from([1, 2, 3, 4]);
client.connection.emit('authenticationMD5Password', {salt: salt});

test('responds', function() {
Expand Down
16 changes: 8 additions & 8 deletions test/unit/connection/inbound-parser-tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ test('Connection', function() {
testForMessage(plainPasswordBuffer, expectedPlainPasswordMessage);
var msg = testForMessage(md5PasswordBuffer, expectedMD5PasswordMessage);
test('md5 has right salt', function() {
assert.equalBuffers(msg.salt, Buffer([1,2,3,4]));
assert.equalBuffers(msg.salt, Buffer.from([1,2,3,4]));
});
testForMessage(paramStatusBuffer, expectedParameterStatusMessage);
testForMessage(backendKeyDataBuffer, expectedBackendKeyDataMessage);
Expand All @@ -173,7 +173,7 @@ test('Connection', function() {
});

test("no data message", function() {
testForMessage(Buffer([0x6e, 0, 0, 0, 4]), {
testForMessage(Buffer.from([0x6e, 0, 0, 0, 4]), {
name: 'noData'
});
});
Expand Down Expand Up @@ -349,7 +349,7 @@ test('Connection', function() {
});

test('parses replication start message', function() {
testForMessage(new Buffer([0x57, 0x00, 0x00, 0x00, 0x04]), {
testForMessage(Buffer.from([0x57, 0x00, 0x00, 0x00, 0x04]), {
name: 'replicationStart',
length: 4
});
Expand Down Expand Up @@ -383,8 +383,8 @@ test('split buffer, single message parsing', function() {
});

var testMessageRecievedAfterSpiltAt = function(split) {
var firstBuffer = new Buffer(fullBuffer.length-split);
var secondBuffer = new Buffer(fullBuffer.length-firstBuffer.length);
var firstBuffer = Buffer.alloc(fullBuffer.length-split);
var secondBuffer = Buffer.alloc(fullBuffer.length-firstBuffer.length);
fullBuffer.copy(firstBuffer, 0, 0);
fullBuffer.copy(secondBuffer, 0, firstBuffer.length);
stream.emit('data', firstBuffer);
Expand Down Expand Up @@ -416,7 +416,7 @@ test('split buffer, single message parsing', function() {
test('split buffer, multiple message parsing', function() {
var dataRowBuffer = buffers.dataRow(['!']);
var readyForQueryBuffer = buffers.readyForQuery();
var fullBuffer = new Buffer(dataRowBuffer.length + readyForQueryBuffer.length);
var fullBuffer = Buffer.alloc(dataRowBuffer.length + readyForQueryBuffer.length);
dataRowBuffer.copy(fullBuffer, 0, 0);
readyForQueryBuffer.copy(fullBuffer, dataRowBuffer.length, 0);

Expand Down Expand Up @@ -449,8 +449,8 @@ test('split buffer, multiple message parsing', function() {
verifyMessages();
});
var splitAndVerifyTwoMessages = function(split) {
var firstBuffer = new Buffer(fullBuffer.length-split);
var secondBuffer = new Buffer(fullBuffer.length-firstBuffer.length);
var firstBuffer = Buffer.alloc(fullBuffer.length-split);
var secondBuffer = Buffer.alloc(fullBuffer.length-firstBuffer.length);
fullBuffer.copy(firstBuffer, 0, 0);
fullBuffer.copy(secondBuffer, 0, firstBuffer.length);
stream.emit('data', firstBuffer);
Expand Down
16 changes: 8 additions & 8 deletions test/unit/connection/outbound-sending-tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -104,12 +104,12 @@ test('bind messages', function() {
.addInt16(0)
.addInt16(4)
.addInt32(1)
.add(Buffer("1"))
.add(Buffer.from("1"))
.addInt32(2)
.add(Buffer("hi"))
.add(Buffer.from("hi"))
.addInt32(-1)
.addInt32(4)
.add(Buffer('zing'))
.add(Buffer.from('zing'))
.addInt16(0)
.join(true, 'B');
assert.received(stream, expectedBuffer);
Expand All @@ -120,7 +120,7 @@ test('with named statement, portal, and buffer value', function() {
con.bind({
portal: 'bang',
statement: 'woo',
values: ['1', 'hi', null, new Buffer('zing', 'UTF-8')]
values: ['1', 'hi', null, Buffer.from('zing', 'utf8')]
});
var expectedBuffer = new BufferList()
.addCString('bang') //portal name
Expand All @@ -132,12 +132,12 @@ test('with named statement, portal, and buffer value', function() {
.addInt16(1)//binary
.addInt16(4)
.addInt32(1)
.add(Buffer("1"))
.add(Buffer.from("1"))
.addInt32(2)
.add(Buffer("hi"))
.add(Buffer.from("hi"))
.addInt32(-1)
.addInt32(4)
.add(new Buffer('zing', 'UTF-8'))
.add(Buffer.from('zing', 'UTF-8'))
.addInt16(0)
.join(true, 'B');
assert.received(stream, expectedBuffer);
Expand Down Expand Up @@ -181,7 +181,7 @@ test('sends sync command', function() {

test('sends end command', function() {
con.end();
var expected = new Buffer([0x58, 0, 0, 0, 4]);
var expected = Buffer.from([0x58, 0, 0, 0, 4]);
assert.received(stream, expected);
});

Expand Down
Loading