fix unnecessary stackClick report from nested promise reporters

Check that a reporting block is the last operation as part of some
parent block. The last operation is the block itself which may report
values for stack clicks and monitor updates if it meets other
requirements.
This commit is contained in:
Michael "Z" Goddard 2018-07-13 10:23:42 -04:00
parent c69a59575d
commit fee3c4cc04
No known key found for this signature in database
GPG key ID: 762CD40DD5349872

View file

@ -50,7 +50,7 @@ const isPromise = function (value) {
*/ */
// @todo move this to callback attached to the thread when we have performance // @todo move this to callback attached to the thread when we have performance
// metrics (dd) // metrics (dd)
const handleReport = function (resolvedValue, sequencer, thread, blockCached) { const handleReport = function (resolvedValue, sequencer, thread, blockCached, lastOperation) {
const currentBlockId = blockCached.id; const currentBlockId = blockCached.id;
const opcode = blockCached.opcode; const opcode = blockCached.opcode;
const isHat = blockCached._isHat; const isHat = blockCached._isHat;
@ -80,7 +80,7 @@ const handleReport = function (resolvedValue, sequencer, thread, blockCached) {
} else { } else {
// In a non-hat, report the value visually if necessary if // In a non-hat, report the value visually if necessary if
// at the top of the thread stack. // at the top of the thread stack.
if (typeof resolvedValue !== 'undefined' && thread.atStackTop()) { if (lastOperation && typeof resolvedValue !== 'undefined' && thread.atStackTop()) {
if (thread.stackClick) { if (thread.stackClick) {
sequencer.runtime.visualReport(currentBlockId, resolvedValue); sequencer.runtime.visualReport(currentBlockId, resolvedValue);
} }
@ -109,7 +109,7 @@ const handlePromise = (primitiveReportedValue, sequencer, thread, blockCached, l
} }
// Promise handlers // Promise handlers
primitiveReportedValue.then(resolvedValue => { primitiveReportedValue.then(resolvedValue => {
handleReport(resolvedValue, sequencer, thread, blockCached); handleReport(resolvedValue, sequencer, thread, blockCached, lastOperation);
// If its a command block. // If its a command block.
if (lastOperation && typeof resolvedValue === 'undefined') { if (lastOperation && typeof resolvedValue === 'undefined') {
let stackFrame; let stackFrame;
@ -465,7 +465,7 @@ const execute = function (sequencer, thread) {
} }
for (; i < length; i++) { for (; i < length; i++) {
const last = i === length - 1; const lastOperation = i === length - 1;
const opCached = ops[i]; const opCached = ops[i];
const blockFunction = opCached._blockFunction; const blockFunction = opCached._blockFunction;
@ -501,7 +501,7 @@ const execute = function (sequencer, thread) {
// If it's a promise, wait until promise resolves. // If it's a promise, wait until promise resolves.
if (isPromise(primitiveReportedValue)) { if (isPromise(primitiveReportedValue)) {
handlePromise(primitiveReportedValue, sequencer, thread, opCached, last); handlePromise(primitiveReportedValue, sequencer, thread, opCached, lastOperation);
// Store the already reported values. They will be thawed into the // Store the already reported values. They will be thawed into the
// future versions of the same operations by block id. The reporting // future versions of the same operations by block id. The reporting
@ -529,7 +529,7 @@ const execute = function (sequencer, thread) {
// and continue them later after thawing the reported values. // and continue them later after thawing the reported values.
break; break;
} else if (thread.status === Thread.STATUS_RUNNING) { } else if (thread.status === Thread.STATUS_RUNNING) {
if (last) { if (lastOperation) {
if (typeof primitiveReportedValue === 'undefined') { if (typeof primitiveReportedValue === 'undefined') {
// No value reported - potentially a command block. // No value reported - potentially a command block.
// Edge-activated hats don't request a glow; all // Edge-activated hats don't request a glow; all
@ -537,7 +537,7 @@ const execute = function (sequencer, thread) {
thread.requestScriptGlowInFrame = true; thread.requestScriptGlowInFrame = true;
} }
handleReport(primitiveReportedValue, sequencer, thread, opCached); handleReport(primitiveReportedValue, sequencer, thread, opCached, lastOperation);
} else { } else {
// By definition a block that is not last in the list has a // By definition a block that is not last in the list has a
// parent. // parent.