diff --git a/core/block.ts b/core/block.ts index a37de7dab..314ba1383 100644 --- a/core/block.ts +++ b/core/block.ts @@ -343,23 +343,17 @@ export class Block implements IASTNodeLocation, IDeletable { this.workspace.removeChangeListener(this.onchangeWrapper_); } - eventUtils.disable(); - try { - this.workspace.removeTypedBlock(this); - this.workspace.removeBlockById(this.id); - this.disposing = true; + this.workspace.removeTypedBlock(this); + this.workspace.removeBlockById(this.id); + this.disposing = true; - this.childBlocks_.forEach((c) => c.disposeInternal()); - this.inputList.forEach((i) => i.dispose()); - this.inputList.length = 0; - this.getConnections_(true).forEach((c) => c.dispose()); - } finally { - eventUtils.enable(); - if (typeof this.destroy === 'function') { - this.destroy(); - } - this.disposed = true; - } + if (typeof this.destroy === 'function') this.destroy(); + + this.childBlocks_.forEach((c) => c.disposeInternal()); + this.inputList.forEach((i) => i.dispose()); + this.inputList.length = 0; + this.getConnections_(true).forEach((c) => c.dispose()); + this.disposed = true; } /** diff --git a/tests/mocha/block_test.js b/tests/mocha/block_test.js index 9d09c7151..22fa3c07f 100644 --- a/tests/mocha/block_test.js +++ b/tests/mocha/block_test.js @@ -213,7 +213,11 @@ suite('Blocks', function () { suite('calling destroy', function () { setup(function () { Blockly.Blocks['destroyable_block'] = { - init: function () {}, + init: function () { + this.appendStatementInput('STATEMENT'); + this.setPreviousStatement(true); + this.setNextStatement(true); + }, destroy: function () {}, }; this.block = this.workspace.newBlock('destroyable_block'); @@ -274,6 +278,26 @@ suite('Blocks', function () { 'Expected to be able to fire events from destroy' ); }); + + test('child blocks can fire events from destroy', function () { + const mockEvent = createMockEvent(this.workspace); + const childBlock = this.workspace.newBlock('destroyable_block'); + this.block + .getInput('STATEMENT') + .connection.connect(childBlock.previousConnection); + childBlock.destroy = function () { + Blockly.Events.fire(mockEvent); + }; + const spy = createChangeListenerSpy(this.workspace); + + this.block.dispose(); + this.clock.runAll(); + + chai.assert.isTrue( + spy.calledWith(mockEvent), + 'Expected to be able to fire events from destroy' + ); + }); }); suite('stack/row healing', function () {