8
0
Quellcode durchsuchen

element.children is now protected.

Piotr Jasiun vor 10 Jahren
Ursprung
Commit
2b1d78116e

+ 36 - 7
packages/ckeditor5-utils/src/document/element.js

@@ -37,10 +37,10 @@ CKEDITOR.define( [ 'document/node', 'document/nodelist' ], function( Node, NodeL
 			/**
 			 * List of children nodes.
 			 *
-			 * @readonly
-			 * @property {document.NodeList} children
+			 * @protected
+			 * @property {document.NodeList} _children
 			 */
-			this.children = new NodeList();
+			this._children = new NodeList();
 
 			if ( children ) {
 				this.insertChildren( 0, children );
@@ -58,9 +58,9 @@ CKEDITOR.define( [ 'document/node', 'document/nodelist' ], function( Node, NodeL
 		 * List of nodes can be any type accepted by the {@link document.NodeList} constructor.
 		 */
 		insertChildren( index, nodes ) {
-			this.children.insert( index, new NodeList( nodes ) );
+			this._children.insert( index, new NodeList( nodes ) );
 
-			for ( var node of this.children ) {
+			for ( var node of this._children ) {
 				node.parent = this;
 			}
 		}
@@ -77,10 +77,39 @@ CKEDITOR.define( [ 'document/node', 'document/nodelist' ], function( Node, NodeL
 
 		removeChildren( index, number ) {
 			for ( var i = index; i < index + number; i++ ) {
-				this.children.get( i ).parent = null;
+				this._children.get( i ).parent = null;
 			}
 
-			this.children.remove( index, number );
+			this._children.remove( index, number );
+		}
+
+		/**
+		 * Get child at given index.
+		 *
+		 * @param {Number} index Index of child.
+		 * @returns {document.Node} Child node.
+		 */
+		getChild( index ) {
+			return this._children.get( index );
+		}
+
+		/**
+		 * Get index of child node.
+		 *
+		 * @param {document.Node} node Child node.
+		 * @returns {Number} Index of child.
+		 */
+		getChildIndex( node ) {
+			return this._children.indexOf( node );
+		}
+
+		/**
+		 * Gets number of element's children.
+		 *
+		 * @returns {Number} Number of element's children.
+		 */
+		getChildCount() {
+			return this._children.length;
 		}
 	}
 

+ 1 - 1
packages/ckeditor5-utils/src/document/moveoperation.js

@@ -73,7 +73,7 @@ CKEDITOR.define( [
 				var i = 0;
 
 				for ( var node of this.nodeList ) {
-					if ( !utils.isEqual( sourceElement.children.get( sourceOffset + i ), node ) ) {
+					if ( !utils.isEqual( sourceElement.getChild( sourceOffset + i ), node ) ) {
 						/**
 						 * The node which should be removed does not exists.
 						 *

+ 3 - 3
packages/ckeditor5-utils/src/document/node.js

@@ -89,7 +89,7 @@ CKEDITOR.define( [ 'document/attribute', 'utils' ], function( Attribute, utils )
 			var pos;
 
 			// No parent or child doesn't exist in parent's children.
-			if ( !this.parent || ( pos = this.parent.children.indexOf( this ) ) == -1 ) {
+			if ( !this.parent || ( pos = this.parent.getChildIndex( this ) ) == -1 ) {
 				return null;
 			}
 
@@ -140,7 +140,7 @@ CKEDITOR.define( [ 'document/attribute', 'utils' ], function( Attribute, utils )
 		get nextSibling() {
 			var pos = this.positionInParent;
 
-			return ( pos !== null && this.parent.children.get( pos + 1 ) ) || null;
+			return ( pos !== null && this.parent.getChild( pos + 1 ) ) || null;
 		}
 
 		/**
@@ -152,7 +152,7 @@ CKEDITOR.define( [ 'document/attribute', 'utils' ], function( Attribute, utils )
 		get previousSibling() {
 			var pos = this.positionInParent;
 
-			return ( pos !== null && this.parent.children.get( pos - 1 ) ) || null;
+			return ( pos !== null && this.parent.getChild( pos - 1 ) ) || null;
 		}
 
 		/**

+ 3 - 3
packages/ckeditor5-utils/src/document/position.js

@@ -112,7 +112,7 @@ CKEDITOR.define( [ 'utils', 'ckeditorerror' ], function( utils, CKEditorError )
 			var i, len;
 
 			for ( i = 0, len = this.path.length - 1; i < len; i++ ) {
-				parent = parent.children.get( this.path[ i ] );
+				parent = parent.getChild( this.path[ i ] );
 			}
 
 			return parent;
@@ -135,7 +135,7 @@ CKEDITOR.define( [ 'utils', 'ckeditorerror' ], function( utils, CKEditorError )
 		 * @type {Node}
 		 */
 		get nodeBefore() {
-			return this.parent.children.get( this.offset - 1 ) || null;
+			return this.parent.getChild( this.offset - 1 ) || null;
 		}
 
 		/**
@@ -145,7 +145,7 @@ CKEDITOR.define( [ 'utils', 'ckeditorerror' ], function( utils, CKEditorError )
 		 * @type {Node}
 		 */
 		get nodeAfter() {
-			return this.parent.children.get( this.offset ) || null;
+			return this.parent.getChild( this.offset ) || null;
 		}
 
 		/**

+ 2 - 2
packages/ckeditor5-utils/src/document/positioniterator.js

@@ -66,7 +66,7 @@ CKEDITOR.define( [
 			var parent = position.parent;
 
 			// We are at the end of the root.
-			if ( parent.parent === null && position.offset === parent.children.length ) {
+			if ( parent.parent === null && position.offset === parent.getChildCount() ) {
 				return { done: true };
 			}
 
@@ -117,7 +117,7 @@ CKEDITOR.define( [
 			var nodeBefore = position.nodeBefore;
 
 			if ( nodeBefore instanceof Element ) {
-				this.position = Position.makePositionFromParentAndOffset( nodeBefore, nodeBefore.children.length );
+				this.position = Position.makePositionFromParentAndOffset( nodeBefore, nodeBefore.getChildCount() );
 
 				return formatReturnValue( CLOSING_TAG, nodeBefore );
 			} else if ( nodeBefore instanceof Character ) {

+ 1 - 1
packages/ckeditor5-utils/src/document/removeoperation.js

@@ -63,7 +63,7 @@ CKEDITOR.define( [
 				var i = 0;
 
 				for ( var node of this.nodeList ) {
-					if ( !utils.isEqual( parent.children.get( offset + i ), node ) ) {
+					if ( !utils.isEqual( parent.getChild( offset + i ), node ) ) {
 						/**
 						 * The node which should be removed does not exists.
 						 *

+ 58 - 58
packages/ckeditor5-utils/tests/document/changeoperation.js

@@ -39,10 +39,10 @@ describe( 'ChangeOperation', function() {
 			doc.version ) );
 
 		expect( doc.version ).to.be.equal( 1 );
-		expect( doc.root.children.length ).to.be.equal( 3 );
-		expect( doc.root.children.get( 0 ).hasAttr( newAttr ) ).to.be.true;
-		expect( doc.root.children.get( 1 ).hasAttr( newAttr ) ).to.be.true;
-		expect( doc.root.children.get( 2 ).attrs.length ).to.be.equal( 0 );
+		expect( doc.root.getChildCount() ).to.be.equal( 3 );
+		expect( doc.root.getChild( 0 ).hasAttr( newAttr ) ).to.be.true;
+		expect( doc.root.getChild( 1 ).hasAttr( newAttr ) ).to.be.true;
+		expect( doc.root.getChild( 2 ).attrs.length ).to.be.equal( 0 );
 	} );
 
 	it( 'should insert attribute to multiple ranges', function() {
@@ -68,10 +68,10 @@ describe( 'ChangeOperation', function() {
 			doc.version ) );
 
 		expect( doc.version ).to.be.equal( 1 );
-		expect( doc.root.children.length ).to.be.equal( 3 );
-		expect( doc.root.children.get( 0 ).hasAttr( newAttr ) ).to.be.true;
-		expect( doc.root.children.get( 1 ).attrs.length ).to.be.equal( 0 );
-		expect( doc.root.children.get( 2 ).hasAttr( newAttr ) ).to.be.true;
+		expect( doc.root.getChildCount() ).to.be.equal( 3 );
+		expect( doc.root.getChild( 0 ).hasAttr( newAttr ) ).to.be.true;
+		expect( doc.root.getChild( 1 ).attrs.length ).to.be.equal( 0 );
+		expect( doc.root.getChild( 2 ).hasAttr( newAttr ) ).to.be.true;
 	} );
 
 	it( 'should add attribute to the existing attributes', function() {
@@ -97,11 +97,11 @@ describe( 'ChangeOperation', function() {
 			doc.version ) );
 
 		expect( doc.version ).to.be.equal( 1 );
-		expect( doc.root.children.length ).to.be.equal( 1 );
-		expect( doc.root.children.get( 0 ).attrs.length ).to.be.equal( 3 );
-		expect( doc.root.children.get( 0 ).hasAttr( newAttr ) ).to.be.true;
-		expect( doc.root.children.get( 0 ).hasAttr( fooAttr ) ).to.be.true;
-		expect( doc.root.children.get( 0 ).hasAttr( barAttr ) ).to.be.true;
+		expect( doc.root.getChildCount() ).to.be.equal( 1 );
+		expect( doc.root.getChild( 0 ).attrs.length ).to.be.equal( 3 );
+		expect( doc.root.getChild( 0 ).hasAttr( newAttr ) ).to.be.true;
+		expect( doc.root.getChild( 0 ).hasAttr( fooAttr ) ).to.be.true;
+		expect( doc.root.getChild( 0 ).hasAttr( barAttr ) ).to.be.true;
 	} );
 
 	it( 'should change attributes on multiple ranges', function() {
@@ -129,13 +129,13 @@ describe( 'ChangeOperation', function() {
 			doc.version ) );
 
 		expect( doc.version ).to.be.equal( 1 );
-		expect( doc.root.children.length ).to.be.equal( 3 );
-		expect( doc.root.children.get( 0 ).attrs.length ).to.be.equal( 1 );
-		expect( doc.root.children.get( 0 ).hasAttr( newAttr ) ).to.be.true;
-		expect( doc.root.children.get( 1 ).attrs.length ).to.be.equal( 1 );
-		expect( doc.root.children.get( 1 ).hasAttr( oldAttr ) ).to.be.true;
-		expect( doc.root.children.get( 2 ).attrs.length ).to.be.equal( 1 );
-		expect( doc.root.children.get( 2 ).hasAttr( newAttr ) ).to.be.true;
+		expect( doc.root.getChildCount() ).to.be.equal( 3 );
+		expect( doc.root.getChild( 0 ).attrs.length ).to.be.equal( 1 );
+		expect( doc.root.getChild( 0 ).hasAttr( newAttr ) ).to.be.true;
+		expect( doc.root.getChild( 1 ).attrs.length ).to.be.equal( 1 );
+		expect( doc.root.getChild( 1 ).hasAttr( oldAttr ) ).to.be.true;
+		expect( doc.root.getChild( 2 ).attrs.length ).to.be.equal( 1 );
+		expect( doc.root.getChild( 2 ).hasAttr( newAttr ) ).to.be.true;
 	} );
 
 	it( 'should change attribute to the set of nodes', function() {
@@ -160,13 +160,13 @@ describe( 'ChangeOperation', function() {
 			doc.version ) );
 
 		expect( doc.version ).to.be.equal( 1 );
-		expect( doc.root.children.length ).to.be.equal( 3 );
-		expect( doc.root.children.get( 0 ).attrs.length ).to.be.equal( 1 );
-		expect( doc.root.children.get( 0 ).hasAttr( newAttr ) ).to.be.true;
-		expect( doc.root.children.get( 1 ).attrs.length ).to.be.equal( 1 );
-		expect( doc.root.children.get( 1 ).hasAttr( newAttr ) ).to.be.true;
-		expect( doc.root.children.get( 2 ).attrs.length ).to.be.equal( 1 );
-		expect( doc.root.children.get( 2 ).hasAttr( oldAttr ) ).to.be.true;
+		expect( doc.root.getChildCount() ).to.be.equal( 3 );
+		expect( doc.root.getChild( 0 ).attrs.length ).to.be.equal( 1 );
+		expect( doc.root.getChild( 0 ).hasAttr( newAttr ) ).to.be.true;
+		expect( doc.root.getChild( 1 ).attrs.length ).to.be.equal( 1 );
+		expect( doc.root.getChild( 1 ).hasAttr( newAttr ) ).to.be.true;
+		expect( doc.root.getChild( 2 ).attrs.length ).to.be.equal( 1 );
+		expect( doc.root.getChild( 2 ).hasAttr( oldAttr ) ).to.be.true;
 	} );
 
 	it( 'should change attribute in the middle of existing attributes', function() {
@@ -193,11 +193,11 @@ describe( 'ChangeOperation', function() {
 			doc.version ) );
 
 		expect( doc.version ).to.be.equal( 1 );
-		expect( doc.root.children.length ).to.be.equal( 1 );
-		expect( doc.root.children.get( 0 ).attrs.length ).to.be.equal( 3 );
-		expect( doc.root.children.get( 0 ).hasAttr( fooAttr ) ).to.be.true;
-		expect( doc.root.children.get( 0 ).hasAttr( x2Attr ) ).to.be.true;
-		expect( doc.root.children.get( 0 ).hasAttr( barAttr ) ).to.be.true;
+		expect( doc.root.getChildCount() ).to.be.equal( 1 );
+		expect( doc.root.getChild( 0 ).attrs.length ).to.be.equal( 3 );
+		expect( doc.root.getChild( 0 ).hasAttr( fooAttr ) ).to.be.true;
+		expect( doc.root.getChild( 0 ).hasAttr( x2Attr ) ).to.be.true;
+		expect( doc.root.getChild( 0 ).hasAttr( barAttr ) ).to.be.true;
 	} );
 
 	it( 'should remove attribute', function() {
@@ -223,10 +223,10 @@ describe( 'ChangeOperation', function() {
 			doc.version ) );
 
 		expect( doc.version ).to.be.equal( 1 );
-		expect( doc.root.children.length ).to.be.equal( 1 );
-		expect( doc.root.children.get( 0 ).attrs.length ).to.be.equal( 2 );
-		expect( doc.root.children.get( 0 ).hasAttr( fooAttr ) ).to.be.true;
-		expect( doc.root.children.get( 0 ).hasAttr( barAttr ) ).to.be.true;
+		expect( doc.root.getChildCount() ).to.be.equal( 1 );
+		expect( doc.root.getChild( 0 ).attrs.length ).to.be.equal( 2 );
+		expect( doc.root.getChild( 0 ).hasAttr( fooAttr ) ).to.be.true;
+		expect( doc.root.getChild( 0 ).hasAttr( barAttr ) ).to.be.true;
 	} );
 
 	it( 'should remove attributes on multiple ranges', function() {
@@ -253,10 +253,10 @@ describe( 'ChangeOperation', function() {
 			doc.version ) );
 
 		expect( doc.version ).to.be.equal( 1 );
-		expect( doc.root.children.length ).to.be.equal( 3 );
-		expect( doc.root.children.get( 0 ).attrs.length ).to.be.equal( 0 );
-		expect( doc.root.children.get( 1 ).hasAttr( fooAttr ) ).to.be.true;
-		expect( doc.root.children.get( 2 ).attrs.length ).to.be.equal( 0 );
+		expect( doc.root.getChildCount() ).to.be.equal( 3 );
+		expect( doc.root.getChild( 0 ).attrs.length ).to.be.equal( 0 );
+		expect( doc.root.getChild( 1 ).hasAttr( fooAttr ) ).to.be.true;
+		expect( doc.root.getChild( 2 ).attrs.length ).to.be.equal( 0 );
 	} );
 
 	it( 'should create a change operation as a reverse', function() {
@@ -310,10 +310,10 @@ describe( 'ChangeOperation', function() {
 		doc.applyOperation( reverse );
 
 		expect( doc.version ).to.be.equal( 2 );
-		expect( doc.root.children.length ).to.be.equal( 3 );
-		expect( doc.root.children.get( 0 ).attrs.length ).to.be.equal( 0 );
-		expect( doc.root.children.get( 1 ).attrs.length ).to.be.equal( 0 );
-		expect( doc.root.children.get( 2 ).attrs.length ).to.be.equal( 0 );
+		expect( doc.root.getChildCount() ).to.be.equal( 3 );
+		expect( doc.root.getChild( 0 ).attrs.length ).to.be.equal( 0 );
+		expect( doc.root.getChild( 1 ).attrs.length ).to.be.equal( 0 );
+		expect( doc.root.getChild( 2 ).attrs.length ).to.be.equal( 0 );
 	} );
 
 	it( 'should undo change attribute by applying reverse operation', function() {
@@ -344,13 +344,13 @@ describe( 'ChangeOperation', function() {
 		doc.applyOperation( reverse );
 
 		expect( doc.version ).to.be.equal( 2 );
-		expect( doc.root.children.length ).to.be.equal( 3 );
-		expect( doc.root.children.get( 0 ).attrs.length ).to.be.equal( 1 );
-		expect( doc.root.children.get( 0 ).hasAttr( oldAttr ) ).to.be.true;
-		expect( doc.root.children.get( 1 ).attrs.length ).to.be.equal( 1 );
-		expect( doc.root.children.get( 1 ).hasAttr( oldAttr ) ).to.be.true;
-		expect( doc.root.children.get( 2 ).attrs.length ).to.be.equal( 1 );
-		expect( doc.root.children.get( 2 ).hasAttr( oldAttr ) ).to.be.true;
+		expect( doc.root.getChildCount() ).to.be.equal( 3 );
+		expect( doc.root.getChild( 0 ).attrs.length ).to.be.equal( 1 );
+		expect( doc.root.getChild( 0 ).hasAttr( oldAttr ) ).to.be.true;
+		expect( doc.root.getChild( 1 ).attrs.length ).to.be.equal( 1 );
+		expect( doc.root.getChild( 1 ).hasAttr( oldAttr ) ).to.be.true;
+		expect( doc.root.getChild( 2 ).attrs.length ).to.be.equal( 1 );
+		expect( doc.root.getChild( 2 ).hasAttr( oldAttr ) ).to.be.true;
 	} );
 
 	it( 'should undo remove attribute by applying reverse operation', function() {
@@ -380,13 +380,13 @@ describe( 'ChangeOperation', function() {
 		doc.applyOperation( reverse );
 
 		expect( doc.version ).to.be.equal( 2 );
-		expect( doc.root.children.length ).to.be.equal( 3 );
-		expect( doc.root.children.get( 0 ).attrs.length ).to.be.equal( 1 );
-		expect( doc.root.children.get( 0 ).hasAttr( fooAttr ) ).to.be.true;
-		expect( doc.root.children.get( 1 ).attrs.length ).to.be.equal( 1 );
-		expect( doc.root.children.get( 1 ).hasAttr( fooAttr ) ).to.be.true;
-		expect( doc.root.children.get( 2 ).attrs.length ).to.be.equal( 1 );
-		expect( doc.root.children.get( 2 ).hasAttr( fooAttr ) ).to.be.true;
+		expect( doc.root.getChildCount() ).to.be.equal( 3 );
+		expect( doc.root.getChild( 0 ).attrs.length ).to.be.equal( 1 );
+		expect( doc.root.getChild( 0 ).hasAttr( fooAttr ) ).to.be.true;
+		expect( doc.root.getChild( 1 ).attrs.length ).to.be.equal( 1 );
+		expect( doc.root.getChild( 1 ).hasAttr( fooAttr ) ).to.be.true;
+		expect( doc.root.getChild( 2 ).attrs.length ).to.be.equal( 1 );
+		expect( doc.root.getChild( 2 ).hasAttr( fooAttr ) ).to.be.true;
 	} );
 
 	it( 'should throw an error when one try to remove and the attribute does not exists', function() {

+ 42 - 17
packages/ckeditor5-utils/tests/document/element.js

@@ -52,10 +52,10 @@ describe( 'constructor', function() {
 		var element = new Element( 'elem', [], 'foo' );
 
 		expect( element ).to.have.property( 'name' ).that.equals( 'elem' );
-		expect( element ).to.have.property( 'children' ).with.length( 3 );
-		expect( element.children.get( 0 ) ).to.have.property( 'character' ).that.equals( 'f' );
-		expect( element.children.get( 1 ) ).to.have.property( 'character' ).that.equals( 'o' );
-		expect( element.children.get( 2 ) ).to.have.property( 'character' ).that.equals( 'o' );
+		expect( element.getChildCount() ).to.be.equals( 3 );
+		expect( element.getChild( 0 ) ).to.have.property( 'character' ).that.equals( 'f' );
+		expect( element.getChild( 1 ) ).to.have.property( 'character' ).that.equals( 'o' );
+		expect( element.getChild( 2 ) ).to.have.property( 'character' ).that.equals( 'o' );
 	} );
 } );
 
@@ -67,12 +67,12 @@ describe( 'insertChildren', function() {
 		element.insertChildren( 1, 'foo' );
 
 		expect( element ).to.have.property( 'name' ).that.equals( 'elem' );
-		expect( element ).to.have.property( 'children' ).with.length( 5 );
-		expect( element.children.get( 0 ) ).to.have.property( 'character' ).that.equals( 'x' );
-		expect( element.children.get( 1 ) ).to.have.property( 'character' ).that.equals( 'f' );
-		expect( element.children.get( 2 ) ).to.have.property( 'character' ).that.equals( 'o' );
-		expect( element.children.get( 3 ) ).to.have.property( 'character' ).that.equals( 'o' );
-		expect( element.children.get( 4 ) ).to.have.property( 'character' ).that.equals( 'y' );
+		expect( element.getChildCount() ).to.be.equals( 5 );
+		expect( element.getChild( 0 ) ).to.have.property( 'character' ).that.equals( 'x' );
+		expect( element.getChild( 1 ) ).to.have.property( 'character' ).that.equals( 'f' );
+		expect( element.getChild( 2 ) ).to.have.property( 'character' ).that.equals( 'o' );
+		expect( element.getChild( 3 ) ).to.have.property( 'character' ).that.equals( 'o' );
+		expect( element.getChild( 4 ) ).to.have.property( 'character' ).that.equals( 'y' );
 	} );
 } );
 
@@ -81,18 +81,43 @@ describe( 'removeChildren', function() {
 		var Element = modules[ 'document/element' ];
 
 		var element = new Element( 'elem', [], [ 'foobar' ] );
-		var o = element.children.get( 2 );
-		var b = element.children.get( 3 );
-		var a = element.children.get( 4 );
+		var o = element.getChild( 2 );
+		var b = element.getChild( 3 );
+		var a = element.getChild( 4 );
 		element.removeChildren( 2, 3 );
 
-		expect( element ).to.have.property( 'children' ).with.length( 3 );
-		expect( element.children.get( 0 ) ).to.have.property( 'character' ).that.equals( 'f' );
-		expect( element.children.get( 1 ) ).to.have.property( 'character' ).that.equals( 'o' );
-		expect( element.children.get( 2 ) ).to.have.property( 'character' ).that.equals( 'r' );
+		expect( element.getChildCount() ).to.be.equals( 3 );
+		expect( element.getChild( 0 ) ).to.have.property( 'character' ).that.equals( 'f' );
+		expect( element.getChild( 1 ) ).to.have.property( 'character' ).that.equals( 'o' );
+		expect( element.getChild( 2 ) ).to.have.property( 'character' ).that.equals( 'r' );
 
 		expect( o ).to.have.property( 'parent' ).that.is.null;
 		expect( b ).to.have.property( 'parent' ).that.is.null;
 		expect( a ).to.have.property( 'parent' ).that.is.null;
 	} );
+} );
+
+describe( 'getChildIndex', function() {
+	it( 'should return child index', function() {
+		var Element = modules[ 'document/element' ];
+
+		var element = new Element( 'elem', [], [ 'bar' ] );
+		var b = element.getChild( 0 );
+		var a = element.getChild( 1 );
+		var r = element.getChild( 2 );
+
+		expect( element.getChildIndex( b ) ).to.equals( 0 );
+		expect( element.getChildIndex( a ) ).to.equals( 1 );
+		expect( element.getChildIndex( r ) ).to.equals( 2 );
+	} );
+} );
+
+describe( 'getChildCount', function() {
+	it( 'should return number of children', function() {
+		var Element = modules[ 'document/element' ];
+
+		var element = new Element( 'elem', [], [ 'bar' ] );
+
+		expect( element.getChildCount() ).to.equals( 3 );
+	} );
 } );

+ 22 - 22
packages/ckeditor5-utils/tests/document/insertoperation.js

@@ -30,8 +30,8 @@ describe( 'InsertOperation', function() {
 			doc.version ) );
 
 		expect( doc.version ).to.be.equal( 1 );
-		expect( doc.root.children.length ).to.be.equal( 1 );
-		expect( doc.root.children.get( 0 ).character ).to.be.equal( 'x' );
+		expect( doc.root.getChildCount() ).to.be.equal( 1 );
+		expect( doc.root.getChild( 0 ).character ).to.be.equal( 'x' );
 	} );
 
 	it( 'should insert set of nodes', function() {
@@ -44,10 +44,10 @@ describe( 'InsertOperation', function() {
 		doc.applyOperation( new InsertOperation( new Position( [ 0 ], doc.root ), 'bar', doc.version ) );
 
 		expect( doc.version ).to.be.equal( 1 );
-		expect( doc.root.children.length ).to.be.equal( 3 );
-		expect( doc.root.children.get( 0 ).character ).to.be.equal( 'b' );
-		expect( doc.root.children.get( 1 ).character ).to.be.equal( 'a' );
-		expect( doc.root.children.get( 2 ).character ).to.be.equal( 'r' );
+		expect( doc.root.getChildCount() ).to.be.equal( 3 );
+		expect( doc.root.getChild( 0 ).character ).to.be.equal( 'b' );
+		expect( doc.root.getChild( 1 ).character ).to.be.equal( 'a' );
+		expect( doc.root.getChild( 2 ).character ).to.be.equal( 'r' );
 	} );
 
 	it( 'should insert between existing nodes', function() {
@@ -62,12 +62,12 @@ describe( 'InsertOperation', function() {
 		doc.applyOperation( new InsertOperation( new Position( [ 1 ], doc.root ), 'bar', doc.version ) );
 
 		expect( doc.version ).to.be.equal( 1 );
-		expect( doc.root.children.length ).to.be.equal( 5 );
-		expect( doc.root.children.get( 0 ).character ).to.be.equal( 'x' );
-		expect( doc.root.children.get( 1 ).character ).to.be.equal( 'b' );
-		expect( doc.root.children.get( 2 ).character ).to.be.equal( 'a' );
-		expect( doc.root.children.get( 3 ).character ).to.be.equal( 'r' );
-		expect( doc.root.children.get( 4 ).character ).to.be.equal( 'y' );
+		expect( doc.root.getChildCount() ).to.be.equal( 5 );
+		expect( doc.root.getChild( 0 ).character ).to.be.equal( 'x' );
+		expect( doc.root.getChild( 1 ).character ).to.be.equal( 'b' );
+		expect( doc.root.getChild( 2 ).character ).to.be.equal( 'a' );
+		expect( doc.root.getChild( 3 ).character ).to.be.equal( 'r' );
+		expect( doc.root.getChild( 4 ).character ).to.be.equal( 'y' );
 	} );
 
 	it( 'should insert text', function() {
@@ -84,14 +84,14 @@ describe( 'InsertOperation', function() {
 			doc.version ) );
 
 		expect( doc.version ).to.be.equal( 1 );
-		expect( doc.root.children.length ).to.be.equal( 7 );
-		expect( doc.root.children.get( 0 ).character ).to.be.equal( 'f' );
-		expect( doc.root.children.get( 1 ).character ).to.be.equal( 'o' );
-		expect( doc.root.children.get( 2 ).character ).to.be.equal( 'o' );
-		expect( doc.root.children.get( 3 ).character ).to.be.equal( 'x' );
-		expect( doc.root.children.get( 4 ).character ).to.be.equal( 'b' );
-		expect( doc.root.children.get( 5 ).character ).to.be.equal( 'a' );
-		expect( doc.root.children.get( 6 ).character ).to.be.equal( 'r' );
+		expect( doc.root.getChildCount() ).to.be.equal( 7 );
+		expect( doc.root.getChild( 0 ).character ).to.be.equal( 'f' );
+		expect( doc.root.getChild( 1 ).character ).to.be.equal( 'o' );
+		expect( doc.root.getChild( 2 ).character ).to.be.equal( 'o' );
+		expect( doc.root.getChild( 3 ).character ).to.be.equal( 'x' );
+		expect( doc.root.getChild( 4 ).character ).to.be.equal( 'b' );
+		expect( doc.root.getChild( 5 ).character ).to.be.equal( 'a' );
+		expect( doc.root.getChild( 6 ).character ).to.be.equal( 'r' );
 	} );
 
 	it( 'should create a remove operation as a reverse', function() {
@@ -138,7 +138,7 @@ describe( 'InsertOperation', function() {
 		doc.applyOperation( reverse );
 
 		expect( doc.version ).to.be.equal( 2 );
-		expect( doc.root.children.length ).to.be.equal( 0 );
+		expect( doc.root.getChildCount() ).to.be.equal( 0 );
 	} );
 
 	it( 'should undo insert set of nodes by applying reverse operation', function() {
@@ -159,6 +159,6 @@ describe( 'InsertOperation', function() {
 		doc.applyOperation( reverse );
 
 		expect( doc.version ).to.be.equal( 2 );
-		expect( doc.root.children.length ).to.be.equal( 0 );
+		expect( doc.root.getChildCount() ).to.be.equal( 0 );
 	} );
 } );

+ 30 - 30
packages/ckeditor5-utils/tests/document/moveoperation.js

@@ -33,16 +33,16 @@ describe( 'MoveOperation', function() {
 		doc.applyOperation( new MoveOperation(
 			new Position( [ 0, 0 ], doc.root ),
 			new Position( [ 1, 0 ], doc.root ),
-			p1.children.get( 0 ),
+			p1.getChild( 0 ),
 			doc.version ) );
 
 		expect( doc.version ).to.be.equal( 1 );
-		expect( doc.root.children.length ).to.be.equal( 2 );
-		expect( doc.root.children.get( 0 ).name ).to.be.equal( 'p1' );
-		expect( doc.root.children.get( 1 ).name ).to.be.equal( 'p2' );
-		expect( p1.children.length ).to.be.equal( 0 );
-		expect( p2.children.length ).to.be.equal( 1 );
-		expect( p2.children.get( 0 ).name ).to.be.equal( 'x' );
+		expect( doc.root.getChildCount() ).to.be.equal( 2 );
+		expect( doc.root.getChild( 0 ).name ).to.be.equal( 'p1' );
+		expect( doc.root.getChild( 1 ).name ).to.be.equal( 'p2' );
+		expect( p1.getChildCount() ).to.be.equal( 0 );
+		expect( p2.getChildCount() ).to.be.equal( 1 );
+		expect( p2.getChild( 0 ).name ).to.be.equal( 'x' );
 	} );
 
 	it( 'should move position of children in one node backward', function() {
@@ -57,16 +57,16 @@ describe( 'MoveOperation', function() {
 		doc.applyOperation( new MoveOperation(
 			new Position( [ 2 ], doc.root ),
 			new Position( [ 1 ], doc.root ),
-			[ doc.root.children.get( 2 ),  doc.root.children.get( 3 ) ],
+			[ doc.root.getChild( 2 ),  doc.root.getChild( 3 ) ],
 			doc.version ) );
 
 		expect( doc.version ).to.be.equal( 1 );
-		expect( doc.root.children.length ).to.be.equal( 5 );
-		expect( doc.root.children.get( 0 ).character ).to.be.equal( 'x' );
-		expect( doc.root.children.get( 1 ).character ).to.be.equal( 'a' );
-		expect( doc.root.children.get( 2 ).character ).to.be.equal( 'r' );
-		expect( doc.root.children.get( 3 ).character ).to.be.equal( 'b' );
-		expect( doc.root.children.get( 4 ).character ).to.be.equal( 'x' );
+		expect( doc.root.getChildCount() ).to.be.equal( 5 );
+		expect( doc.root.getChild( 0 ).character ).to.be.equal( 'x' );
+		expect( doc.root.getChild( 1 ).character ).to.be.equal( 'a' );
+		expect( doc.root.getChild( 2 ).character ).to.be.equal( 'r' );
+		expect( doc.root.getChild( 3 ).character ).to.be.equal( 'b' );
+		expect( doc.root.getChild( 4 ).character ).to.be.equal( 'x' );
 	} );
 
 	it( 'should move position of children in one node forward', function() {
@@ -81,16 +81,16 @@ describe( 'MoveOperation', function() {
 		doc.applyOperation( new MoveOperation(
 			new Position( [ 1 ], doc.root ),
 			new Position( [ 4 ], doc.root ),
-			[ doc.root.children.get( 1 ),  doc.root.children.get( 2 ) ],
+			[ doc.root.getChild( 1 ),  doc.root.getChild( 2 ) ],
 			doc.version ) );
 
 		expect( doc.version ).to.be.equal( 1 );
-		expect( doc.root.children.length ).to.be.equal( 5 );
-		expect( doc.root.children.get( 0 ).character ).to.be.equal( 'x' );
-		expect( doc.root.children.get( 1 ).character ).to.be.equal( 'r' );
-		expect( doc.root.children.get( 2 ).character ).to.be.equal( 'b' );
-		expect( doc.root.children.get( 3 ).character ).to.be.equal( 'a' );
-		expect( doc.root.children.get( 4 ).character ).to.be.equal( 'x' );
+		expect( doc.root.getChildCount() ).to.be.equal( 5 );
+		expect( doc.root.getChild( 0 ).character ).to.be.equal( 'x' );
+		expect( doc.root.getChild( 1 ).character ).to.be.equal( 'r' );
+		expect( doc.root.getChild( 2 ).character ).to.be.equal( 'b' );
+		expect( doc.root.getChild( 3 ).character ).to.be.equal( 'a' );
+		expect( doc.root.getChild( 4 ).character ).to.be.equal( 'x' );
 	} );
 
 	it( 'should create a move operation as a reverse', function() {
@@ -133,24 +133,24 @@ describe( 'MoveOperation', function() {
 		var operation =  new MoveOperation(
 			new Position( [ 0, 0 ], doc.root ),
 			new Position( [ 1, 0 ], doc.root ),
-			p1.children.get( 0 ),
+			p1.getChild( 0 ),
 			doc.version );
 
 		doc.applyOperation( operation );
 
 		expect( doc.version ).to.be.equal( 1 );
-		expect( doc.root.children.length ).to.be.equal( 2 );
-		expect( p1.children.length ).to.be.equal( 0 );
-		expect( p2.children.length ).to.be.equal( 1 );
-		expect( p2.children.get( 0 ).name ).to.be.equal( 'x' );
+		expect( doc.root.getChildCount() ).to.be.equal( 2 );
+		expect( p1.getChildCount() ).to.be.equal( 0 );
+		expect( p2.getChildCount() ).to.be.equal( 1 );
+		expect( p2.getChild( 0 ).name ).to.be.equal( 'x' );
 
 		doc.applyOperation( operation.reverseOperation() );
 
 		expect( doc.version ).to.be.equal( 2 );
-		expect( doc.root.children.length ).to.be.equal( 2 );
-		expect( p1.children.length ).to.be.equal( 1 );
-		expect( p1.children.get( 0 ).name ).to.be.equal( 'x' );
-		expect( p2.children.length ).to.be.equal( 0 );
+		expect( doc.root.getChildCount() ).to.be.equal( 2 );
+		expect( p1.getChildCount() ).to.be.equal( 1 );
+		expect( p1.getChild( 0 ).name ).to.be.equal( 'x' );
+		expect( p2.getChildCount() ).to.be.equal( 0 );
 	} );
 
 	if ( CKEDITOR.isDebug ) {

+ 2 - 2
packages/ckeditor5-utils/tests/document/node.js

@@ -198,13 +198,13 @@ describe( 'hasAttr', function() {
 		var parsedFoo = JSON.parse( JSON.stringify( foo ) );
 		var parsedBar = JSON.parse( JSON.stringify( b ) );
 
-		parsedFoo.children = new NodeList( parsedFoo.children );
+		parsedFoo._children = new NodeList( parsedFoo._children );
 
 		expect( parsedFoo ).to.be.deep.equals( {
 			name: 'foo',
 			parent: null,
 			attrs: [],
-			children: new NodeList( parsedFoo.children )
+			_children: new NodeList( parsedFoo._children )
 		} );
 
 		expect( parsedBar ).to.be.deep.equals( {

+ 13 - 13
packages/ckeditor5-utils/tests/document/removeoperation.js

@@ -28,11 +28,11 @@ describe( 'RemoveOperation', function() {
 
 		doc.applyOperation( new RemoveOperation(
 			new Position( [ 0 ], doc.root ),
-			doc.root.children.get( 0 ),
+			doc.root.getChild( 0 ),
 			doc.version ) );
 
 		expect( doc.version ).to.be.equal( 1 );
-		expect( doc.root.children.length ).to.be.equal( 0 );
+		expect( doc.root.getChildCount() ).to.be.equal( 0 );
 	} );
 
 	it( 'should remove set of nodes', function() {
@@ -46,11 +46,11 @@ describe( 'RemoveOperation', function() {
 
 		doc.applyOperation( new RemoveOperation(
 			new Position( [ 0 ], doc.root ),
-			[ doc.root.children.get( 0 ), doc.root.children.get( 1 ), doc.root.children.get( 2 ) ],
+			[ doc.root.getChild( 0 ), doc.root.getChild( 1 ), doc.root.getChild( 2 ) ],
 			doc.version ) );
 
 		expect( doc.version ).to.be.equal( 1 );
-		expect( doc.root.children.length ).to.be.equal( 0 );
+		expect( doc.root.getChildCount() ).to.be.equal( 0 );
 	} );
 
 	it( 'should remove from between existing nodes', function() {
@@ -64,13 +64,13 @@ describe( 'RemoveOperation', function() {
 
 		doc.applyOperation( new RemoveOperation(
 			new Position( [ 1 ], doc.root ),
-			[ doc.root.children.get( 1 ) ],
+			[ doc.root.getChild( 1 ) ],
 			doc.version ) );
 
 		expect( doc.version ).to.be.equal( 1 );
-		expect( doc.root.children.length ).to.be.equal( 2 );
-		expect( doc.root.children.get( 0 ).character ).to.be.equal( 'b' );
-		expect( doc.root.children.get( 1 ).character ).to.be.equal( 'r' );
+		expect( doc.root.getChildCount() ).to.be.equal( 2 );
+		expect( doc.root.getChild( 0 ).character ).to.be.equal( 'b' );
+		expect( doc.root.getChild( 1 ).character ).to.be.equal( 'r' );
 	} );
 
 	it( 'should create a insert operation as a reverse', function() {
@@ -117,15 +117,15 @@ describe( 'RemoveOperation', function() {
 		doc.applyOperation( operation );
 
 		expect( doc.version ).to.be.equal( 1 );
-		expect( doc.root.children.length ).to.be.equal( 0 );
+		expect( doc.root.getChildCount() ).to.be.equal( 0 );
 
 		doc.applyOperation( reverse );
 
 		expect( doc.version ).to.be.equal( 2 );
-		expect( doc.root.children.length ).to.be.equal( 3 );
-		expect( doc.root.children.get( 0 ).character ).to.be.equal( 'b' );
-		expect( doc.root.children.get( 1 ).character ).to.be.equal( 'a' );
-		expect( doc.root.children.get( 2 ).character ).to.be.equal( 'r' );
+		expect( doc.root.getChildCount() ).to.be.equal( 3 );
+		expect( doc.root.getChild( 0 ).character ).to.be.equal( 'b' );
+		expect( doc.root.getChild( 1 ).character ).to.be.equal( 'a' );
+		expect( doc.root.getChild( 2 ).character ).to.be.equal( 'r' );
 	}  );
 
 	if ( CKEDITOR.isDebug ) {