diff --git a/blocks/procedures.js b/blocks/procedures.js index d6fd9ddcf..c7a5d7fc3 100644 --- a/blocks/procedures.js +++ b/blocks/procedures.js @@ -979,7 +979,7 @@ const PROCEDURE_CALL_COMMON = { Xml.domToWorkspace(xml, this.workspace); Events.setGroup(false); } - } else if (event.type === Events.BLOCK_DELETE && event.blockId != this.id) { + } else if (event.type === Events.BLOCK_DELETE) { // Look for the case where a procedure definition has been deleted, // leaving this block (a procedure call) orphaned. In this case, delete // the orphan. diff --git a/core/block.ts b/core/block.ts index ee81f1cf8..3c7b21a6a 100644 --- a/core/block.ts +++ b/core/block.ts @@ -324,16 +324,15 @@ export class Block implements IASTNodeLocation, IDeletable { if (this.isDeadOrDying()) { return; } + // Terminate onchange event calls. + if (this.onchangeWrapper_) { + this.workspace.removeChangeListener(this.onchangeWrapper_); + } this.unplug(healStack); if (eventUtils.isEnabled()) { eventUtils.fire(new (eventUtils.get(eventUtils.BLOCK_DELETE))(this)); } - - if (this.onchangeWrapper_) { - this.workspace.removeChangeListener(this.onchangeWrapper_); - } - eventUtils.disable(); try { diff --git a/tests/mocha/blocks/procedures_test.js b/tests/mocha/blocks/procedures_test.js index 898bdf27a..98bdf6e9d 100644 --- a/tests/mocha/blocks/procedures_test.js +++ b/tests/mocha/blocks/procedures_test.js @@ -11,6 +11,7 @@ import {assertCallBlockStructure, assertDefBlockStructure, createProcDefBlock, c import {runSerializationTestSuite} from '../test_helpers/serialization.js'; import {createGenUidStubWithReturns, sharedTestSetup, sharedTestTeardown, workspaceTeardown} from '../test_helpers/setup_teardown.js'; + suite('Procedures', function() { setup(function() { sharedTestSetup.call(this); @@ -1209,43 +1210,3 @@ suite('Procedures', function() { }); }); }); - -suite('Procedures, dont auto fire events', function() { - setup(function() { - sharedTestSetup.call(this, {fireEventsNow: false}); - this.workspace = new Blockly.Workspace(); - }); - teardown(function() { - sharedTestTeardown.call(this); - }); - - const testSuites = [ - {title: 'procedures_defreturn', hasReturn: true, - defType: 'procedures_defreturn', callType: 'procedures_callreturn'}, - {title: 'procedures_defnoreturn', hasReturn: false, - defType: 'procedures_defnoreturn', callType: 'procedures_callnoreturn'}, - ]; - - testSuites.forEach((testSuite) => { - suite(testSuite.title, function() { - suite('Disposal', function() { - test('callers are disposed when definitions are disposed', function() { - this.defBlock = new Blockly.Block(this.workspace, testSuite.defType); - this.defBlock.setFieldValue('proc name', 'NAME'); - this.callerBlock = new Blockly.Block( - this.workspace, testSuite.callType); - this.callerBlock.setFieldValue('proc name', 'NAME'); - - // Run the clock now so that the create events get fired. If we fire - // it after disposing, a new procedure def will get created when - // the caller create event is heard. - this.clock.runAll(); - this.defBlock.dispose(); - this.clock.runAll(); - - chai.assert.isTrue(this.callerBlock.disposed); - }); - }); - }); - }); -}); diff --git a/tests/mocha/event_block_delete_test.js b/tests/mocha/event_block_delete_test.js index 4f03f6629..e5aed21c5 100644 --- a/tests/mocha/event_block_delete_test.js +++ b/tests/mocha/event_block_delete_test.js @@ -21,24 +21,6 @@ suite('Block Delete Event', function() { sharedTestTeardown.call(this); }); - suite('Receiving', function() { - test('blocks receive their own delete events', function() { - Blockly.Blocks['test'] = { - onchange: function(e) {}, - }; - // Need to stub the definition, because the property on the definition is - // what gets registered as an event listener. - const spy = sinon.spy(Blockly.Blocks['test'], 'onchange'); - const testBlock = this.workspace.newBlock('test'); - - testBlock.dispose(); - - const deleteClass = eventUtils.get(eventUtils.BLOCK_DELETE); - chai.assert.isTrue(spy.calledOnce); - chai.assert.isTrue(spy.getCall(0).args[0] instanceof deleteClass); - }); - }); - suite('Serialization', function() { test('events round-trip through JSON', function() { const block = this.workspace.newBlock('row_block', 'block_id'); diff --git a/tests/mocha/index.html b/tests/mocha/index.html index ce43ace99..7dcc92e42 100644 --- a/tests/mocha/index.html +++ b/tests/mocha/index.html @@ -19,8 +19,8 @@ + goog.require() the test modules that make calls to (e.g.) + suite() at the top level. -->