Skip to content

Commit 934ca3a

Browse files
charmanderbrianc
authored andcommitted
Remove fallbacks for unsupported Node versions (brianc#1304)
* Remove unsupported Node versions 0.10 and 0.12 from CI * Replace deprecated Buffer constructor with .from/.alloc * Remove Promise polyfill * Make use of Object.assign * Remove checks for versions of Node earlier than 4 * Remove Buffer#indexOf fallback for Node 0.10
1 parent 3757ff7 commit 934ca3a

16 files changed

+65
-106
lines changed

.travis.yml

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,6 @@ addons:
1212

1313
matrix:
1414
include:
15-
- node_js: "0.10"
16-
addons:
17-
postgresql: "9.6"
18-
env: []
19-
- node_js: "0.12"
20-
addons:
21-
postgresql: "9.6"
22-
env: []
2315
- node_js: "4"
2416
addons:
2517
postgresql: "9.6"

lib/client.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ Client.prototype.connect = function(callback) {
9494
//password request handling
9595
con.on('authenticationMD5Password', checkPgPass(function(msg) {
9696
var inner = Client.md5(self.password + self.user);
97-
var outer = Client.md5(Buffer.concat([new Buffer(inner), msg.salt]));
97+
var outer = Client.md5(Buffer.concat([Buffer.from(inner), msg.salt]));
9898
var md5password = "md5" + outer;
9999
con.password(md5password);
100100
}));

lib/connection.js

Lines changed: 3 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -13,21 +13,6 @@ var util = require('util');
1313
var Writer = require('buffer-writer');
1414
var Reader = require('packet-reader');
1515

16-
var indexOf =
17-
'indexOf' in Buffer.prototype ?
18-
function indexOf(buffer, value, start) {
19-
return buffer.indexOf(value, start);
20-
} :
21-
function indexOf(buffer, value, start) {
22-
for (var i = start, len = buffer.length; i < len; i++) {
23-
if (buffer[i] === value) {
24-
return i;
25-
}
26-
}
27-
28-
return -1;
29-
};
30-
3116
var TEXT_MODE = 0;
3217
var BINARY_MODE = 1;
3318
var Connection = function(config) {
@@ -311,7 +296,7 @@ Connection.prototype.execute = function(config, more) {
311296
this._send(0x45, more);
312297
};
313298

314-
var emptyBuffer = Buffer(0);
299+
var emptyBuffer = Buffer.alloc(0);
315300

316301
Connection.prototype.flush = function() {
317302
//0x48 = 'H'
@@ -450,7 +435,7 @@ Connection.prototype.parseR = function(buffer, length) {
450435
code = this.parseInt32(buffer);
451436
if(code === 5) { //md5 required
452437
msg.name = 'authenticationMD5Password';
453-
msg.salt = new Buffer(4);
438+
msg.salt = Buffer.alloc(4);
454439
buffer.copy(msg.salt, 0, this.offset, this.offset + 4);
455440
this.offset += 4;
456441
return msg;
@@ -665,7 +650,7 @@ Connection.prototype.readBytes = function(buffer, length) {
665650

666651
Connection.prototype.parseCString = function(buffer) {
667652
var start = this.offset;
668-
var end = indexOf(buffer, 0, start);
653+
var end = buffer.indexOf(0, start);
669654
this.offset = end + 1;
670655
return buffer.toString(this.encoding, start, end);
671656
};

package.json

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,7 @@
3030
"async": "0.9.0",
3131
"co": "4.6.0",
3232
"jshint": "2.5.2",
33-
"lodash": "4.13.1",
34-
"pg-copy-streams": "0.3.0",
35-
"promise-polyfill": "5.2.1"
33+
"pg-copy-streams": "0.3.0"
3634
},
3735
"minNativeVersion": "1.7.0",
3836
"scripts": {

test/buffer-list.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ p.add = function(buffer, front) {
99
};
1010

1111
p.addInt16 = function(val, front) {
12-
return this.add(Buffer([(val >>> 8),(val >>> 0)]),front);
12+
return this.add(Buffer.from([(val >>> 8),(val >>> 0)]),front);
1313
};
1414

1515
p.getByteLength = function(initial) {
@@ -19,7 +19,7 @@ p.getByteLength = function(initial) {
1919
};
2020

2121
p.addInt32 = function(val, first) {
22-
return this.add(Buffer([
22+
return this.add(Buffer.from([
2323
(val >>> 24 & 0xFF),
2424
(val >>> 16 & 0xFF),
2525
(val >>> 8 & 0xFF),
@@ -29,14 +29,14 @@ p.addInt32 = function(val, first) {
2929

3030
p.addCString = function(val, front) {
3131
var len = Buffer.byteLength(val);
32-
var buffer = new Buffer(len+1);
32+
var buffer = Buffer.alloc(len+1);
3333
buffer.write(val);
3434
buffer[len] = 0;
3535
return this.add(buffer, front);
3636
};
3737

3838
p.addChar = function(char, first) {
39-
return this.add(Buffer(char,'utf8'), first);
39+
return this.add(Buffer.from(char,'utf8'), first);
4040
};
4141

4242
p.join = function(appendLength, char) {
@@ -49,7 +49,7 @@ p.join = function(appendLength, char) {
4949
this.addChar(char, true);
5050
length++;
5151
}
52-
var result = Buffer(length);
52+
var result = Buffer.alloc(length);
5353
var index = 0;
5454
this.buffers.forEach(function(buffer) {
5555
buffer.copy(result, index, 0);

test/integration/client/query-as-promise-tests.js

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,5 @@
11
var helper = require(__dirname + '/../test-helper');
22
var pg = helper.pg;
3-
var semver = require('semver')
4-
5-
if (semver.lt(process.version, '0.12.0')) {
6-
return console.log('promises are not supported in node < v0.10')
7-
}
83

94
process.on('unhandledRejection', function(e) {
105
console.error(e, e.stack)

test/integration/connection-pool/idle-timeout-tests.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
var helper = require(__dirname + '/test-helper');
2-
var _ = require('lodash')
32

4-
const config = _.extend({ }, helper.config, { idleTimeoutMillis: 50 })
3+
const config = Object.assign({ }, helper.config, { idleTimeoutMillis: 50 })
54

65
test('idle timeout', function() {
76
helper.pg.connect(config, assert.calls(function(err, client, done) {

test/integration/connection-pool/yield-support-body.js

Lines changed: 0 additions & 28 deletions
This file was deleted.
Lines changed: 28 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,28 @@
1-
var semver = require('semver')
2-
if (semver.lt(process.version, '1.0.0')) {
3-
return console.log('yield is not supported in node <= v0.12')
4-
}
5-
require('./yield-support-body')
1+
var helper = require('./test-helper')
2+
var co = require('co')
3+
4+
var tid = setTimeout(function() {
5+
throw new Error('Tests did not complete in time')
6+
}, 1000)
7+
8+
co(function * () {
9+
var client = yield helper.pg.connect()
10+
var res = yield client.query('SELECT $1::text as name', ['foo'])
11+
assert.equal(res.rows[0].name, 'foo')
12+
13+
var threw = false
14+
try {
15+
yield client.query('SELECT LKDSJDSLKFJ')
16+
} catch(e) {
17+
threw = true
18+
}
19+
assert(threw)
20+
client.release()
21+
helper.pg.end()
22+
clearTimeout(tid)
23+
})
24+
.catch(function(e) {
25+
setImmediate(function() {
26+
throw e
27+
})
28+
})

test/integration/gh-issues/675-tests.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,11 @@ helper.pg.connect(helper.config, function(err, client, done) {
1111

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

14-
var body = new Buffer('foo');
14+
var body = Buffer.from('foo');
1515
client.query(c, [body], function(err) {
1616
if (err) throw err;
1717

18-
body = new Buffer([]);
18+
body = Buffer.from([]);
1919
client.query(c, [body], function(err, res) {
2020
done();
2121

0 commit comments

Comments
 (0)