setTimeout is not executed if called from inside an event handler

RESOLVED DUPLICATE of bug 765780

Status

()

Core
DOM
RESOLVED DUPLICATE of bug 765780
5 years ago
3 years ago

People

(Reporter: Michal Kawalec, Unassigned)

Tracking

21 Branch
x86_64
Linux
Points:
---

Firefox Tracking Flags

(Not tracked)

Details

(Reporter)

Description

5 years ago
User Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/28.0.1500.52 Safari/537.36

Steps to reproduce:

Consider the following JS code that uses jQuery:

$(document).on('click', function (e) {
    console.log('clicked');
    setTimeout(function () { console.log('yes'); }, 0);
});


Actual results:

Only 'clicked' was printed to the console after a click.


Expected results:

'clicked' should be followed by 'yes' and it is in all the other major browsers.
Can you provide a test case that doesn't use jQuery?
Flags: needinfo?(michal)
(Reporter)

Comment 2

5 years ago
I played around and the matter became even more interesting:

a = function() { 
    console.log('executed'); 
    setTimeout(function(){console.log('yes');}, 0); };
a();

returns just 'executed', 'yes' is not shown (while it works in Chromium).
Flags: needinfo?(michal)
(Reporter)

Comment 3

5 years ago
Well, it only happens on my site (running the same code in Firebug while on google.com produces correct results). I will investigate a bit more then.
(Reporter)

Comment 4

5 years ago
Apparently turning the designMode on triggers this weird behaviour of the JS engine.

Updated

5 years ago
Duplicate of this bug: 887194
Aha, that's an important part. Can you test with a build from nightly.mozilla.org?
(Reporter)

Comment 7

5 years ago
Just tested with the latest nightly from AUR (Arch linux) and the same thing happens. The exact test case I am using is:

(function() { console.log('clicked'); setTimeout(function() { console.log('yes'); }, 0); })(
(Reporter)

Comment 8

5 years ago
I missed a closing bracket when pasting, the test case is:

(function() { console.log('clicked'); setTimeout(function(){console.log('yes');}, 0); })()
(Reporter)

Comment 9

5 years ago
I am sorry for a message flood, but I am focused on something else at the moment. The test case would not be complete without turning the designMode on. Therefore I present upon you the complete test case:

document.designMode = "on";
(function() { console.log('clicked'); setTimeout(function(){console.log('yes');}, 0); })()

Comment 10

5 years ago
With the last testcase:

FF22 on Win 7:
--
[14:36:57,683] document.designMode = "on";
(function() { console.log('clicked'); setTimeout(function(){console.log('yes');}, 0); })()
[14:36:57,687] undefined
[14:36:57,710] clicked

FF25 on Win 7:
[14:35:40.284] document.designMode = "on";
(function() { console.log('clicked'); setTimeout(function(){console.log('yes');}, 0); })()
[14:35:40.287] undefined
[14:35:40.310] "clicked"
[14:35:40.311] "yes"
(Reporter)

Comment 11

5 years ago
I can confirm Loic's findings - there is an expected behaviour in Aurora on Windows 7 in my case too, but on x86_64 Arch (and Aurora) the problem persists.

Comment 12

5 years ago
duplication of Bug 466688 ?
(Reporter)

Comment 13

5 years ago
I doubt that it is a duplicate - if scripts are disabled, why would it be working on Windows? Plus, the compilation surely works as first console.log is executed without problems. So I vote no.

Updated

5 years ago
Component: Untriaged → DOM
Keywords: testcase-wanted
Product: Firefox → Core
This is a duplicate of bug 765780.

> If scripts are disabled, why would it be working on Windows?

It's working in Firefox 23 and later, as far as I can tell, on all platforms.  As expected given bug 765780.

> Plus, the compilation surely works as first console.log is executed without problems.

The compilation and start of execution of the first script happened before designMode was turned on, of course: it's that script that changes designMode.
Status: UNCONFIRMED → RESOLVED
Last Resolved: 5 years ago
Resolution: --- → DUPLICATE
Duplicate of bug: 765780
Keywords: testcase-wanted
You need to log in before you can comment on or make changes to this bug.