File tree 4 files changed +49
-1
lines changed
4 files changed +49
-1
lines changed Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change @@ -12,9 +12,13 @@ var Client = require('./client')
12
12
var defaults = require ( './defaults' )
13
13
var Connection = require ( './connection' )
14
14
var Pool = require ( 'pg-pool' )
15
+ const checkConstructor = require ( './compat/check-constructor' )
15
16
16
17
const poolFactory = ( Client ) => {
17
18
var BoundPool = function ( options ) {
19
+ // eslint-disable-next-line no-eval
20
+ checkConstructor ( 'pg.Pool' , 'PG-POOL-NEW' , ( ) => eval ( 'new.target' ) )
21
+
18
22
var config = Object . assign ( { Client : Client } , options )
19
23
return new Pool ( config )
20
24
}
Original file line number Diff line number Diff line change 9
9
10
10
var EventEmitter = require ( 'events' ) . EventEmitter
11
11
var util = require ( 'util' )
12
+ const checkConstructor = require ( './compat/check-constructor' )
12
13
13
14
var Result = require ( './result' )
14
15
var utils = require ( './utils' )
15
16
16
17
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' ) )
18
21
if ( ! ( this instanceof Query ) ) { return new Query ( config , values , callback ) }
19
22
20
23
config = utils . normalizeQueryConfig ( config , values , callback )
You can’t perform that action at this time.
0 commit comments