Browse Source

fix(common): Handle edge case in serializing null prototype objects

Michael Bromley 3 years ago
parent
commit
02249fbf3d
1 changed files with 3 additions and 1 deletions
  1. 3 1
      packages/common/src/shared-utils.ts

+ 3 - 1
packages/common/src/shared-utils.ts

@@ -24,7 +24,9 @@ export function isObject(item: any): item is object {
 }
 }
 
 
 export function isClassInstance(item: any): boolean {
 export function isClassInstance(item: any): boolean {
-    return isObject(item) && item.constructor.name !== 'Object';
+    // Even if item is an object, it might not have a constructor as in the
+    // case when it is a null-prototype object, i.e. created using `Object.create(null)`.
+    return isObject(item) && item.constructor && item.constructor.name !== 'Object';
 }
 }
 
 
 type NumericPropsOf<T> = {
 type NumericPropsOf<T> = {