mirror of
https://github.com/scratchfoundation/scratch-vm.git
synced 2025-08-28 22:30:40 -04:00
Implement "Stop this script" function
Existing implementation incorrectly terminates the entire thread. See: http://llk.github.io/scratch-vm/#144142535
This commit is contained in:
parent
aecc3bf893
commit
9cb595312e
4 changed files with 28 additions and 7 deletions
|
@ -110,7 +110,7 @@ Scratch3ControlBlocks.prototype.stop = function (args, util) {
|
|||
option === 'other scripts in stage') {
|
||||
util.stopOtherTargetThreads();
|
||||
} else if (option === 'this script') {
|
||||
util.stopThread();
|
||||
util.stopThisScript();
|
||||
}
|
||||
};
|
||||
|
||||
|
|
|
@ -183,8 +183,8 @@ var execute = function (sequencer, thread) {
|
|||
stopOtherTargetThreads: function () {
|
||||
runtime.stopForTarget(target, thread);
|
||||
},
|
||||
stopThread: function () {
|
||||
sequencer.retireThread(thread);
|
||||
stopThisScript: function () {
|
||||
thread.stopThisScript();
|
||||
},
|
||||
startProcedure: function (procedureCode) {
|
||||
sequencer.stepToProcedure(thread, procedureCode);
|
||||
|
|
|
@ -140,6 +140,27 @@ Thread.prototype.popStack = function () {
|
|||
return this.stack.pop();
|
||||
};
|
||||
|
||||
/**
|
||||
* Pop back down the stack frame until we hit a procedure call or the stack frame is emptied
|
||||
*/
|
||||
Thread.prototype.stopThisScript = function () {
|
||||
var blockID = this.peekStack();
|
||||
while (blockID !== null) {
|
||||
var block = this.target.blocks.getBlock(blockID);
|
||||
if (typeof block !== 'undefined' && block.opcode === 'procedures_callnoreturn') {
|
||||
break;
|
||||
}
|
||||
this.popStack();
|
||||
blockID = this.peekStack();
|
||||
}
|
||||
|
||||
if (this.stack.length === 0) {
|
||||
// Clean up!
|
||||
this.requestScriptGlowInFrame = false;
|
||||
this.status = Thread.STATUS_DONE;
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Get top stack item.
|
||||
* @return {?string} Block ID on top of stack.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue