mirror of
https://github.com/scratchfoundation/scratch-vm.git
synced 2025-06-06 10:34:05 -04:00
Add sequencer-level debug console logs
This commit is contained in:
parent
5767e05d56
commit
c1e30cf2ee
4 changed files with 19 additions and 11 deletions
|
@ -8,7 +8,7 @@
|
||||||
"max-len": [2, 80, 4],
|
"max-len": [2, 80, 4],
|
||||||
"semi": [2, "always"],
|
"semi": [2, "always"],
|
||||||
"strict": [2, "never"],
|
"strict": [2, "never"],
|
||||||
"no-console": [2, {"allow": ["log", "warn", "error"]}]
|
"no-console": [2, {"allow": ["log", "warn", "error", "groupCollapsed", "groupEnd"]}]
|
||||||
},
|
},
|
||||||
"env": {
|
"env": {
|
||||||
"node": true,
|
"node": true,
|
||||||
|
|
|
@ -23,7 +23,6 @@ Scratch3Blocks.prototype.getPrimitives = function() {
|
||||||
};
|
};
|
||||||
|
|
||||||
Scratch3Blocks.prototype.repeat = function(argValues, util) {
|
Scratch3Blocks.prototype.repeat = function(argValues, util) {
|
||||||
console.log('Running: control_repeat');
|
|
||||||
// Initialize loop
|
// Initialize loop
|
||||||
if (util.stackFrame.loopCounter === undefined) {
|
if (util.stackFrame.loopCounter === undefined) {
|
||||||
util.stackFrame.loopCounter = parseInt(argValues[0]); // @todo arg
|
util.stackFrame.loopCounter = parseInt(argValues[0]); // @todo arg
|
||||||
|
@ -37,12 +36,10 @@ Scratch3Blocks.prototype.repeat = function(argValues, util) {
|
||||||
};
|
};
|
||||||
|
|
||||||
Scratch3Blocks.prototype.forever = function(argValues, util) {
|
Scratch3Blocks.prototype.forever = function(argValues, util) {
|
||||||
console.log('Running: control_forever');
|
|
||||||
util.startSubstack();
|
util.startSubstack();
|
||||||
};
|
};
|
||||||
|
|
||||||
Scratch3Blocks.prototype.wait = function(argValues, util) {
|
Scratch3Blocks.prototype.wait = function(argValues, util) {
|
||||||
console.log('Running: control_wait');
|
|
||||||
util.yield();
|
util.yield();
|
||||||
util.timeout(function() {
|
util.timeout(function() {
|
||||||
util.done();
|
util.done();
|
||||||
|
@ -50,23 +47,19 @@ Scratch3Blocks.prototype.wait = function(argValues, util) {
|
||||||
};
|
};
|
||||||
|
|
||||||
Scratch3Blocks.prototype.stop = function() {
|
Scratch3Blocks.prototype.stop = function() {
|
||||||
console.log('Running: control_stop');
|
|
||||||
// @todo - don't use this.runtime
|
// @todo - don't use this.runtime
|
||||||
this.runtime.stopAll();
|
this.runtime.stopAll();
|
||||||
};
|
};
|
||||||
|
|
||||||
Scratch3Blocks.prototype.whenFlagClicked = function() {
|
Scratch3Blocks.prototype.whenFlagClicked = function() {
|
||||||
console.log('Running: event_whenflagclicked');
|
|
||||||
// No-op
|
// No-op
|
||||||
};
|
};
|
||||||
|
|
||||||
Scratch3Blocks.prototype.whenBroadcastReceived = function() {
|
Scratch3Blocks.prototype.whenBroadcastReceived = function() {
|
||||||
console.log('Running: event_whenbroadcastreceived');
|
|
||||||
// No-op
|
// No-op
|
||||||
};
|
};
|
||||||
|
|
||||||
Scratch3Blocks.prototype.broadcast = function(argValues, util) {
|
Scratch3Blocks.prototype.broadcast = function(argValues, util) {
|
||||||
console.log('Running: event_broadcast');
|
|
||||||
util.startHats(function(hat) {
|
util.startHats(function(hat) {
|
||||||
if (hat.opcode === 'event_whenbroadcastreceived') {
|
if (hat.opcode === 'event_whenbroadcastreceived') {
|
||||||
var shadows = hat.fields.CHOICE.blocks;
|
var shadows = hat.fields.CHOICE.blocks;
|
||||||
|
|
|
@ -144,11 +144,9 @@ WeDo2Blocks.prototype.setColor = function(argValues, util) {
|
||||||
};
|
};
|
||||||
|
|
||||||
WeDo2Blocks.prototype.whenDistanceClose = function() {
|
WeDo2Blocks.prototype.whenDistanceClose = function() {
|
||||||
console.log('Running: wedo_whendistanceclose');
|
|
||||||
};
|
};
|
||||||
|
|
||||||
WeDo2Blocks.prototype.whenTilt = function() {
|
WeDo2Blocks.prototype.whenTilt = function() {
|
||||||
console.log('Running: wedo_whentilt');
|
|
||||||
};
|
};
|
||||||
|
|
||||||
module.exports = WeDo2Blocks;
|
module.exports = WeDo2Blocks;
|
||||||
|
|
|
@ -24,6 +24,12 @@ function Sequencer (runtime) {
|
||||||
*/
|
*/
|
||||||
Sequencer.WORK_TIME = 10;
|
Sequencer.WORK_TIME = 10;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* If set, block calls, args, and return values will be logged to the console.
|
||||||
|
* @const {boolean}
|
||||||
|
*/
|
||||||
|
Sequencer.DEBUG_BLOCK_CALLS = true;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Step through all threads in `this.threads`, running them in order.
|
* Step through all threads in `this.threads`, running them in order.
|
||||||
* @return {Array.<Thread>} All threads which have finished in this iteration.
|
* @return {Array.<Thread>} All threads which have finished in this iteration.
|
||||||
|
@ -213,9 +219,15 @@ Sequencer.prototype.stepThread = function (thread) {
|
||||||
console.warn('Could not get implementation for opcode: ' + opcode);
|
console.warn('Could not get implementation for opcode: ' + opcode);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
if (Sequencer.DEBUG_BLOCK_CALLS) {
|
||||||
|
console.groupCollapsed('Executing: ' + opcode);
|
||||||
|
console.log('with arguments: ', argValues);
|
||||||
|
console.log('and stack frame: ', currentStackFrame);
|
||||||
|
}
|
||||||
|
var blockFunctionReturnValue = null;
|
||||||
try {
|
try {
|
||||||
// @todo deal with the return value
|
// @todo deal with the return value
|
||||||
blockFunction(argValues, {
|
blockFunctionReturnValue = blockFunction(argValues, {
|
||||||
yield: threadYieldCallback,
|
yield: threadYieldCallback,
|
||||||
done: threadDoneCallback,
|
done: threadDoneCallback,
|
||||||
timeout: YieldTimers.timeout,
|
timeout: YieldTimers.timeout,
|
||||||
|
@ -238,6 +250,11 @@ Sequencer.prototype.stepThread = function (thread) {
|
||||||
// Thread executed without yielding - move to done
|
// Thread executed without yielding - move to done
|
||||||
threadDoneCallback();
|
threadDoneCallback();
|
||||||
}
|
}
|
||||||
|
if (Sequencer.DEBUG_BLOCK_CALLS) {
|
||||||
|
console.log('ending stack frame: ', currentStackFrame);
|
||||||
|
console.log('returned: ', blockFunctionReturnValue);
|
||||||
|
console.groupEnd();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue