From 48721dd33657f0f530e7dc0be3be5f2b3ef7f7ff Mon Sep 17 00:00:00 2001 From: Andrew Sliwinski Date: Fri, 23 Dec 2016 09:38:18 -0500 Subject: [PATCH] If not hat fields are not found, check inputs before continuing. Resolves GH-360 --- src/engine/runtime.js | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/engine/runtime.js b/src/engine/runtime.js index a404ce421..9c49d9ec1 100644 --- a/src/engine/runtime.js +++ b/src/engine/runtime.js @@ -435,12 +435,24 @@ Runtime.prototype.startHats = function (requestedHatOpcode, // Not the right hat. return; } + // Match any requested fields. // For example: ensures that broadcasts match. // This needs to happen before the block is evaluated // (i.e., before the predicate can be run) because "broadcast and wait" // needs to have a precise collection of started threads. var hatFields = target.blocks.getFields(topBlockId); + + // If no fields are present, check inputs (horizontal blocks) + if (Object.keys(hatFields).length === 0) { + var hatInputs = target.blocks.getInputs(topBlockId); + for (var input in hatInputs) { + var id = hatInputs[input].block; + var fields = target.blocks.getFields(id); + hatFields = Object.assign(fields, hatFields); + } + } + if (optMatchFields) { for (var matchField in optMatchFields) { if (hatFields[matchField].value !== @@ -450,6 +462,7 @@ Runtime.prototype.startHats = function (requestedHatOpcode, } } } + // Look up metadata for the relevant hat. var hatMeta = instance._hats[requestedHatOpcode]; if (hatMeta.restartExistingThreads) {