don't crash on objects with null prototype
This commit is contained in:
parent
be31d8a11e
commit
92ce930651
12
src/keys.js
12
src/keys.js
|
@ -8,23 +8,23 @@ let array
|
|||
|
||||
let recurse = obj => {
|
||||
let temp
|
||||
switch (typeof obj === 'object' && obj !== null && Object.getPrototypeOf(obj).constructor) {
|
||||
case Array:
|
||||
switch (typeof obj === 'object' && obj !== null && Object.getPrototypeOf(obj)) {
|
||||
case Array.prototype:
|
||||
array.push(ARRAY, obj.length)
|
||||
obj.forEach(recurse)
|
||||
break
|
||||
case Object:
|
||||
case Object.prototype:
|
||||
temp = Object.getOwnPropertyNames(obj).sort()
|
||||
array.push(OBJECT, temp.length, ...temp)
|
||||
temp.forEach(key => recurse(obj[key]))
|
||||
break
|
||||
case RegExp:
|
||||
case RegExp.prototype:
|
||||
array.push(REGEXP, obj.toString())
|
||||
break
|
||||
case Date:
|
||||
case Date.prototype:
|
||||
array.push(DATE, obj.getTime())
|
||||
break
|
||||
case Buffer:
|
||||
case Buffer.prototype:
|
||||
array.push(BUFFER, obj.toString('binary'))
|
||||
break
|
||||
default:
|
||||
|
|
Loading…
Reference in New Issue