Skip to content

Commit 00bfb5f

Browse files
committed
Merge origin/master
2 parents 1528ad6 + 2b59209 commit 00bfb5f

File tree

6 files changed

+58
-17
lines changed

6 files changed

+58
-17
lines changed

packages/pg/lib/client.js

+1
Original file line numberDiff line numberDiff line change
@@ -251,6 +251,7 @@ Client.prototype._connect = function (callback) {
251251
? new Error('Connection terminated')
252252
: new Error('Connection terminated unexpectedly')
253253

254+
clearTimeout(connectionTimeoutHandle)
254255
this._errorAllQueries(error)
255256

256257
if (!this._ending) {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
'use strict'
2+
3+
const warnDeprecation = require('./warn-deprecation')
4+
5+
// Node 4 doesn’t support new.target.
6+
let hasNewTarget
7+
8+
try {
9+
// eslint-disable-next-line no-eval
10+
eval('(function () { new.target })')
11+
hasNewTarget = true
12+
} catch (error) {
13+
hasNewTarget = false
14+
}
15+
16+
const checkConstructor = (name, code, getNewTarget) => {
17+
if (hasNewTarget && getNewTarget() === undefined) {
18+
warnDeprecation(`Constructing a ${name} without new is deprecated and will stop working in pg 8.`, code)
19+
}
20+
}
21+
22+
module.exports = checkConstructor
+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
'use strict'
2+
3+
const util = require('util')
4+
5+
const dummyFunctions = new Map()
6+
7+
// Node 4 doesn’t support process.emitWarning(message, 'DeprecationWarning', code).
8+
const emitDeprecationWarning = (message, code) => {
9+
let dummy = dummyFunctions.get(code)
10+
11+
if (dummy === undefined) {
12+
dummy = util.deprecate(() => {}, message)
13+
dummyFunctions.set(code, dummy)
14+
}
15+
16+
dummy()
17+
}
18+
19+
module.exports = emitDeprecationWarning

packages/pg/lib/connection.js

+8-16
Original file line numberDiff line numberDiff line change
@@ -594,27 +594,19 @@ Connection.prototype._readValue = function (buffer) {
594594
// parses error
595595
Connection.prototype.parseE = function (buffer, length) {
596596
var fields = {}
597-
var msg, item
598-
var input = new Message('error', length)
599597
var fieldType = this.readString(buffer, 1)
600598
while (fieldType !== '\0') {
601599
fields[fieldType] = this.parseCString(buffer)
602600
fieldType = this.readString(buffer, 1)
603601
}
604-
if (input.name === 'error') {
605-
// the msg is an Error instance
606-
msg = new Error(fields.M)
607-
for (item in input) {
608-
// copy input properties to the error
609-
if (Object.prototype.hasOwnProperty.call(input, item)) {
610-
msg[item] = input[item]
611-
}
612-
}
613-
} else {
614-
// the msg is an object literal
615-
msg = input
616-
msg.message = fields.M
617-
}
602+
603+
// the msg is an Error instance
604+
var msg = new Error(fields.M)
605+
606+
// for compatibility with Message
607+
msg.name = 'error'
608+
msg.length = length
609+
618610
msg.severity = fields.S
619611
msg.code = fields.C
620612
msg.detail = fields.D

packages/pg/lib/index.js

+4
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,13 @@ var Client = require('./client')
1212
var defaults = require('./defaults')
1313
var Connection = require('./connection')
1414
var Pool = require('pg-pool')
15+
const checkConstructor = require('./compat/check-constructor')
1516

1617
const poolFactory = (Client) => {
1718
var BoundPool = function (options) {
19+
// eslint-disable-next-line no-eval
20+
checkConstructor('pg.Pool', 'PG-POOL-NEW', () => eval('new.target'))
21+
1822
var config = Object.assign({ Client: Client }, options)
1923
return new Pool(config)
2024
}

packages/pg/lib/query.js

+4-1
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,15 @@
99

1010
var EventEmitter = require('events').EventEmitter
1111
var util = require('util')
12+
const checkConstructor = require('./compat/check-constructor')
1213

1314
var Result = require('./result')
1415
var utils = require('./utils')
1516

1617
var Query = function (config, values, callback) {
17-
// use of "new" optional
18+
// use of "new" optional in pg 7
19+
// eslint-disable-next-line no-eval
20+
checkConstructor('Query', 'PG-QUERY-NEW', () => eval('new.target'))
1821
if (!(this instanceof Query)) { return new Query(config, values, callback) }
1922

2023
config = utils.normalizeQueryConfig(config, values, callback)

0 commit comments

Comments
 (0)