Verified Commit 9b388f08 authored by Georg Koppen's avatar Georg Koppen Committed by Pier Angelo Vendrame
Browse files

Revert "Bug 1724777, optimize suppressed MicroTask handling, r=mccr8 a=RyanVM"

This reverts commit 1eb13643.

This fixes tor-browser#40721, tor-browser#40698, and #40706.
However, it is a temporary workaround, that we should revert once
https://bugzilla.mozilla.org/show_bug.cgi?id=1744719 is fixed.
parent cd05477a
Loading
Loading
Loading
Loading
+0 −12
Original line number Diff line number Diff line
@@ -16095,18 +16095,6 @@ nsAutoSyncOperation::~nsAutoSyncOperation() {
  }
}
void Document::SetIsInSyncOperation(bool aSync) {
  if (CycleCollectedJSContext* ccjs = CycleCollectedJSContext::Get()) {
    ccjs->UpdateMicroTaskSuppressionGeneration();
  }
  if (aSync) {
    ++mInSyncOperationCount;
  } else {
    --mInSyncOperationCount;
  }
}
gfxUserFontSet* Document::GetUserFontSet() {
  if (!mFontFaceSet) {
    return nullptr;
+7 −1
Original line number Diff line number Diff line
@@ -3253,7 +3253,13 @@ class Document : public nsINode,

  bool IsInSyncOperation() { return mInSyncOperationCount != 0; }

  void SetIsInSyncOperation(bool aSync);
  void SetIsInSyncOperation(bool aSync) {
    if (aSync) {
      ++mInSyncOperationCount;
    } else {
      --mInSyncOperationCount;
    }
  }

  bool CreatingStaticClone() const { return mCreatingStaticClone; }

+0 −2
Original line number Diff line number Diff line
@@ -908,8 +908,6 @@ support-files =
  file_suppressed_events_middle.html
  file_suppressed_events_inner.html
  !/gfx/layers/apz/test/mochitest/apz_test_utils.js
[test_suppressed_microtasks.html]
skip-if = debug || asan || verify || toolkit == 'android' # The test needs to run reasonably fast.
[test_text_wholeText.html]
[test_textnode_normalize_in_selection.html]
[test_textnode_split_in_selection.html]
+0 −62
Original line number Diff line number Diff line
<!DOCTYPE HTML>
<html>
<head>
  <meta charset="utf-8">
  <title>Test microtask suppression</title>
  <script src="/tests/SimpleTest/SimpleTest.js"></script>
  <link rel="stylesheet" href="/tests/SimpleTest/test.css"/>
  <script>
    SimpleTest.waitForExplicitFinish();

    var previousTask = -1;
    function test() {
      let win = window.open("about:blank");
      win.onload = function() {
        win.onmessage = function() {
          win.start = win.performance.now();
          win.didRunMicrotask = false;
          win.onmessage = function() {
            ok(win.didRunMicrotask, "Should have run a microtask.");
            let period = win.performance.now() - win.start;
            win.opener.ok(
              period < 200,
              "Running a task should be fast. Took " + period + "ms.");
            win.onmessage = null;
          }
          win.queueMicrotask(function() { win.didRunMicrotask = true; });
          win.postMessage("measurementMessage", "*");
        }
        win.postMessage("initialMessage", "*");

        const last = 500000;
        for (let i = 0; i < last + 1; ++i) {
          window.queueMicrotask(function() {
            // Check that once microtasks are unsuppressed, they are handled in
            // the correct order.
            if (previousTask !=  i - 1) {
              // Explicitly optimize out cases which pass.
              ok(false, "Microtasks should be handled in order.");
            }
            previousTask = i;
            if (i == last) {
              win.close();
              SimpleTest.finish();
            }
          });
        }

        // Synchronous XMLHttpRequest suppresses microtasks.
        var xhr = new XMLHttpRequest();
        xhr.open("GET", "slow.sjs", false);
        xhr.send();
        is(previousTask, -1, "Shouldn't have run microtasks during a sync XHR.");
      }
    }
  </script>
</head>
<body onload="test()">
<p id="display"></p>
<div id="content" style="display: none"></div>
<pre id="test"></pre>
</body>
</html>
+2 −2
Original line number Diff line number Diff line
@@ -885,7 +885,7 @@ class WorkerJSContext final : public mozilla::CycleCollectedJSContext {
    MOZ_ASSERT(!NS_IsMainThread());
    MOZ_ASSERT(runnable);

    std::deque<RefPtr<MicroTaskRunnable>>* microTaskQueue = nullptr;
    std::queue<RefPtr<MicroTaskRunnable>>* microTaskQueue = nullptr;

    JSContext* cx = Context();
    NS_ASSERTION(cx, "This should never be null!");
@@ -907,7 +907,7 @@ class WorkerJSContext final : public mozilla::CycleCollectedJSContext {
    }

    JS::JobQueueMayNotBeEmpty(cx);
    microTaskQueue->push_back(std::move(runnable));
    microTaskQueue->push(std::move(runnable));
  }

  bool IsSystemCaller() const override {
Loading