forked from scratchfoundation/scratch-vm
-
-
Notifications
You must be signed in to change notification settings - Fork 74
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
interpreter: Do not re-evaluate procedure arguments after stop this s…
…cript 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 #201
- Loading branch information
1 parent
064155f
commit 20f25f2
Showing
6 changed files
with
117 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file added
BIN
+2.44 KB
test/fixtures/execute/tw-gh-201-stop-script-does-not-reevaluate-arguments.sb3
Binary file not shown.
25 changes: 25 additions & 0 deletions
25
...napshot/__snapshots__/tw-gh-201-stop-script-does-not-reevaluate-arguments.sb3.tw-snapshot
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
// TW Snapshot | ||
// Input SHA-256: fd981742e0e4299bad5a89349635d3a7d0467d8163ae77ba4bafe43c97849bae | ||
|
||
// Sprite1 script | ||
(function factoryXYZ(thread) { const target = thread.target; const runtime = target.runtime; const stage = runtime.getTargetForStage(); | ||
const b0 = runtime.getOpcodeFunction("looks_say"); | ||
return function* genXYZ () { | ||
yield* executeInCompatibilityLayer({"MESSAGE":"plan 0",}, b0, false, false, "d", null); | ||
thread.procedures["Zfoo %s"](""); | ||
yield* executeInCompatibilityLayer({"MESSAGE":"end",}, b0, false, false, "g", null); | ||
retire(); return; | ||
}; }) | ||
|
||
// Sprite1 foo %s | ||
(function factoryXYZ(thread) { const target = thread.target; const runtime = target.runtime; const stage = runtime.getTargetForStage(); | ||
return function funXYZ_foo_ (p0) { | ||
return ""; | ||
return ""; | ||
}; }) | ||
|
||
// Sprite1 no op | ||
(function factoryXYZ(thread) { const target = thread.target; const runtime = target.runtime; const stage = runtime.getTargetForStage(); | ||
return function funXYZ_no_op () { | ||
return ""; | ||
}; }) |
25 changes: 25 additions & 0 deletions
25
...napshots__/warp-timer/tw-gh-201-stop-script-does-not-reevaluate-arguments.sb3.tw-snapshot
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
// TW Snapshot | ||
// Input SHA-256: fd981742e0e4299bad5a89349635d3a7d0467d8163ae77ba4bafe43c97849bae | ||
|
||
// Sprite1 script | ||
(function factoryXYZ(thread) { const target = thread.target; const runtime = target.runtime; const stage = runtime.getTargetForStage(); | ||
const b0 = runtime.getOpcodeFunction("looks_say"); | ||
return function* genXYZ () { | ||
yield* executeInCompatibilityLayer({"MESSAGE":"plan 0",}, b0, false, false, "d", null); | ||
thread.procedures["Zfoo %s"](""); | ||
yield* executeInCompatibilityLayer({"MESSAGE":"end",}, b0, false, false, "g", null); | ||
retire(); return; | ||
}; }) | ||
|
||
// Sprite1 foo %s | ||
(function factoryXYZ(thread) { const target = thread.target; const runtime = target.runtime; const stage = runtime.getTargetForStage(); | ||
return function funXYZ_foo_ (p0) { | ||
return ""; | ||
return ""; | ||
}; }) | ||
|
||
// Sprite1 no op | ||
(function factoryXYZ(thread) { const target = thread.target; const runtime = target.runtime; const stage = runtime.getTargetForStage(); | ||
return function funXYZ_no_op () { | ||
return ""; | ||
}; }) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
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(); | ||
}); |