[ENA-266] JS TypeError when clicking a procedure in the toolbox
alexcui03 opened this issue · comments
Alex Cui commented
Expected Behavior
No Error
Actual Behavior
Uncaught TypeError: Cannot read properties of undefined (reading 'opcode')
Steps to Reproduce
- create a procedure as the following picture:
- run it by clicking the procedure block in the toolbox, we will get the error in console:
Other Infomation
It causes endless loop in development mode.
Related code src/engine/thread.js:
isRecursiveCall (procedureCode) {
let callCount = 5; // Max number of enclosing procedure calls to examine.
const sp = this.stack.length - 1;
for (let i = sp - 1; i >= 0; i--) {
const block = this.target.blocks.getBlock(this.stack[i]);
if (block.opcode === 'procedures_call' &&
block.mutation.proccode === procedureCode) {
return true;
}
if (--callCount < 0) return false;
}
return false;
}
Possible reason: the procedure block from toolbox cannot be get with this.target.blocks.getBlock
, so it get undefined. Accessing block.opcode (block is undefined) cause the error.
System Details
Windows 11
Chrome 109.0.5414.122