Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/blocks/scratch3_control.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
};

Expand Down
4 changes: 2 additions & 2 deletions src/engine/execute.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
21 changes: 21 additions & 0 deletions src/engine/thread.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
8 changes: 4 additions & 4 deletions test/unit/blocks_control.js
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ test('stop', function (t) {
var state = {
stopAll: 0,
stopOtherTargetThreads: 0,
stopThread: 0
stopThisScript: 0
};
var util = {
stopAll: function () {
Expand All @@ -113,8 +113,8 @@ test('stop', function (t) {
stopOtherTargetThreads: function () {
state.stopOtherTargetThreads++;
},
stopThread: function () {
state.stopThread++;
stopThisScript: function () {
state.stopThisScript++;
}
};

Expand All @@ -125,6 +125,6 @@ test('stop', function (t) {
c.stop({STOP_OPTION: 'this script'}, util);
t.strictEqual(state.stopAll, 1);
t.strictEqual(state.stopOtherTargetThreads, 2);
t.strictEqual(state.stopThread, 1);
t.strictEqual(state.stopThisScript, 1);
t.end();
});