-
Notifications
You must be signed in to change notification settings - Fork 29.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
util: support classes in util.deprecate()
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: #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>
- Loading branch information
1 parent
df35ae6
commit 295d1ea
Showing
5 changed files
with
62 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters