Procházet zdrojové kódy

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

Szymon Cofalik před 6 roky
rodič
revize
e0ef1cedba

+ 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();
+		} );
 	} );
 } );