@@ -2,6 +2,7 @@ import referee from "@sinonjs/referee";
22import walk from "../../../../src/sinon/util/core/walk.js" ;
33import createSpy from "../../../../src/sinon/spy.js" ;
44const assert = referee . assert ;
5+ const refute = referee . refute ;
56
67describe ( "util/core/walk" , function ( ) {
78 it ( "should call iterator with value, key, and obj, with context as the receiver" , function ( ) {
@@ -163,4 +164,35 @@ describe("util/core/walk", function () {
163164 assert . equals ( index , propertyNames . lastIndexOf ( name ) ) ;
164165 } ) ;
165166 } ) ;
167+
168+ it ( "tracks visited names without inheriting Object.prototype properties" , function ( ) {
169+ const target = { } ;
170+ const iterator = createSpy ( ) ;
171+ const descriptor = Object . getOwnPropertyDescriptor (
172+ Object . prototype ,
173+ "someFlag" ,
174+ ) ;
175+
176+ // eslint-disable-next-line no-extend-native
177+ Object . defineProperty ( Object . prototype , "someFlag" , {
178+ value : "x" ,
179+ writable : false ,
180+ configurable : true ,
181+ } ) ;
182+
183+ try {
184+ refute . exception ( function ( ) {
185+ walk ( target , iterator ) ;
186+ } ) ;
187+
188+ assert ( iterator . calledWith ( "someFlag" , Object . prototype ) ) ;
189+ } finally {
190+ if ( descriptor ) {
191+ // eslint-disable-next-line no-extend-native
192+ Object . defineProperty ( Object . prototype , "someFlag" , descriptor ) ;
193+ } else {
194+ delete Object . prototype . someFlag ;
195+ }
196+ }
197+ } ) ;
166198} ) ;
0 commit comments