-
-
Notifications
You must be signed in to change notification settings - Fork 4.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #17374 from jacobq/test-for-prototype-extension-re…
…gression [BUGFIX release] Fix cyclic references on Array.prototype
- Loading branch information
Showing
2 changed files
with
48 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
31 changes: 31 additions & 0 deletions
31
packages/@ember/-internals/runtime/tests/array/apply-test.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import { NativeArray } from '../../lib/mixins/array'; | ||
import { AbstractTestCase, moduleFor } from 'internal-test-helpers'; | ||
|
||
class ArrayPrototypeExtensionSelfReferenceTests extends AbstractTestCase { | ||
'@test should not create non-Symbol, enumerable properties that refer to itself'() { | ||
// Don't want to pollute Array.prototype so we make a fake / simple prototype | ||
function ThrowAwayArray() {} | ||
|
||
// Extend our throw-away prototype (like EXTEND_PROTOTYPES.Array would) | ||
NativeArray.apply(ThrowAwayArray.prototype); | ||
|
||
// Create an instance to test | ||
let obj = new ThrowAwayArray(); | ||
|
||
// Make sure that no enumerable properties refer back to the object (creating a cyclic structure) | ||
for (let p in obj) { | ||
this.assert.notStrictEqual( | ||
obj[p], | ||
obj, | ||
`Property "${p}" is an enumerable part of the prototype | ||
so must not refer back to the original array. | ||
Otherwise code that explores all properties, | ||
such as jQuery.extend and other "deep cloning" functions, | ||
will get stuck in an infinite loop. | ||
`.replace(/\s+/g, ' ') | ||
); | ||
} | ||
} | ||
} | ||
|
||
moduleFor(`NativeArray: apply`, ArrayPrototypeExtensionSelfReferenceTests); |