util: use getOwnPropertyDescripter
Change formatProperty in util.js to use Object.getOwnPropertyDescriptor instead of __lookup[GS]etter__. Use the cached value from the descriptor to reduce number of property lookups from 3 to 1. Fallback to standard lookup if the descriptor is empty. This doesn't ever happen with normal JS objects (this function is called only when the key exists) but apparently does with Node's custom ENV interface. Fixes: #2109.
This commit is contained in:
parent
3df7c90c30
commit
f9014438c7
27
lib/util.js
27
lib/util.js
@ -296,29 +296,28 @@ function formatArray(ctx, value, recurseTimes, visibleKeys, keys) {
|
||||
|
||||
|
||||
function formatProperty(ctx, value, recurseTimes, visibleKeys, key, array) {
|
||||
var name, str;
|
||||
if (value.__lookupGetter__) {
|
||||
if (value.__lookupGetter__(key)) {
|
||||
if (value.__lookupSetter__(key)) {
|
||||
str = ctx.stylize('[Getter/Setter]', 'special');
|
||||
} else {
|
||||
str = ctx.stylize('[Getter]', 'special');
|
||||
}
|
||||
var name, str, desc;
|
||||
desc = Object.getOwnPropertyDescriptor(value, key) || { value: value[key] };
|
||||
if (desc.get) {
|
||||
if (desc.set) {
|
||||
str = ctx.stylize('[Getter/Setter]', 'special');
|
||||
} else {
|
||||
if (value.__lookupSetter__(key)) {
|
||||
str = ctx.stylize('[Setter]', 'special');
|
||||
}
|
||||
str = ctx.stylize('[Getter]', 'special');
|
||||
}
|
||||
} else {
|
||||
if (desc.set) {
|
||||
str = ctx.stylize('[Setter]', 'special');
|
||||
}
|
||||
}
|
||||
if (visibleKeys.indexOf(key) < 0) {
|
||||
name = '[' + key + ']';
|
||||
}
|
||||
if (!str) {
|
||||
if (ctx.seen.indexOf(value[key]) < 0) {
|
||||
if (ctx.seen.indexOf(desc.value) < 0) {
|
||||
if (recurseTimes === null) {
|
||||
str = formatValue(ctx, value[key], null);
|
||||
str = formatValue(ctx, desc.value, null);
|
||||
} else {
|
||||
str = formatValue(ctx, value[key], recurseTimes - 1);
|
||||
str = formatValue(ctx, desc.value, recurseTimes - 1);
|
||||
}
|
||||
if (str.indexOf('\n') > -1) {
|
||||
if (array) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user