소스 검색

Prevented from crashing when the editor is being removed for the second time.

Szymon Cofalik 6 년 전
부모
커밋
e0ef1cedba
2개의 변경된 파일18개의 추가작업 그리고 1개의 파일을 삭제
  1. 3 1
      packages/ckeditor5-core/src/context.js
  2. 15 0
      packages/ckeditor5-core/tests/context.js

+ 3 - 1
packages/ckeditor5-core/src/context.js

@@ -198,7 +198,9 @@ export default class Context {
 	 * @return {Promise} A promise that resolves once the editor is removed from the context or when the context has been destroyed.
 	 */
 	_removeEditor( editor ) {
-		this.editors.remove( editor );
+		if ( this.editors.has( editor ) ) {
+			this.editors.remove( editor );
+		}
 
 		if ( this._contextOwner === editor ) {
 			return this.destroy();

+ 15 - 0
packages/ckeditor5-core/tests/context.js

@@ -280,5 +280,20 @@ describe( 'Context', () => {
 			sinon.assert.calledOnce( editorB.destroy );
 			sinon.assert.notCalled( editorC.destroy );
 		} );
+
+		it( 'should not crash when destroyed for the second time', async () => {
+			const context = await Context.create();
+
+			await VirtualTestEditor.create( { context } );
+			await context.destroy();
+			await context.destroy();
+		} );
+
+		it( 'should not crash when destroyed for the second time - editor own managed context', async () => {
+			const editor = await VirtualTestEditor.create();
+
+			await editor.destroy();
+			await editor.destroy();
+		} );
 	} );
 } );