Open Bug 1173716 Opened 9 years ago Updated 1 year ago

alert() spins the event loop, which can cause other alert() calls to happen and cover up the older alert

Categories

(Core :: DOM: Core & HTML, defect, P3)

38 Branch
x86
Windows XP
defect

Tracking

()

UNCONFIRMED

People

(Reporter: tcaudilllg, Unassigned)

References

(Blocks 1 open bug)

Details

(Keywords: parity-chrome, parity-edge, Whiteboard: DUPEME)

User Agent: Mozilla/5.0 (Windows NT 5.1; rv:38.0) Gecko/20100101 Firefox/38.0 Build ID: 20150525141253 Steps to reproduce: imageTest = new Image(); imageTest.onload = checkout; imageTest.src = "whatever.png"; alert("foo"); function checkout () { alert("bar"); } Actual results: alert("bar") happens before alert("foo"); Expected results: May only be happening with local files, but it works in Chrome. Used to work in Firefox, as well.
Severity: normal → critical
Component: Untriaged → General
OS: Unspecified → Windows XP
Hardware: Unspecified → x86
Component: General → DOM
Product: Firefox → Core
Severity: critical → normal
I expect this to be fixed by the end of the day. Compliance with DOM level 1 is the least that should be expected of the institution that has screamed the loudest about standards compliance.
Severity: normal → major
> alert("bar") happens before alert("foo"); No, what happens is that alert("foo") happens first. This spins the event loop, which causes the image load to complete, the image load handler to fire, and the second alert() call to happen. The second alert is then shown on top of the first alert. Since the image loads quickly, you only perceive the state with the second alert on top, click it away, and see the (older) first alert. If the image loaded slowly enough you'd see the full sequence of events here. You should try console.log() instead of alert if you want to see the order those two code positions are actually reached in without the nested event loop interference. Note that DOM level 1 doesn't define the behavior of alert() at all (or of the image load event, for that matter), so there is no DOM level 1 compliance issue here.
Severity: major → normal
Summary: Javascript image onload event fires immediately after receiving function reference → alert() spins the event loop, which can cause other alert() calls to happen and cover up the older alert
Whiteboard: DUPEME
Alright, level 2 then. I know the event is misfiring because I'm using a counter to track img object loads before drawing to canvas. The counter is jumping to the max and rendering before load, causing drawImage to fail. This is not not happening in Chrome (and it didn't used to in FF before 38).
> Alright, level 2 then. alert() isn't defined by DOM level 2 either. Or level 3, for that matter. > I know the event is misfiring because I'm using a counter to track img object loads > before drawing to canvas. Please feel free to post a testcase or link to testcase that shows the actual issue you're encontering. I'll be happy to take a look at it.
https://jsfiddle.net/jdctgsp1/ It makes a game map based on the data in a file. You'll have to plug in values for width and height and cell size (make width/height kinda small, like 20 or 30), and give it a file to analyze. You'll need to give it a list of images to draw, separated by line breaks, in the box below the Draw Map button. Click Draw Map to use.
(In reply to tcaudilllg from comment #5) > https://jsfiddle.net/jdctgsp1/ > > It makes a game map based on the data in a file. > You'll have to plug in values for width and height and cell size (make > width/height kinda small, like 20 or 30), and give it a file to analyze. > You'll need to give it a list of images to draw, > separated by line breaks, in the box below the Draw Map button. Click Draw > Map to use. One more thing: you have to put a starting offset for read in the box after "Draw Map from".
> and give it a file to analyze What sort of file? In case it wasn't clear, what would be ideal here is a testcase with clear steps to reproduce that can definitely be followed by anyone without screwing them up. Comment 5 is not it. :(
Oh, and the other thing that's needed is a clear description of the expected behavior and the actual behavior you see, so I can tell whether I'm reproducing the problem you're seeing.
If your issue is not specific to alert(), please take it back to bug 1211528.
Whiteboard: DUPEME → DUPEME,[parity-Chrome][parity-Edge]
Priority: -- → P3
Mass bug change to replace various 'parity' whiteboard flags with the new canonical keywords. (See bug 1443764 comment 13.)
Whiteboard: DUPEME,[parity-Chrome][parity-Edge] → DUPEME,
Whiteboard: DUPEME, → DUPEME
Component: DOM → DOM: Core & HTML
Severity: normal → S3

Hello, can I try to solve this bug?
also I want to ask which file should I look to reproduce and solve this bug?

Flags: needinfo?(tcaudilllg)

This is a really complicated issue to fix.
Alert is implemented here https://searchfox.org/mozilla-central/rev/87ba454e5c68ff77dff9acb9d7b0b51d6df12d11/dom/base/nsGlobalWindowInner.cpp#3870-3880 but the issue is more about spinning event loop.
We should somehow block running tasks which might trigger any JS on the web page to run while still spinning the event loop so that underlying privileged code (native C++ and JS) can still run.

This is definitely not a good first bug ;)

https://bugzilla.mozilla.org/buglist.cgi?keywords_type=allwords&query_format=advanced&classification=Client%20Software&classification=Developer%20Infrastructure&classification=Components&classification=Server%20Software&classification=Other&list_id=16580470&keywords=good-first-bug%2C%20&resolution=--- has a list of possibly easier bugs.

Redirect a needinfo that is pending on an inactive user to the triage owner.
:edgar, since the bug has recent activity, could you have a look please?

For more information, please visit BugBot documentation.

Flags: needinfo?(tcaudilllg) → needinfo?(echen)

I think comment #20 already provides enough information.

Flags: needinfo?(echen)
You need to log in before you can comment on or make changes to this bug.