Permalink
Browse files

Handle errors better in stringify

  • Loading branch information...
1 parent 54a8d88 commit cc5a7121da86879497684e662efc84701efdef96 @isaacs committed Nov 16, 2011
Showing with 8 additions and 2 deletions.
  1. +8 −2 assert.js
View
@@ -301,7 +301,13 @@ function selectFields (a, b) {
if (!a.hasOwnProperty(k)) return
var v = b[k]
, av = a[k]
- if (v && av && typeof v === "object" && typeof av === "object") {
+ if (v && av && typeof v === "object" && typeof av === "object"
+ && !(v instanceof Date)
+ && !(v instanceof RegExp)
+ && !(v instanceof String)
+ && !(v instanceof Boolean)
+ && !(v instanceof Number)
+ && !(Array.isArray(v))) {
ret[k] = selectFields(av, v)
} else ret[k] = av
})
@@ -322,7 +328,7 @@ function stringify (a) {
keys.push(val["!"] || val.name || key || "<root>")
if (typeof val === "function") {
return val.toString().split(/\n/)[0]
- } else if (val.toUTCString) {
+ } else if (typeof val.toUTCString === "function") {
return val.toUTCString()
}
}

0 comments on commit cc5a712

Please sign in to comment.