mirror of https://github.com/lukechilds/node.git
Browse Source
Classes cannot be instantiated without new, but util.deprecate() uses Function.prototype.apply(). This commit uses new.target to detect constructor calls, allowing classes to be deprecated. PR-URL: https://github.com/nodejs/node/pull/7690 Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Michaël Zasso <mic.besace@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>v6.x
committed by
cjihrig
5 changed files with 62 additions and 4 deletions
@ -0,0 +1,12 @@ |
|||||
|
const util = require('util'); |
||||
|
const assert = require('assert'); |
||||
|
|
||||
|
class deprecatedClass { |
||||
|
} |
||||
|
|
||||
|
const deprecated = util.deprecate(deprecatedClass, 'deprecatedClass is deprecated.'); |
||||
|
|
||||
|
const instance = new deprecated(); |
||||
|
|
||||
|
assert(instance instanceof deprecated); |
||||
|
assert(instance instanceof deprecatedClass); |
@ -0,0 +1,19 @@ |
|||||
|
const util = require('util'); |
||||
|
const assert = require('assert'); |
||||
|
|
||||
|
class deprecatedClass { |
||||
|
} |
||||
|
|
||||
|
const deprecated = util.deprecate(deprecatedClass, 'deprecatedClass is deprecated.'); |
||||
|
|
||||
|
class subclass extends deprecated { |
||||
|
constructor() { |
||||
|
super(); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
const instance = new subclass(); |
||||
|
|
||||
|
assert(instance instanceof subclass); |
||||
|
assert(instance instanceof deprecated); |
||||
|
assert(instance instanceof deprecatedClass); |
Loading…
Reference in new issue