Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed editor throwing an exception when destroyed shortly after it was created #2258

Closed
wants to merge 12 commits into from
1 change: 1 addition & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ Fixed Issues:
* [#2167](https://github.com/ckeditor/ckeditor-dev/issues/2167): Fixed: Matching in [Emoji](https://ckeditor.com/cke4/addon/emoji) plugin is not case insensitive.
* [#1084](https://github.com/ckeditor/ckeditor-dev/issues/1084) Fixed: Using the "Automatic" option with [Color Button](https://ckeditor.com/cke4/addon/colorbutton) on a text with color already defined sets an invalid color value.
* [#966](https://github.com/ckeditor/ckeditor-dev/issues/966): Fixed: Executing [`editor.destroy()`](https://docs.ckeditor.com/ckeditor4/latest/api/CKEDITOR_editor.html#destroy) during [file upload](https://docs.ckeditor.com/ckeditor4/latest/api/CKEDITOR_fileTools_uploadWidgetDefinition.html#onUploading) throws error. Thanks to [Maksim Makarevich](https://github.com/MaksimMakarevich)!
* [#2257](https://github.com/ckeditor/ckeditor-dev/issues/2257) Fixed: Editor throws an exception when destroyed shortly after it was created. Thanks to [brianmay27](https://github.com/brianmay27)!

## CKEditor 4.10

Expand Down
5 changes: 5 additions & 0 deletions core/editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -604,6 +604,11 @@

// Load all plugin specific language files in a row.
CKEDITOR.scriptLoader.load( languageFiles, function() {
// Ensure the editor had not been destroyed in the meantime (#2257).
if ( editor.status === 'destroyed' ) {
return;
}

// Initialize all plugins that have the "beforeInit" and "init" methods defined.
var methods = [ 'beforeInit', 'init', 'afterInit' ];
for ( var m = 0; m < methods.length; m++ ) {
Expand Down
1 change: 1 addition & 0 deletions tests/core/editor/destroyrace.html
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<div id="destroyed"></div>
42 changes: 42 additions & 0 deletions tests/core/editor/destroyrace.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/* bender-tags: editor,unit */
/* bender-ckeditor-plugins: toolbar */

( function() {
'use strict';

bender.test( {
// (#2257)
'test destroy editor on instance created': function() {
var init = sinon.spy(),
editor;

CKEDITOR.plugins.add( 'test', {
init: init
} );

CKEDITOR.tools.setTimeout( function() {
resume( function() {
editor.on( 'destroy', function() {
// Another timeout as the plugins are also loaded in a timeout launched during editor creation.
setTimeout( function() {
resume( function() {
assert.isFalse( init.called, 'Plugin init called when editor already destroyed' );
} );
}, 150 );
} );

editor.destroy();

wait();

} );
}, 0 );

editor = CKEDITOR.replace( 'destroyed', {
plugins: 'test'
} );

wait();
}
} );
} )();