From bdbb884be02e8a43d452371e47e320ba5903bdc3 Mon Sep 17 00:00:00 2001 From: "jeremy@jermolene.com" Date: Mon, 20 Sep 2021 16:46:26 +0100 Subject: [PATCH] MessageCatcher: Fix stack overflow when re-issuing a trapped message This makes it possible to trap a message and then re-issue the same message within the action string without an infinite loop. --- core/modules/widgets/messagecatcher.js | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/core/modules/widgets/messagecatcher.js b/core/modules/widgets/messagecatcher.js index a1346cde4..85a3561f2 100644 --- a/core/modules/widgets/messagecatcher.js +++ b/core/modules/widgets/messagecatcher.js @@ -36,9 +36,14 @@ MessageCatcherWidget.prototype.render = function(parent,nextSibling) { // Helper to add an event handler var addEventHandler = function(type,actions) { if(type && actions) { + var isActionStringExecuting = false; self.addEventListener( type, function(event) { + // Don't trap the event if it came from one of our action handlers + if(isActionStringExecuting) { + return true; + } // Collect all the event properties into variables var collectProps = function(obj,prefix) { prefix = prefix || ""; @@ -60,7 +65,9 @@ MessageCatcherWidget.prototype.render = function(parent,nextSibling) { { modifier: $tw.keyboardManager.getEventModifierKeyDescriptor(event) }); + isActionStringExecuting = true; self.invokeActionString(actions,self,event,variables); + isActionStringExecuting = false; return false; } );