--- mozilla/dom/base/nsGlobalWindow.cpp.orig 2021-10-26 19:49:54.000000000 +0300
+++ mozilla/dom/base/nsGlobalWindow.cpp 2021-12-15 00:29:59.801185237 +0300
@@ -9254,6 +9254,22 @@ nsGlobalWindow::PostMessageMozOuter(JSCo
return;
}
+ //
+ // Do not generate new event here when something is pending.
+ // It avoids cpu hogs (esp. when run without e10s), preventing
+ // permanent event generation loop by badly written scripts.
+ //
+ // See also https://html.spec.whatwg.org/multipage/web-messaging.html
+ // p. 9.4.2.2 about rate-limiting etc.
+ //
+ if (!aTargetOrigin.EqualsASCII("/")) {
+ nsIThread* thread = NS_GetCurrentThread();
+
+ while (NS_HasPendingEvents(thread)) {
+ (void)NS_ProcessNextEvent(thread, false);
+ }
+ }
+
aError = Dispatch(TaskCategory::Other, event.forget());
}