mirror of
https://github.com/scratchfoundation/scratch-vm.git
synced 2024-12-23 06:23:37 -05:00
Fix tests and make chain more resilient
This commit is contained in:
parent
b0870518a4
commit
e8c5bbbf80
2 changed files with 29 additions and 6 deletions
|
@ -152,10 +152,12 @@ class Blocks {
|
|||
for (const id in this._blocks) {
|
||||
if (!this._blocks.hasOwnProperty(id)) continue;
|
||||
const block = this._blocks[id];
|
||||
if ((block.opcode === 'procedures_defnoreturn' ||
|
||||
block.opcode === 'procedures_defreturn') &&
|
||||
this._blocks[block.inputs.custom_block.block].mutation.proccode === name) {
|
||||
return id;
|
||||
if (block.opcode === 'procedures_defnoreturn' ||
|
||||
block.opcode === 'procedures_defreturn') {
|
||||
const internal = this._getCustomBlockInternal(block);
|
||||
if (internal && internal.mutation.proccode === name) {
|
||||
return id; // The outer define block id
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
|
@ -546,6 +548,17 @@ class Blocks {
|
|||
return params;
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper to get the corresponding internal procedure definition block
|
||||
* @param {!object} defineBlock Outer define block.
|
||||
* @return {!object} internal definition block which has the mutation.
|
||||
*/
|
||||
_getCustomBlockInternal (defineBlock) {
|
||||
if (defineBlock.inputs && defineBlock.inputs.custom_block) {
|
||||
return this._blocks[defineBlock.inputs.custom_block.block];
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper to add a stack to `this._scripts`.
|
||||
* @param {?string} topBlockId ID of block that starts the script.
|
||||
|
|
|
@ -153,9 +153,19 @@ test('stepToProcedure', t => {
|
|||
t.strictEquals(th.peekStack(), expectedBlock);
|
||||
s.stepToProcedure(th, 'faceCode');
|
||||
t.strictEquals(th.peekStack(), expectedBlock);
|
||||
s.stepToProcedure(th, 'faceCode');
|
||||
th.target.blocks.getBlock(th.stack[th.stack.length - 4]).mutation.proccode = 'othercode';
|
||||
|
||||
th.target.blocks.createBlock({
|
||||
id: 'internalId',
|
||||
opcode: 'procedures_defnoreturn_internal',
|
||||
mutation: {
|
||||
proccode: 'othercode'
|
||||
}
|
||||
});
|
||||
expectedBlock = th.stack[th.stack.length - 4];
|
||||
th.target.blocks.getBlock(expectedBlock).inputs.custom_block = {
|
||||
type: 'custom_block',
|
||||
block: 'internalId'
|
||||
};
|
||||
s.stepToProcedure(th, 'othercode');
|
||||
t.strictEquals(th.peekStack(), expectedBlock);
|
||||
|
||||
|
|
Loading…
Reference in a new issue