mirror of
https://github.com/nodejs/node.git
synced 2024-11-21 10:59:27 +00:00
util: make util.inspect() work when "hasOwnProperty" is overwritten
This commit is contained in:
parent
9a3521cb25
commit
fb383a0ad0
@ -318,7 +318,7 @@ function formatError(value) {
|
||||
function formatArray(ctx, value, recurseTimes, visibleKeys, keys) {
|
||||
var output = [];
|
||||
for (var i = 0, l = value.length; i < l; ++i) {
|
||||
if (Object.prototype.hasOwnProperty.call(value, String(i))) {
|
||||
if (hasOwnProperty(value, String(i))) {
|
||||
output.push(formatProperty(ctx, value, recurseTimes, visibleKeys,
|
||||
String(i), true));
|
||||
} else {
|
||||
@ -349,7 +349,7 @@ function formatProperty(ctx, value, recurseTimes, visibleKeys, key, array) {
|
||||
str = ctx.stylize('[Setter]', 'special');
|
||||
}
|
||||
}
|
||||
if (!visibleKeys.hasOwnProperty(key)) {
|
||||
if (!hasOwnProperty(visibleKeys, key)) {
|
||||
name = '[' + key + ']';
|
||||
}
|
||||
if (!str) {
|
||||
@ -556,3 +556,7 @@ exports._extend = function(origin, add) {
|
||||
}
|
||||
return origin;
|
||||
};
|
||||
|
||||
function hasOwnProperty(obj, prop) {
|
||||
return Object.prototype.hasOwnProperty.call(obj, prop);
|
||||
}
|
||||
|
@ -107,3 +107,10 @@ assert.doesNotThrow(function() {
|
||||
// GH-2225
|
||||
var x = { inspect: util.inspect };
|
||||
assert.ok(util.inspect(x).indexOf('inspect') != -1);
|
||||
|
||||
// an object with "hasOwnProperty" overwritten should not throw
|
||||
assert.doesNotThrow(function() {
|
||||
util.inspect({
|
||||
hasOwnProperty: null
|
||||
});
|
||||
});
|
||||
|
Loading…
Reference in New Issue
Block a user