TurboWarp / scratch-vm

Scratch VM with a JIT compiler and more features
https://turbowarp.org/
Mozilla Public License 2.0
75 stars 72 forks source link

Possibly unintended behaviour of `getListContent()` with `updateMonitor` #126

Closed MinekPo1 closed 1 year ago

MinekPo1 commented 1 year ago

Expected Behavior

It seems to me that getListContent() is meant to return a string containing joined items.

Actual Behavior

If util.thread.updateMonitor is true/-thy, it returns the raw value (a list of strings/numbers).

Steps to Reproduce

Add the following to test/unit/blocks_data.js:

test('getListContents works with updateMonitor' ,t => {
    const args = {LIST: {name: 'list'}};
    util.thread = {updateMonitor: true};

    // multi-character items, up to date
    lists.list = {value: ["apple","banana","orange"], _monitorUpToDate: true};
    t.strictEqual(blocks.getListContents(args, util), "apple banana orange");
    t.ok(lists.list._monitorUpToDate);

    // single character items, not up to date
    lists.list = {value: ["a","p","p","l","e"], _monitorUpToDate: false};
    t.strictEqual(blocks.getListContents(args, util), "apple");
    t.ok(lists.list._monitorUpToDate);

    // disable updateMonitor for other tests
    util.thread = null;

    t.end();
});

Operating System and Browser

N/A. Tested on node v18.16.0, npm 9.1.3, though that shouldn't matter.

MinekPo1 commented 1 year ago

I cannot tell if this behavior has any impact on TurboWrap/scratch-gui, or at all.

GarboMuffin commented 1 year ago

I believe this is intended. updateMonitor is only enabled for the threads that update the variable monitors shown over the stage. Returning the raw list here is what allows the GUI to display lists. This is vanilla Scratch code anyways, so if there's something wrong, you should report it to Scratch