From fee3c4cc0441d67b1ff4b433a9f00004ee3a59c7 Mon Sep 17 00:00:00 2001
From: "Michael \"Z\" Goddard" <mzgoddard@gmail.com>
Date: Fri, 13 Jul 2018 10:23:42 -0400
Subject: [PATCH] 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.
---
 src/engine/execute.js | 14 +++++++-------
 1 file changed, 7 insertions(+), 7 deletions(-)

diff --git a/src/engine/execute.js b/src/engine/execute.js
index be35e31b5..a6958aabd 100644
--- a/src/engine/execute.js
+++ b/src/engine/execute.js
@@ -50,7 +50,7 @@ const isPromise = function (value) {
  */
 // @todo move this to callback attached to the thread when we have performance
 // metrics (dd)
-const handleReport = function (resolvedValue, sequencer, thread, blockCached) {
+const handleReport = function (resolvedValue, sequencer, thread, blockCached, lastOperation) {
     const currentBlockId = blockCached.id;
     const opcode = blockCached.opcode;
     const isHat = blockCached._isHat;
@@ -80,7 +80,7 @@ const handleReport = function (resolvedValue, sequencer, thread, blockCached) {
     } else {
         // In a non-hat, report the value visually if necessary if
         // at the top of the thread stack.
-        if (typeof resolvedValue !== 'undefined' && thread.atStackTop()) {
+        if (lastOperation && typeof resolvedValue !== 'undefined' && thread.atStackTop()) {
             if (thread.stackClick) {
                 sequencer.runtime.visualReport(currentBlockId, resolvedValue);
             }
@@ -109,7 +109,7 @@ const handlePromise = (primitiveReportedValue, sequencer, thread, blockCached, l
     }
     // Promise handlers
     primitiveReportedValue.then(resolvedValue => {
-        handleReport(resolvedValue, sequencer, thread, blockCached);
+        handleReport(resolvedValue, sequencer, thread, blockCached, lastOperation);
         // If its a command block.
         if (lastOperation && typeof resolvedValue === 'undefined') {
             let stackFrame;
@@ -465,7 +465,7 @@ const execute = function (sequencer, thread) {
     }
 
     for (; i < length; i++) {
-        const last = i === length - 1;
+        const lastOperation = i === length - 1;
         const opCached = ops[i];
 
         const blockFunction = opCached._blockFunction;
@@ -501,7 +501,7 @@ const execute = function (sequencer, thread) {
 
         // If it's a promise, wait until promise resolves.
         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
             // 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.
             break;
         } else if (thread.status === Thread.STATUS_RUNNING) {
-            if (last) {
+            if (lastOperation) {
                 if (typeof primitiveReportedValue === 'undefined') {
                     // No value reported - potentially a command block.
                     // Edge-activated hats don't request a glow; all
@@ -537,7 +537,7 @@ const execute = function (sequencer, thread) {
                     thread.requestScriptGlowInFrame = true;
                 }
 
-                handleReport(primitiveReportedValue, sequencer, thread, opCached);
+                handleReport(primitiveReportedValue, sequencer, thread, opCached, lastOperation);
             } else {
                 // By definition a block that is not last in the list has a
                 // parent.