Przeglądaj źródła

LibWeb: Ensure requestAnimationFrame callbacks run in the proper order

From https://html.spec.whatwg.org/#list-of-animation-frame-callbacks:

    Each target object has a map of animation frame callbacks, which is
    an ordered map that must be initially empty, and an animation frame
    callback identifier, which is a number that must initially be zero.
Matthew Olsson 1 rok temu
rodzic
commit
c33f6b2ff6

+ 20 - 0
Tests/LibWeb/Text/expected/request-animation-frame-order.txt

@@ -0,0 +1,20 @@
+   0
+1
+2
+3
+4
+5
+6
+7
+8
+9
+10
+11
+12
+13
+14
+15
+16
+17
+18
+19

+ 14 - 0
Tests/LibWeb/Text/input/request-animation-frame-order.html

@@ -0,0 +1,14 @@
+<!DOCTYPE html>
+<div id="foo"></div>
+<script src="include.js"></script>
+<script>
+    test(() => {
+        for (let i = 0; i < 20; i++) {
+            // FIXME: Workaround for https://github.com/SerenityOS/serenity/issues/23552
+            let x = i;
+            requestAnimationFrame(() => {
+                println(x);
+            });
+        }
+    });
+</script>

+ 1 - 1
Userland/Libraries/LibWeb/HTML/AnimationFrameCallbackDriver.h

@@ -56,7 +56,7 @@ struct AnimationFrameCallbackDriver {
     }
 
 private:
-    HashMap<i32, Callback> m_callbacks;
+    OrderedHashMap<i32, Callback> m_callbacks;
     IDAllocator m_id_allocator;
     RefPtr<Platform::Timer> m_timer;
 };