File tree Expand file tree Collapse file tree
packages/@ember/-internals/runtime/tests/array Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ import { NativeArray } from '../../lib/mixins/array' ;
2+ import { AbstractTestCase , moduleFor } from 'internal-test-helpers' ;
3+
4+ class ArrayPrototypeExtensionSelfReferenceTests extends AbstractTestCase {
5+ '@test should not create non-Symbol, enumerable properties that refer to itself' ( ) {
6+ // Don't want to pollute Array.prototype so we make our own to extend
7+ class ThrowAwayArray extends Array { }
8+
9+ // Extend our throw-away prototype (like EXTEND_PROTOTYPES.Array would)
10+ NativeArray . apply ( ThrowAwayArray . prototype ) ;
11+
12+ // Create an instance to test
13+ let obj = new ThrowAwayArray ( ) ;
14+
15+ // Make sure we have an array-like thing & avoid the zero assertion problem is there are no enumerable properties
16+ this . assert . strictEqual ( obj . length , 0 ) ;
17+
18+ // Make sure that no enumerable properties refer back to the object (creating a cyclic structure)
19+ for ( let p in obj ) {
20+ this . assert . notStrictEqual (
21+ obj [ p ] ,
22+ obj ,
23+ `Property "${ p } " is an enumerable part of the prototype
24+ so must not refer back to the original array.
25+ Otherwise code that explores all properties,
26+ such as jQuery.extend and other "deep cloning" functions,
27+ will get stuck in an infinite loop.
28+ ` . replace ( / \s + / g, ' ' )
29+ ) ;
30+ }
31+ }
32+ }
33+
34+ moduleFor ( `NativeArray: apply` , ArrayPrototypeExtensionSelfReferenceTests ) ;
You can’t perform that action at this time.
0 commit comments