Skip to content

Commit f233f28

Browse files
committed
Never clone List objects
1 parent fcb909a commit f233f28

File tree

3 files changed

+20
-2
lines changed

3 files changed

+20
-2
lines changed

src/GroupableCollection.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ var SELF = wb.datamodel.GroupableCollection = function WbDataModelGroupableColle
1515

1616
$.extend( SELF.prototype, {
1717
/**
18-
* Returns a copy of the collection items as list.
18+
* Returns the collection items as list.
1919
* @abstract
2020
*
2121
* @return {*[]}

src/List.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ var SELF = wb.datamodel.List = util.inherit(
7171
* @inheritdoc
7272
*/
7373
toArray: function() {
74-
return this._items.slice();
74+
return this._items;
7575
},
7676

7777
/**

tests/List.tests.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,24 @@ QUnit.test( 'each()', function( assert ) {
7777
} );
7878
} );
7979

80+
QUnit.test( 'toArray()', function( assert ) {
81+
assert.expect( 2 );
82+
var item = new TestItem(),
83+
list = new wb.datamodel.List( TestItem, [item] ),
84+
actual = list.toArray();
85+
86+
assert.ok(
87+
actual.length === 1 && actual[0] === item,
88+
'toArray() returns original items.'
89+
);
90+
91+
assert.strictEqual(
92+
list.toArray(),
93+
actual,
94+
'toArray() does not clone.'
95+
);
96+
} );
97+
8098
QUnit.test( 'hasItem()', function( assert ) {
8199
assert.expect( 2 );
82100
var items = getTestItems( 3 ),

0 commit comments

Comments
 (0)