@@ -56,6 +56,8 @@ var isNonNullishPrimitive = function isNonNullishPrimitive(v) {
56
56
|| typeof v === 'bigint' ;
57
57
} ;
58
58
59
+ var sentinel = { } ;
60
+
59
61
var stringify = function stringify (
60
62
object ,
61
63
prefix ,
@@ -75,8 +77,23 @@ var stringify = function stringify(
75
77
) {
76
78
var obj = object ;
77
79
78
- if ( sideChannel . has ( object ) ) {
79
- throw new RangeError ( 'Cyclic object value' ) ;
80
+ var tmpSc = sideChannel ;
81
+ var step = 0 ;
82
+ var findFlag = false ;
83
+ while ( ( tmpSc = tmpSc . get ( sentinel ) ) !== undefined && ! findFlag ) {
84
+ // Where object last appeared in the ref tree
85
+ var pos = tmpSc . get ( object ) ;
86
+ step += 1 ;
87
+ if ( typeof pos !== 'undefined' ) {
88
+ if ( pos === step ) {
89
+ throw new RangeError ( 'Cyclic object value' ) ;
90
+ } else {
91
+ findFlag = true ; // Break while
92
+ }
93
+ }
94
+ if ( typeof tmpSc . get ( sentinel ) === 'undefined' ) {
95
+ step = 0 ;
96
+ }
80
97
}
81
98
82
99
if ( typeof filter === 'function' ) {
@@ -145,8 +162,9 @@ var stringify = function stringify(
145
162
? typeof generateArrayPrefix === 'function' ? generateArrayPrefix ( prefix , key ) : prefix
146
163
: prefix + ( allowDots ? '.' + key : '[' + key + ']' ) ;
147
164
148
- sideChannel . set ( object , true ) ;
165
+ sideChannel . set ( object , step ) ;
149
166
var valueSideChannel = getSideChannel ( ) ;
167
+ valueSideChannel . set ( sentinel , sideChannel ) ;
150
168
pushToArray ( values , stringify (
151
169
value ,
152
170
keyPrefix ,
0 commit comments