mirror of
https://github.com/nodejs/node.git
synced 2026-11-09 15:11:11 -05:00
More bulletproof util.inspect() function.
Use the *real* versions of the Date and RegExp functions, from the
prototype. This defends against code like:
var d = new Date()
d.toUTCString = null
util.inspect(d)
// TypeError: toUTCString is not a function
Fixes #1944.
This commit is contained in:
1 parent
d4379fcee3
commit
ebefe77bc0
1 file changed
+5
-5
+5
-5
@@ -180,10 +180,10 @@ function formatValue(ctx, value, recurseTimes) {
|
||||
return ctx.stylize('[Function' + name + ']', 'special');
|
||||
}
|
||||
if (isRegExp(value)) {
|
||||
return ctx.stylize('' + value, 'regexp');
|
||||
return ctx.stylize(RegExp.prototype.toString.call(value), 'regexp');
|
||||
}
|
||||
if (isDate(value)) {
|
||||
return ctx.stylize(value.toUTCString(), 'date');
|
||||
return ctx.stylize(Date.prototype.toUTCString.call(value), 'date');
|
||||
}
|
||||
if (isError(value)) {
|
||||
return formatError(value);
|
||||
@@ -206,12 +206,12 @@ function formatValue(ctx, value, recurseTimes) {
|
||||
|
||||
// Make RegExps say that they are RegExps
|
||||
if (isRegExp(value)) {
|
||||
base = ' ' + value;
|
||||
base = ' ' + RegExp.prototype.toString.call(value);
|
||||
}
|
||||
|
||||
// Make dates with properties first say the date
|
||||
if (isDate(value)) {
|
||||
base = ' ' + value.toUTCString();
|
||||
base = ' ' + Date.prototype.toUTCString.call(value);
|
||||
}
|
||||
|
||||
// Make error with message first say the error
|
||||
@@ -225,7 +225,7 @@ function formatValue(ctx, value, recurseTimes) {
|
||||
|
||||
if (recurseTimes < 0) {
|
||||
if (isRegExp(value)) {
|
||||
return ctx.stylize('' + value, 'regexp');
|
||||
return ctx.stylize(RegExp.prototype.toString.call(value), 'regexp');
|
||||
} else {
|
||||
return ctx.stylize('[Object]', 'special');
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user