mirror of
https://github.com/scratchfoundation/scratch-vm.git
synced 2025-08-21 10:49:50 -04:00
Delete monitor block when variable is deleted
This commit is contained in:
parent
95ca10038b
commit
aa0064948a
3 changed files with 13 additions and 20 deletions
|
@ -250,9 +250,7 @@ class Blocks {
|
||||||
if (optRuntime && this._blocks[e.blockId].topLevel) {
|
if (optRuntime && this._blocks[e.blockId].topLevel) {
|
||||||
optRuntime.quietGlow(e.blockId);
|
optRuntime.quietGlow(e.blockId);
|
||||||
}
|
}
|
||||||
this.deleteBlock({
|
this.deleteBlock(e.blockId);
|
||||||
id: e.blockId
|
|
||||||
});
|
|
||||||
break;
|
break;
|
||||||
case 'var_create':
|
case 'var_create':
|
||||||
// New variables being created by the user are all global.
|
// New variables being created by the user are all global.
|
||||||
|
@ -414,37 +412,37 @@ class Blocks {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Block management: delete blocks and their associated scripts.
|
* Block management: delete blocks and their associated scripts.
|
||||||
* @param {!object} e Blockly delete event to be processed.
|
* @param {!string} blockId Id of block to delete
|
||||||
*/
|
*/
|
||||||
deleteBlock (e) {
|
deleteBlock (blockId) {
|
||||||
// @todo In runtime, stop threads running on this script.
|
// @todo In runtime, stop threads running on this script.
|
||||||
|
|
||||||
// Get block
|
// Get block
|
||||||
const block = this._blocks[e.id];
|
const block = this._blocks[blockId];
|
||||||
|
|
||||||
// Delete children
|
// Delete children
|
||||||
if (block.next !== null) {
|
if (block.next !== null) {
|
||||||
this.deleteBlock({id: block.next});
|
this.deleteBlock(block.next);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Delete inputs (including branches)
|
// Delete inputs (including branches)
|
||||||
for (const input in block.inputs) {
|
for (const input in block.inputs) {
|
||||||
// If it's null, the block in this input moved away.
|
// If it's null, the block in this input moved away.
|
||||||
if (block.inputs[input].block !== null) {
|
if (block.inputs[input].block !== null) {
|
||||||
this.deleteBlock({id: block.inputs[input].block});
|
this.deleteBlock(block.inputs[input].block);
|
||||||
}
|
}
|
||||||
// Delete obscured shadow blocks.
|
// Delete obscured shadow blocks.
|
||||||
if (block.inputs[input].shadow !== null &&
|
if (block.inputs[input].shadow !== null &&
|
||||||
block.inputs[input].shadow !== block.inputs[input].block) {
|
block.inputs[input].shadow !== block.inputs[input].block) {
|
||||||
this.deleteBlock({id: block.inputs[input].shadow});
|
this.deleteBlock(block.inputs[input].shadow);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Delete any script starting with this block.
|
// Delete any script starting with this block.
|
||||||
this._deleteScript(e.id);
|
this._deleteScript(blockId);
|
||||||
|
|
||||||
// Delete block itself.
|
// Delete block itself.
|
||||||
delete this._blocks[e.id];
|
delete this._blocks[blockId];
|
||||||
}
|
}
|
||||||
|
|
||||||
// ---------------------------------------------------------------------
|
// ---------------------------------------------------------------------
|
||||||
|
|
|
@ -189,6 +189,7 @@ class Target extends EventEmitter {
|
||||||
if (this.variables.hasOwnProperty(id)) {
|
if (this.variables.hasOwnProperty(id)) {
|
||||||
delete this.variables[id];
|
delete this.variables[id];
|
||||||
if (this.runtime) {
|
if (this.runtime) {
|
||||||
|
this.runtime.monitorBlocks.deleteBlock(id);
|
||||||
this.runtime.requestRemoveMonitor(id);
|
this.runtime.requestRemoveMonitor(id);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -421,9 +421,7 @@ test('delete', t => {
|
||||||
inputs: {},
|
inputs: {},
|
||||||
topLevel: true
|
topLevel: true
|
||||||
});
|
});
|
||||||
b.deleteBlock({
|
b.deleteBlock('foo');
|
||||||
id: 'foo'
|
|
||||||
});
|
|
||||||
|
|
||||||
t.type(b._blocks.foo, 'undefined');
|
t.type(b._blocks.foo, 'undefined');
|
||||||
t.equal(b._scripts.indexOf('foo'), -1);
|
t.equal(b._scripts.indexOf('foo'), -1);
|
||||||
|
@ -458,9 +456,7 @@ test('delete chain', t => {
|
||||||
inputs: {},
|
inputs: {},
|
||||||
topLevel: false
|
topLevel: false
|
||||||
});
|
});
|
||||||
b.deleteBlock({
|
b.deleteBlock('foo');
|
||||||
id: 'foo'
|
|
||||||
});
|
|
||||||
t.type(b._blocks.foo, 'undefined');
|
t.type(b._blocks.foo, 'undefined');
|
||||||
t.type(b._blocks.foo2, 'undefined');
|
t.type(b._blocks.foo2, 'undefined');
|
||||||
t.type(b._blocks.foo3, 'undefined');
|
t.type(b._blocks.foo3, 'undefined');
|
||||||
|
@ -531,9 +527,7 @@ test('delete inputs', t => {
|
||||||
inputs: {},
|
inputs: {},
|
||||||
topLevel: false
|
topLevel: false
|
||||||
});
|
});
|
||||||
b.deleteBlock({
|
b.deleteBlock('foo');
|
||||||
id: 'foo'
|
|
||||||
});
|
|
||||||
t.type(b._blocks.foo, 'undefined');
|
t.type(b._blocks.foo, 'undefined');
|
||||||
t.type(b._blocks.foo2, 'undefined');
|
t.type(b._blocks.foo2, 'undefined');
|
||||||
t.type(b._blocks.foo3, 'undefined');
|
t.type(b._blocks.foo3, 'undefined');
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue