<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<!DOCTYPE bugzilla SYSTEM "https://bugs.webkit.org/page.cgi?id=bugzilla.dtd">

<bugzilla version="5.0.4.1"
          urlbase="https://bugs.webkit.org/"
          
          maintainer="admin@webkit.org"
>

    <bug>
          <bug_id>253423</bug_id>
          
          <creation_ts>2023-03-05 18:27:43 -0800</creation_ts>
          <short_desc>Regression(248952@main) setInterval and setTimeout order isn&apos;t respected when timeout is 0</short_desc>
          <delta_ts>2023-06-15 07:53:09 -0700</delta_ts>
          <reporter_accessible>1</reporter_accessible>
          <cclist_accessible>1</cclist_accessible>
          <classification_id>1</classification_id>
          <classification>Unclassified</classification>
          <product>WebKit</product>
          <component>WebCore Misc.</component>
          <version>WebKit Nightly Build</version>
          <rep_platform>Unspecified</rep_platform>
          <op_sys>Unspecified</op_sys>
          <bug_status>RESOLVED</bug_status>
          <resolution>FIXED</resolution>
          
          <see_also>https://bugs.webkit.org/show_bug.cgi?id=221124</see_also>
    
    <see_also>https://bugs.webkit.org/show_bug.cgi?id=258135</see_also>
          <bug_file_loc></bug_file_loc>
          <status_whiteboard></status_whiteboard>
          <keywords>InRadar</keywords>
          <priority>P2</priority>
          <bug_severity>Normal</bug_severity>
          <target_milestone>---</target_milestone>
          
          
          <everconfirmed>1</everconfirmed>
          <reporter name="Kaiido">tristan.fraipont</reporter>
          <assigned_to name="Chris Dumez">cdumez</assigned_to>
          <cc>ahmad.saleem792</cc>
    
    <cc>ap</cc>
    
    <cc>cdumez</cc>
    
    <cc>fujii</cc>
    
    <cc>heycam</cc>
    
    <cc>rniwa</cc>
    
    <cc>sam</cc>
    
    <cc>webkit-bug-importer</cc>
          

      

      

      

          <comment_sort_order>oldest_to_newest</comment_sort_order>  
          <long_desc isprivate="0" >
    <commentid>1939011</commentid>
    <comment_count>0</comment_count>
      <attachid>465310</attachid>
    <who name="Kaiido">tristan.fraipont</who>
    <bug_when>2023-03-05 18:27:43 -0800</bug_when>
    <thetext>Created attachment 465310
Test case

Online test case: https://jsfiddle.net/7g5f0cLz/
1. Queue a callback using setInterval(cb1, 0);
2. Queue a callback using setTimeout(cb2, 0);

The callback queued through setTimeout() is executed before the one queued through setInterval().
You can see this StackOverflow answer of mine https://stackoverflow.com/a/75646343/3702797 for a walk-through of the specs showing how this behavior is wrong. Basically, with the same ms value, the order should be respected.

Passing another ms value than 0 will make it behave normally.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1939012</commentid>
    <comment_count>1</comment_count>
    <who name="Ahmad Saleem">ahmad.saleem792</who>
    <bug_when>2023-03-05 18:58:06 -0800</bug_when>
    <thetext>I am able to reproduce this on WebKit ToT (261247@main) and also Chrome Canary 113 also show incorrect results:

setTimeout()
setInterval()

Only Firefox Nightly 112 is giving &apos;Expected&apos; result.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1939312</commentid>
    <comment_count>2</comment_count>
    <who name="Kaiido">tristan.fraipont</who>
    <bug_when>2023-03-06 18:49:21 -0800</bug_when>
    <thetext>&gt; Chrome Canary 113 also show incorrect results

