@@ -175,3 +175,228 @@ try {
175175 assert ( e . message === "foo" ) ;
176176 assert ( e instanceof ReferenceError ) ;
177177}
178+
179+ // Checking behavior when the function's this_argument is undefined
180+ try {
181+ Array . prototype . splice . call ( undefined ) ;
182+ assert ( false ) ;
183+ } catch ( e ) {
184+ assert ( e instanceof TypeError ) ;
185+ }
186+
187+ // Checking behavior when length is an object, which throws error
188+ try {
189+ var o = { } ;
190+ Object . defineProperty ( o , 'toString' , { 'get' : function ( ) { throw new ReferenceError ( "foo" ) ; } } ) ;
191+ var a = { length : o } ;
192+ Array . prototype . splice . call ( a ) ;
193+ assert ( false ) ;
194+ } catch ( e ) {
195+ assert ( e instanceof ReferenceError ) ;
196+ assert ( e . message == "foo" ) ;
197+ }
198+
199+ // Checking behavior when the first argument of the function is an object, which throws error
200+ try {
201+ var o = { } ;
202+ Object . defineProperty ( o , 'toString' , { 'get' : function ( ) { throw new ReferenceError ( "1" ) ; } } ) ;
203+ [ 1 , 2 ] . splice ( o ) ;
204+ assert ( false ) ;
205+ } catch ( e ) {
206+ assert ( e instanceof ReferenceError ) ;
207+ assert ( e . message == "1" ) ;
208+ }
209+
210+ // Checking behavior when the second argument of the function is an object, which throws error
211+ try {
212+ var o = { } ;
213+ Object . defineProperty ( o , 'toString' , { 'get' : function ( ) { throw new ReferenceError ( "2" ) ; } } ) ;
214+ [ 1 , 2 ] . splice ( 1 , o ) ;
215+ assert ( false ) ;
216+ } catch ( e ) {
217+ assert ( e instanceof ReferenceError ) ;
218+ assert ( e . message == "2" ) ;
219+ }
220+
221+ // Checking behavior when the third element of the array throws error
222+ try {
223+ var a = [ 1 , 5 , , 2 ] ;
224+ Object . defineProperty ( a , '2' , { 'get' : function ( ) { throw new ReferenceError ( "3" ) ; } } ) ;
225+ a . splice ( 1 , 7 , 7 , 7 , 7 , 7 ) ;
226+ assert ( false ) ;
227+ } catch ( e ) {
228+ assert ( e instanceof ReferenceError ) ;
229+ assert ( e . message == "3" ) ;
230+ }
231+
232+ // Checking behavior when the function's this_argument is an object, witch only contains a length
233+ var a = { length : 13 } ;
234+ Array . prototype . splice . call ( a , function ( ) { delete a ; } ) ;
235+ assert ( a . length === 0 ) ;
236+
237+ // Checking behavior when the first element of the array throws error
238+ try {
239+ var a = [ 1 , 5 , 6 , 7 , 8 , 5 ] ;
240+ Object . defineProperty ( a , '0' , { 'get' : function ( ) { throw new ReferenceError ( "foo0" ) ; } } ) ;
241+ Array . prototype . splice . call ( a , 0 , 3 ) ;
242+ assert ( false ) ;
243+ } catch ( e ) {
244+ assert ( e instanceof ReferenceError ) ;
245+ assert ( e . message == "foo0" ) ;
246+ }
247+
248+ // Checking behavior when a modified object is an element of the array
249+ try {
250+ f = function ( )
251+ {
252+ delete arr [ 3 ] ;
253+ arr . length = 13 ;
254+ Object . defineProperty ( arr , '5' , function ( ) { } ) ;
255+ } ;
256+ obj = { get : f , valueOf : f , toString : f } ;
257+ arr = [ 1 , 2 , obj , 4 , 5 ] ;
258+ Object . defineProperty ( arr , '2' , { 'get' : f } ) ;
259+ for ( var i = 0 ; i < arr . length ; i ++ )
260+ {
261+ var a = arr [ i ] ;
262+ }
263+ arr . splice ( 1 , 4 , obj ) ;
264+ assert ( false ) ;
265+ } catch ( e ) {
266+ assert ( e instanceof TypeError ) ;
267+ }
268+
269+ // Checking behavior when a modified object is an element of the array and deletes the elements
270+ try {
271+ f = function ( )
272+ {
273+ for ( var i = 0 ; i < arr . length ; i ++ )
274+ {
275+ delete arr [ i ] ;
276+ }
277+ } ;
278+ obj = { get : f , valueOf : f , toString : f } ;
279+ arr = [ 1 , 2 , obj , 4 , 5 ] ;
280+ for ( var i = 0 ; i < 6 ; i ++ )
281+ {
282+ Object . defineProperty ( arr , i , { 'get' : f } ) ;
283+ }
284+ arr . splice ( 1 , 3 , obj ) ;
285+ assert ( false ) ;
286+ } catch ( e ) {
287+ assert ( e instanceof TypeError ) ;
288+ }
289+
290+ // Checking behavior when an element of the array throws error
291+ try {
292+ f = function ( ) { throw new TypeError ( "4" ) ; } ;
293+ obj = { get : f , valueOf : f , toString : f } ;
294+ arr = [ 1 , 2 , obj , 4 , 5 ] ;
295+ Object . defineProperty ( arr , '4' , { 'get' : f } ) ;
296+ arr . splice ( 1 , 3 , obj ) ;
297+ assert ( false ) ;
298+ } catch ( e ) {
299+ assert ( e instanceof TypeError ) ;
300+ assert ( e . message == "4" ) ;
301+ }
302+
303+ // Checking behavior when elements are getting deleted by an element wich only has a get function
304+ try {
305+ f = function ( )
306+ {
307+ for ( var i = 0 ; i < arr . length ; i ++ )
308+ {
309+ delete arr [ i ] ;
310+ }
311+ } ;
312+ arr = [ 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 , 10 , 11 , 12 ] ;
313+ delete arr [ 2 ] ;
314+ Object . defineProperty ( arr , '2' , { 'get' : f } ) ;
315+ arr . splice ( 1 , 7 , 5 ) ;
316+ } catch ( e ) {
317+ assert ( e instanceof TypeError ) ;
318+ }
319+
320+ // Checking behavior when the issue is the same as above, but splice has more arguments
321+ try {
322+ f = function ( )
323+ {
324+ for ( var i = 0 ; i < arr . length ; i ++ )
325+ {
326+ delete arr [ i ] ;
327+ }
328+ } ;
329+ arr = [ 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 , 10 , 11 ] ;
330+ delete arr [ 2 ] ;
331+ Object . defineProperty ( arr , '2' , { 'get' : f } ) ;
332+ arr . splice ( 1 , 7 , 5 , 5 , 5 , 5 ) ;
333+ assert ( false ) ;
334+ } catch ( e ) {
335+ assert ( e instanceof TypeError ) ;
336+ }
337+
338+
339+ // Checking behavior when first 3 elements throw error
340+ try {
341+ var a = [ 1 , 5 , 6 , 7 , 8 , 5 ] ;
342+ Object . defineProperty ( a , '1' , { 'get' : function ( ) { throw new ReferenceError ( "foo1" ) ; } } ) ;
343+ Object . defineProperty ( a , '0' , { 'get' : function ( ) { throw new ReferenceError ( "foo0" ) ; } } ) ;
344+ Object . defineProperty ( a , '2' , { 'get' : function ( ) { throw new ReferenceError ( "foo2" ) ; } } ) ;
345+ Array . prototype . splice . call ( a , 0 , 3 , 3 , 3 , 3 , 3 , 3 , 3 , 3 , 3 , 3 , 3 , 3 , 3 , 3 , 3 , 3 , 3 ) ;
346+ assert ( false ) ;
347+ } catch ( e ) {
348+ assert ( e instanceof ReferenceError ) ;
349+ assert ( e . message == "foo0" ) ;
350+ }
351+
352+ // Checking behavior when the last element throws error
353+ try {
354+ f = function ( )
355+ {
356+ for ( var i = 0 ; i < arr . length ; i ++ )
357+ {
358+ delete arr [ i ] ;
359+ }
360+ } ;
361+ arr = [ 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 , 10 , 11 , 12 , 13 , 14 , 15 , 16 , 17 , 18 , 19 , 20 , 21 , 22 , 23 , 24 ] ;
362+ delete arr [ 23 ] ;
363+ Object . defineProperty ( arr , '23' , { 'get' : f } ) ;
364+ arr . splice ( 1 , 7 , 5 , 5 , 5 , 5 , 5 , 5 , 5 , 5 , 5 , 5 , 5 , 5 , 5 , 5 , 5 , 5 , 5 , 5 , 5 ) ;
365+ assert ( false ) ;
366+ } catch ( e ) {
367+ assert ( e instanceof TypeError ) ;
368+ }
369+
370+ // Checking behavior when a yet non existing element will throw an error
371+ try {
372+ f = function ( ) { throw new TypeError ( "6" ) ; } ;
373+ arr = [ 1 , 2 , 4 , 5 ] ;
374+ Object . defineProperty ( arr , '4' , { 'get' : f } ) ;
375+ arr . splice ( 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 , 10 ) ;
376+ assert ( false ) ;
377+ } catch ( e ) {
378+ assert ( e instanceof TypeError ) ;
379+ assert ( e . message == "6" ) ;
380+ }
381+
382+ // Checking behavior when the last element gets deleted
383+ try {
384+ f = function ( ) { delete arr [ 23 ] ; } ;
385+ arr = [ 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 , 10 , 11 , 12 , 13 , 14 , 15 , 16 , 17 , 18 , 19 , 20 , 21 , 22 , 23 , 24 ] ;
386+ delete arr [ 23 ] ;
387+ Object . defineProperty ( arr , '23' , { 'get' : f } ) ;
388+ arr . splice ( 1 , 7 , 5 , 5 , 5 , 5 , 5 , 5 , 5 , 5 , 5 , 5 , 5 , 5 , 5 , 5 , 5 , 5 , 5 , 5 , 5 ) ;
389+ assert ( false ) ;
390+ } catch ( e ) {
391+ assert ( e instanceof TypeError ) ;
392+ }
393+
394+ // Checking behavior when the array is empty, large, and not writable
395+ try {
396+ arr = [ ] ;
397+ Object . defineProperty ( arr , 'length' , { value : 999 , writable : false } ) ;
398+ arr . splice ( 1 , 2 , 4 , 5 ) ;
399+ assert ( false ) ;
400+ } catch ( e ) {
401+ assert ( e instanceof TypeError ) ;
402+ }
0 commit comments