File tree Expand file tree Collapse file tree 2 files changed +13
-2
lines changed
Expand file tree Collapse file tree 2 files changed +13
-2
lines changed Original file line number Diff line number Diff line change @@ -4,7 +4,7 @@ import { isSyntheticEvent, isVueViewModel } from './is';
44import { convertToPlainObject } from './object' ;
55import { getFunctionName } from './stacktrace' ;
66
7- type Prototype = { constructor : ( ...args : unknown [ ] ) => unknown } ;
7+ type Prototype = { constructor ? : ( ...args : unknown [ ] ) => unknown } ;
88// This is a hack to placate TS, relying on the fact that technically, arrays are objects with integer keys. Normally we
99// think of those keys as actual numbers, but `arr['0']` turns out to work just as well as `arr[0]`, and doing it this
1010// way lets us use a single type in the places where behave as if we are only dealing with objects, even if some of them
@@ -264,7 +264,7 @@ function stringifyValue(
264264function getConstructorName ( value : unknown ) : string {
265265 const prototype : Prototype | null = Object . getPrototypeOf ( value ) ;
266266
267- return prototype ? prototype . constructor . name : 'null prototype' ;
267+ return prototype ?. constructor ? prototype . constructor . name : 'null prototype' ;
268268}
269269
270270/** Calculates bytes size of input string */
Original file line number Diff line number Diff line change @@ -484,6 +484,17 @@ describe('normalize()', () => {
484484 foo : '[VueViewModel]' ,
485485 } ) ;
486486 } ) ;
487+
488+ test ( 'null prototype' , ( ) => {
489+ const obj = Object . create ( null ) ;
490+ expect ( normalize ( obj , 0 ) ) . toEqual ( '[null prototype]' ) ;
491+ } ) ;
492+
493+ test ( 'null prototype base' , ( ) => {
494+ const base = Object . create ( null ) ;
495+ const obj = Object . create ( base ) ;
496+ expect ( normalize ( obj , 0 ) ) . toEqual ( '[null prototype]' ) ;
497+ } ) ;
487498 } ) ;
488499
489500 describe ( 'can limit object to depth' , ( ) => {
You can’t perform that action at this time.
0 commit comments