Yes, this certainly comes from https://bugs.webkit.org/show_bug.cgi?id=221124 which removed the clamping of setTimeout( ,0) to 1ms, following what Chrome was going to do to.  
They&apos;ve got the same issue and it&apos;s been reported at https://crbug.com/1421612 I guess @Wanming.Lin might chime in here too. I&apos;ll mention this issue in the CRBUG too since they seem very related.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1940528</commentid>
    <comment_count>3</comment_count>
    <who name="Radar WebKit Bug Importer">webkit-bug-importer</who>
    <bug_when>2023-03-10 15:44:11 -0800</bug_when>
    <thetext>&lt;rdar://problem/106576260&gt;</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1940529</commentid>
    <comment_count>4</comment_count>
    <who name="Cameron McCormack (:heycam)">heycam</who>
    <bug_when>2023-03-10 15:47:39 -0800</bug_when>
    <thetext>Maybe we can make it so that setInterval(..., 0) will fire the callback immediately (i.e. honoring the 0ms) the first time, and at the clamped 1ms interval afterwards?</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1958844</commentid>
    <comment_count>5</comment_count>
    <who name="Chris Dumez">cdumez</who>
    <bug_when>2023-05-30 12:05:19 -0700</bug_when>
    <thetext>Pull request: https://github.com/WebKit/WebKit/pull/14499</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1958893</commentid>
    <comment_count>6</comment_count>
    <who name="EWS">ews-feeder</who>
    <bug_when>2023-05-30 15:14:12 -0700</bug_when>
    <thetext>Committed 264701@main (09e6c5eb406c): &lt;https://commits.webkit.org/264701@main&gt;

Reviewed commits have been landed. Closing PR #14499 and removing active labels.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1961213</commentid>
    <comment_count>7</comment_count>
    <who name="Fujii Hironori">fujii</who>
    <bug_when>2023-06-12 20:37:50 -0700</bug_when>
    <thetext>fast/dom/Window/setInterval-setTimeout-zero-ordering.html is flaky.
https://results.webkit.org/?suite=layout-tests&amp;test=fast%2Fdom%2FWindow%2FsetInterval-setTimeout-zero-ordering.html</thetext>
  </long_desc>
      
          <attachment
              isobsolete="0"
              ispatch="0"
              isprivate="0"
          >
            <attachid>465310</attachid>
            <date>2023-03-05 18:27:43 -0800</date>
            <delta_ts>2023-03-05 18:27:43 -0800</delta_ts>
            <desc>Test case</desc>
            <filename>test-case.html</filename>
            <type>text/html</type>
            <size>694</size>
            <attacher name="Kaiido">tristan.fraipont</attacher>
            
              <data encoding="base64">PCFET0NUWVBFIGh0bWw+CjxodG1sPgogIDxoZWFkPgogICAgPG1ldGEgY2hhcnNldD0idXRmOCI+
CiAgICA8c3R5bGU+LmV4cGVjdGVkIHByZSB7IGNvbG9yOiBncmVlbiB9Ozwvc3R5bGU+CiAgPC9o
ZWFkPgogIDxib2R5PgogICAgPGRpdiBjbGFzcz0iZXhwZWN0ZWQiPgogICAgICA8aDQ+RXhwZWN0
ZWQ8L2g0PgogICAgICA8cHJlPnNldEludGVydmFsKCkKc2V0VGltZW91dCgpCjwvcHJlPgogICAg
PC9kaXY+CiAgICA8ZGl2IGNsYXNzPSJhY3R1YWwiPgogICAgICA8aDQ+QWN0dWFsPC9oND4KICAg
ICAgPHByZT48L3ByZT4KICAgIDwvZGl2PgogICAgPHNjcmlwdD4KICAgICAgY29uc3QgcHJlID0g
ZG9jdW1lbnQucXVlcnlTZWxlY3RvcigiLmFjdHVhbCBwcmUiKTsKICAgICAgY29uc3QgaWQxID0g
c2V0SW50ZXJ2YWwoKCkgPT4gewogICAgICAgIHByZS50ZXh0Q29udGVudCArPSAic2V0SW50ZXJ2
YWwoKVxuIjsKICAgICAgICBwcmUuc3R5bGUuY29sb3IgPSAicmVkIjsKICAgICAgICBjbGVhcklu
dGVydmFsKGlkMSk7CiAgICAgIH0pOwogICAgICBjb25zdCBpZDIgPSBzZXRUaW1lb3V0KCgpID0+
IHsKICAgICAgICBwcmUudGV4dENvbnRlbnQgKz0gInNldFRpbWVvdXQoKVxuIjsKICAgICAgICBw
cmUuc3R5bGUuY29sb3IgPSAiZ3JlZW4iOwogICAgICB9KTsKICAgIDwvc2NyaXB0PgogIDwvYm9k
eT4KPC9odG1sPg==
</data>

          </attachment>
      

    </bug>

</bugzilla>