forked from scratchfoundation/scratch-vm
-
Notifications
You must be signed in to change notification settings - Fork 113
Closed
Description
Bug Description
- The
resetVariableInputs()function is not called within thegenerateCompatibilityLayerCallfunction injsgen.js. This might lead to a situation where, when executing extension blocks or blocks like "say ... for ... secs", after a thread switch, the type records ofVariableInputsare not cleared in a timely manner.
scratch-vm/src/compiler/jsgen.js
Lines 1328 to 1332 in af3b751
generateCompatibilityLayerCall (node, setFlags, frameName = null) { const opcode = node.opcode; let result = 'yield* executeInCompatibilityLayer({';
Bug Behavior
As shown in the image below, when calculating "(my var) + 2", the compiler does not convert "my var" to a number. Instead, it directly performs string joining.
- When executing the block "say ... for 0.1 secs",
resetVariableInputs()is not called. At this point, the program switches to another script, which changes "my var" from a number to a string. - When returning to the original script and compiling "(my var) + 2", the compiler still assumes that "my var" is a number and does not perform type conversion, resulting in an error.
- Similar bugs may also occur with extension blocks that can cause thread switches.
Suggested Change
- Add a call to
resetVariableInputs()within thegenerateCompatibilityLayerCallfunction injsgen.js↓
scratch-vm/src/compiler/jsgen.js
Lines 1328 to 1332 in af3b751
generateCompatibilityLayerCall (node, setFlags, frameName = null) { const opcode = node.opcode; let result = 'yield* executeInCompatibilityLayer({';
Metadata
Metadata
Assignees
Labels
No labels