File tree Expand file tree Collapse file tree 2 files changed +22
-2
lines changed
Expand file tree Collapse file tree 2 files changed +22
-2
lines changed Original file line number Diff line number Diff line change @@ -56,7 +56,7 @@ describe('createCache', () => {
5656} ) ;
5757
5858describe ( 'getCleanClone' , ( ) => {
59- it ( 'will return a pure object when there is no constructor ' , ( ) => {
59+ it ( 'will return a pure object when there is no prototype ' , ( ) => {
6060 const object = Object . create ( null ) ;
6161
6262 const result = utils . getCleanClone ( Object . getPrototypeOf ( object ) ) ;
@@ -67,6 +67,23 @@ describe('getCleanClone', () => {
6767 expect ( Object . getPrototypeOf ( result ) ) . toBe ( null ) ;
6868 } ) ;
6969
70+ it ( 'will return a pure object when there is a prototype but no constructor' , ( ) => {
71+ const Empty = function ( ) {
72+ // empty
73+ } ;
74+ Empty . prototype = Object . create ( null ) ;
75+
76+ // @ts -expect-error - Testing `fast-querystring` V8 optimization
77+ const object = new Empty ( ) ;
78+
79+ const result = utils . getCleanClone ( Object . getPrototypeOf ( object ) ) ;
80+
81+ expect ( result ) . not . toBe ( object ) ;
82+ expect ( result ) . toEqual ( object ) ;
83+
84+ expect ( Object . getPrototypeOf ( result ) ) . toBe ( Empty . prototype ) ;
85+ } ) ;
86+
7087 it ( 'will return a pure object when there is no __proto__ property' , ( ) => {
7188 const object : PlainObject = { } ;
7289
Original file line number Diff line number Diff line change @@ -57,7 +57,10 @@ export function getCleanClone(prototype: any): any {
5757 return prototype === Object . prototype ? { } : create ( prototype ) ;
5858 }
5959
60- if ( ~ toStringFunction . call ( Constructor ) . indexOf ( '[native code]' ) ) {
60+ if (
61+ Constructor &&
62+ ~ toStringFunction . call ( Constructor ) . indexOf ( '[native code]' )
63+ ) {
6164 try {
6265 return new Constructor ( ) ;
6366 } catch { }
You can’t perform that action at this time.
0 commit comments