don't crash on objects with null prototype

This commit is contained in:
Conduitry 2018-03-18 03:12:10 -04:00
parent be31d8a11e
commit 92ce930651
2 changed files with 8 additions and 6 deletions

View File

@ -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:

View File

@ -74,3 +74,5 @@ assert.notEqual(call(true), call(true, undefined))
assert.notEqual(call(), memor.memoize(() => ++calledCount)())
assert.equal(call(), memor.memoize(func)())
assert.notEqual(call(Object.create(null)), call(Object.create(null)))