Skip to content

[ENA-266] JS TypeError when clicking a procedure in the toolbox #3877

Open
@alexcui03

Description

@alexcui03

Expected Behavior

No Error

Actual Behavior

Uncaught TypeError: Cannot read properties of undefined (reading 'opcode')

Steps to Reproduce

  1. create a procedure as the following picture:
    image
  2. run it by clicking the procedure block in the toolbox, we will get the error in console:
    image

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions