aboutsummaryrefslogtreecommitdiff
path: root/lib/internal/util.js
diff options
context:
space:
mode:
authorTimothy Gu <timothygu99@gmail.com>2017-04-19 23:07:39 -0700
committerTimothy Gu <timothygu99@gmail.com>2017-04-24 16:42:49 -0700
commit3c0dd45c882b8c84ec244d3a5635302fb4875d81 (patch)
treeef0d01e46f4dbdc77c27aaa7f01ddd49d71c0e78 /lib/internal/util.js
parentb2870a4f8c9e68c01ad998cf72ed5964327ccef5 (diff)
downloadandroid-node-v8-3c0dd45c882b8c84ec244d3a5635302fb4875d81.tar.gz
android-node-v8-3c0dd45c882b8c84ec244d3a5635302fb4875d81.tar.bz2
android-node-v8-3c0dd45c882b8c84ec244d3a5635302fb4875d81.zip
util: move getConstructorOf() to internal
PR-URL: https://github.com/nodejs/node/pull/12526 Reviewed-By: James M Snell <jasnell@gmail.com>
Diffstat (limited to 'lib/internal/util.js')
-rw-r--r--lib/internal/util.js16
1 files changed, 16 insertions, 0 deletions
diff --git a/lib/internal/util.js b/lib/internal/util.js
index 48036148b9..8b2148fd6a 100644
--- a/lib/internal/util.js
+++ b/lib/internal/util.js
@@ -180,6 +180,21 @@ function convertToValidSignal(signal) {
throw new Error('Unknown signal: ' + signal);
}
+function getConstructorOf(obj) {
+ while (obj) {
+ var descriptor = Object.getOwnPropertyDescriptor(obj, 'constructor');
+ if (descriptor !== undefined &&
+ typeof descriptor.value === 'function' &&
+ descriptor.value.name !== '') {
+ return descriptor.value;
+ }
+
+ obj = Object.getPrototypeOf(obj);
+ }
+
+ return null;
+}
+
module.exports = exports = {
assertCrypto,
cachedResult,
@@ -188,6 +203,7 @@ module.exports = exports = {
decorateErrorStack,
deprecate,
filterDuplicateStrings,
+ getConstructorOf,
isError,
normalizeEncoding,
objectToString,