Skip to content
Browse files

Improve constructor detection. Make V8 c++ accessors no always show u…

…p as read only.
  • Loading branch information...
1 parent cc9881a commit 9e9ab8c35d0c1a42668b8fcfc090402d77a147ca @Benvie committed
Showing with 20 additions and 15 deletions.
  1. +20 −15 lib/util.js
View
35 lib/util.js
@@ -273,25 +273,26 @@ function formatValue(value, depth, settings) {
return value.inspect(depth);
}
- var base = '',
- type = getClass(value),
- array = isArray(value),
- braces = array ? settings.square : settings.curly;
+ var base = '';
+ var type = getClass(value);
+ var array = isArray(value);
+ var braces = array ? settings.square : settings.curly;
- // most types can just be formatted by matching their internal class
if (type in formatters) {
- if (!isPrimitive(value) && type === 'Function') {
- // check for constructors
- if (!isPrimitive(value.prototype) &&
- (value.prototype.constructor !== value ||
- Object.getOwnPropertyNames(value.prototype).length > 1)) {
+ // check for constructor functions
+ if (typeof value === 'function' && !isPrimitive(value.prototype)) {
+ // check for prototype having non-default properties
+ if (Object.getOwnPropertyNames(value.prototype).length >
+ ('constructor' in value.prototype)) {
// label constructors separately from functions
type = 'Constructor';
}
}
+ // types can be formatted by matching their internal class
base = settings.style(formatters[type](value), type);
}
- // prevent deeper inspection for primitives, regexps, and errors
+
+ // prevent deeper inspection for primitives and regexps
if (isPrimitive(value) ||
!settings.showHidden && type === 'RegExp') {
return base;
@@ -302,11 +303,10 @@ function formatValue(value, depth, settings) {
return settings.style('More', 'More', true);
}
- var properties;
if (!settings.showHidden) {
- properties = Object.keys(value);
+ var properties = Object.keys(value);
} else {
- properties = Object.getOwnPropertyNames(value);
+ var properties = Object.getOwnPropertyNames(value);
if (typeof value === 'function') {
properties = properties.filter(function(key) {
@@ -330,6 +330,7 @@ function formatValue(value, depth, settings) {
}
}
+
settings.seen.push(value);
var output = [];
@@ -366,7 +367,11 @@ function formatProperty(value, key, depth, settings, array) {
// V8 c++ accessors like process.env that don't correctly
// work with Object.getOwnPropertyDescriptor
if (typeof val === 'undefined') {
- val = { value: value[key], enumerable: true };
+ val = {
+ value: value[key],
+ enumerable: true,
+ writable: true
+ };
}
<<<<<<< HEAD
// check for accessors but don't resolve them

0 comments on commit 9e9ab8c

Please sign in to comment.
Something went wrong with that request. Please try again.