浏览代码

Fixed all context errors.

Maciej Bukowski 6 年之前
父节点
当前提交
1c950d60e4

+ 1 - 1
packages/ckeditor5-engine/src/model/liveposition.js

@@ -47,7 +47,7 @@ export default class LivePosition extends Position {
 			 */
 			throw new CKEditorError(
 				'model-liveposition-root-not-rootelement: LivePosition\'s root has to be an instance of RootElement.',
-				this
+				root
 			);
 		}
 

+ 19 - 7
packages/ckeditor5-engine/src/model/position.js

@@ -61,7 +61,10 @@ export default class Position {
 			 *
 			 * @error model-position-root-invalid
 			 */
-			throw new CKEditorError( 'model-position-root-invalid: Position root invalid.', null );
+			throw new CKEditorError(
+				'model-position-root-invalid: Position root invalid.',
+				root
+			);
 		}
 
 		if ( !( path instanceof Array ) || path.length === 0 ) {
@@ -73,7 +76,8 @@ export default class Position {
 			 */
 			throw new CKEditorError(
 				'model-position-path-incorrect: Position path must be an array with at least one item.',
-				null, { path }
+				root,
+				{ path }
 			);
 		}
 
@@ -862,7 +866,7 @@ export default class Position {
 				throw new CKEditorError(
 					'model-createPositionAt-offset-required: ' +
 					'Model#createPositionAt() requires the offset when the first parameter is a model item.',
-					this
+					[ this, itemOrPosition ]
 				);
 			}
 
@@ -874,7 +878,7 @@ export default class Position {
 				 */
 				throw new CKEditorError(
 					'model-position-parent-incorrect: Position parent have to be a element or document fragment.',
-					this
+					[ this, itemOrPosition ]
 				);
 			}
 
@@ -902,7 +906,11 @@ export default class Position {
 			 * @error model-position-after-root
 			 * @param {module:engine/model/item~Item} root
 			 */
-			throw new CKEditorError( 'model-position-after-root: You cannot make a position after root.', this, { root: item } );
+			throw new CKEditorError(
+				'model-position-after-root: You cannot make a position after root.',
+				[ this, item ],
+				{ root: item }
+			);
 		}
 
 		return this._createAt( item.parent, item.endOffset, stickiness );
@@ -924,7 +932,11 @@ export default class Position {
 			 * @error model-position-before-root
 			 * @param {module:engine/model/item~Item} root
 			 */
-			throw new CKEditorError( 'model-position-before-root: You cannot make a position before root.', this, { root: item } );
+			throw new CKEditorError(
+				'model-position-before-root: You cannot make a position before root.',
+				item,
+				{ root: item }
+			);
 		}
 
 		return this._createAt( item.parent, item.startOffset, stickiness );
@@ -954,7 +966,7 @@ export default class Position {
 			 */
 			throw new CKEditorError(
 				'model-position-fromjson-no-root: Cannot create position for document. Root with specified name does not exist.',
-				this,
+				doc,
 				{ rootName: json.root }
 			);
 		}

+ 4 - 1
packages/ckeditor5-engine/src/model/range.js

@@ -877,7 +877,10 @@ export default class Range {
 			 *
 			 * @error range-create-from-ranges-empty-array
 			 */
-			throw new CKEditorError( 'range-create-from-ranges-empty-array: At least one range has to be passed.', this );
+			throw new CKEditorError(
+				'range-create-from-ranges-empty-array: At least one range has to be passed.',
+				ranges
+			);
 		} else if ( ranges.length == 1 ) {
 			return ranges[ 0 ].clone();
 		}

+ 8 - 5
packages/ckeditor5-engine/src/model/selection.js

@@ -396,7 +396,7 @@ export default class Selection {
 				throw new CKEditorError(
 					'model-selection-setTo-required-second-parameter: ' +
 					'selection.setTo requires the second parameter when the first parameter is a node.',
-					this
+					[ this, selectable ]
 				);
 			}
 
@@ -417,7 +417,10 @@ export default class Selection {
 			 *
 			 * @error model-selection-setTo-not-selectable
 			 */
-			throw new CKEditorError( 'model-selection-setTo-not-selectable: Cannot set the selection to the given place.', this );
+			throw new CKEditorError(
+				'model-selection-setTo-not-selectable: Cannot set the selection to the given place.',
+				[ this, selectable ]
+			);
 		}
 	}
 
