Skip to content
This repository was archived by the owner on Apr 22, 2023. It is now read-only.
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions lib/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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
Expand All @@ -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');
}
Expand Down
13 changes: 13 additions & 0 deletions test/simple/test-util-inspect.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,3 +62,16 @@ assert.ok(ex.indexOf('[type]') != -1);
// GH-1941
// should not throw:
assert.equal(util.inspect(Object.create(Date.prototype)), '{}')

// GH-1944
assert.doesNotThrow(function () {
var d = new Date();
d.toUTCString = null;
util.inspect(d);
});

assert.doesNotThrow(function () {
var r = /regexp/;
r.toString = null;
util.inspect(r);
});