diff options
author | koichik <koichik@improvement.jp> | 2011-09-09 01:16:48 +0900 |
---|---|---|
committer | koichik <koichik@improvement.jp> | 2011-09-11 23:13:06 +0900 |
commit | 389e2a07e676e5be3b8cbd94f0a0f7ebccb47f47 (patch) | |
tree | c18602caf70368e9c27bde61894eb1f5e0860b8c /lib/util.js | |
parent | df480e0357b597aa99f0ceb42c14d13129277e9d (diff) | |
download | android-node-v8-389e2a07e676e5be3b8cbd94f0a0f7ebccb47f47.tar.gz android-node-v8-389e2a07e676e5be3b8cbd94f0a0f7ebccb47f47.tar.bz2 android-node-v8-389e2a07e676e5be3b8cbd94f0a0f7ebccb47f47.zip |
util: Fix inspection for Error
Fixes #1634.
Diffstat (limited to 'lib/util.js')
-rw-r--r-- | lib/util.js | 28 |
1 files changed, 26 insertions, 2 deletions
diff --git a/lib/util.js b/lib/util.js index 84833d38c4..5e4f1a67a2 100644 --- a/lib/util.js +++ b/lib/util.js @@ -185,6 +185,9 @@ function formatValue(ctx, value, recurseTimes) { if (isDate(value)) { return ctx.stylize(value.toUTCString(), 'date'); } + if (isError(value)) { + return formatError(value); + } } var base = '', array = false, braces = ['{', '}']; @@ -211,6 +214,11 @@ function formatValue(ctx, value, recurseTimes) { base = ' ' + value.toUTCString(); } + // Make error with message first say the error + if (isError(value)) { + base = ' ' + formatError(value); + } + if (keys.length === 0 && (!array || value.length == 0)) { return braces[0] + base + braces[1]; } @@ -264,6 +272,11 @@ function formatPrimitive(ctx, value) { } +function formatError(value) { + return '[' + Error.prototype.toString.call(value) + ']'; +} + + function formatArray(ctx, value, recurseTimes, visibleKeys, keys) { var output = []; for (var i = 0, l = value.length; i < l; ++i) { @@ -374,13 +387,24 @@ function isArray(ar) { function isRegExp(re) { return re instanceof RegExp || - (typeof re === 'object' && Object.prototype.toString.call(re) === '[object RegExp]'); + (typeof re === 'object' && objectToString(re) === '[object RegExp]'); } function isDate(d) { return d instanceof Date || - (typeof d === 'object' && Object.prototype.toString.call(d) === '[object Date]'); + (typeof d === 'object' && objectToString(d) === '[object Date]'); +} + + +function isError(e) { + return e instanceof Error || + (typeof e === 'object' && objectToString(e) === '[object Error]'); +} + + +function objectToString(o) { + return Object.prototype.toString.call(o); } |