Files
scratch-vm/test/unit/tw_stop_this_script.js
T
GarboMuffin 20f25f252c interpreter: Do not re-evaluate procedure arguments after stop this script or return (#202)
"stop this script" and "return" would previously cause all the procedure
arguments to be re-evaluated and then discarded. In vanilla Scratch the
worst case is a performance penalty, but with our custom reporters it
can cause infinite loops.

Fixes https://github.com/TurboWarp/scratch-vm/issues/201
2024-03-30 17:53:13 -05:00

53 lines
1.3 KiB
JavaScript

const {test} = require('tap');
const Thread = require('../../src/engine/thread');
const Runtime = require('../../src/engine/runtime');
const Target = require('../../src/engine/target');
test('stopThisScript procedures_call reporter form', t => {
const rt = new Runtime();
const target = new Target(rt, null);
target.blocks.createBlock({
id: 'reporterCall',
opcode: 'procedures_call',
inputs: {},
fields: {},
mutation: {
return: '1'
},
shadow: false,
topLevel: true,
parent: null,
next: 'afterReporterCall'
});
target.blocks.createBlock({
id: 'afterReporterCall',
opcode: 'motion_ifonedgebounce',
inputs: {},
fields: {},
mutation: null,
shadow: false,
topLevel: false,
parent: null,
next: null
});
const thread = new Thread('reporterCall');
thread.target = target;
// pretend to run reporterCall
thread.pushStack('reporterCall');
thread.peekStackFrame().waitingReporter = true;
// pretend to run scripts inside of the procedure
thread.pushStack('fakeBlock');
// stopping or returning should always return to reporterCall, not the block after
thread.stopThisScript();
t.same(thread.stack, [
'reporterCall'
]);
t.end();
});