@@ -452,7 +455,7 @@ export default class Selection {
 				throw new CKEditorError(
 					'model-selection-set-ranges-not-range: ' +
 					'Selection range set to an object that is not an instance of model.Range.',
-					this
+					[ this, newRanges ]
 				);
 			}
 
@@ -497,7 +500,7 @@ export default class Selection {
 			 */
 			throw new CKEditorError(
 				'model-selection-setFocus-no-ranges: Cannot set selection focus if there are no ranges in selection.',
-				this
+				[ this, itemOrPosition ]
 			);
 		}
 
@@ -767,7 +770,7 @@ export default class Selection {
 				 */
 				throw new CKEditorError(
 					'model-selection-range-intersects: Trying to add a range that intersects with another range in the selection.',
-					this,
+					[ this, range ],
 					{ addedRange: range, intersectingRange: this._ranges[ i ] }
 				);
 			}

+ 1 - 1
packages/ckeditor5-engine/src/model/treewalker.js

@@ -53,7 +53,7 @@ export default class TreeWalker {
 		if ( direction != 'forward' && direction != 'backward' ) {
 			throw new CKEditorError(
 				'model-tree-walker-unknown-direction: Only `backward` and `forward` direction allowed.',
-				this,
+				options,
 				{ direction }
 			);
 		}

+ 4 - 2
packages/ckeditor5-engine/tests/model/liveposition.js

@@ -42,9 +42,11 @@ describe( 'LivePosition', () =>
 	} );
 
 	it( 'should throw if given root is not a RootElement', () => {
+		const docFrag = new DocumentFragment();
+
 		expectToThrowCKEditorError( () => {
-			new LivePosition( new DocumentFragment(), [ 1 ] ); // eslint-disable-line no-new
-		}, /model-liveposition-root-not-rootelement/, null );
+			new LivePosition( docFrag, [ 1 ] ); // eslint-disable-line no-new
+		}, /model-liveposition-root-not-rootelement/, docFrag );
 	} );
 
 	it( 'should listen to the model applyOperation event', () => {

+ 3 - 3
packages/ckeditor5-engine/tests/model/position.js

@@ -110,17 +110,17 @@ describe( 'Position', () => {
 		it( 'should throw error if given path is incorrect', () => {
 			expectToThrowCKEditorError( () => {
 				new Position( root, {} ); // eslint-disable-line no-new
-			}, /model-position-path-incorrect/, null );
+			}, /model-position-path-incorrect/, model );
 
 			expectToThrowCKEditorError( () => {
 				new Position( root, [] ); // eslint-disable-line no-new
-			}, /model-position-path-incorrect/, null );
+			}, /model-position-path-incorrect/, model );
 		} );
 
 		it( 'should throw error if given root is invalid', () => {
 			expectToThrowCKEditorError( () => {
 				new Position( new Text( 'a' ) ); // eslint-disable-line no-new
-			}, /model-position-root-invalid/, null );
+			}, /model-position-root-invalid/ );
 
 			expect( () => {
 				new Position(); // eslint-disable-line no-new

+ 1 - 1
packages/ckeditor5-engine/tests/model/range.js

@@ -213,7 +213,7 @@ describe( 'Range', () => {
 			it( 'should throw if empty array is passed', () => {
 				expectToThrowCKEditorError( () => {
 					Range._createFromRanges( [] );
-				}, /^range-create-from-ranges-empty-array/, model );
+				}, /^range-create-from-ranges-empty-array/ );
 			} );
 
 			it( 'should return a copy of the range if only one range was passed', () => {

+ 3 - 3
packages/ckeditor5-engine/tests/model/treewalker.js

@@ -51,15 +51,15 @@ describe( 'TreeWalker', () => {
 		it( 'should throw if neither boundaries nor starting position is set', () => {
 			expectToThrowCKEditorError( () => {
 				new TreeWalker(); // eslint-disable-line no-new
-			}, /^model-tree-walker-no-start-position/, model );
+			}, /^model-tree-walker-no-start-position/, null );
 
 			expectToThrowCKEditorError( () => {
 				new TreeWalker( {} ); // eslint-disable-line no-new
-			}, /^model-tree-walker-no-start-position/, model );
+			}, /^model-tree-walker-no-start-position/, null );
 
 			expectToThrowCKEditorError( () => {
 				new TreeWalker( { singleCharacters: true } ); // eslint-disable-line no-new
-			}, /^model-tree-walker-no-start-position/, model );
+			}, /^model-tree-walker-no-start-position/, null );
 		} );
 
 		it( 'should throw if walking direction is unknown', () => {