Bug 91285 - confirm() pauses thread execution but doesn't prevent new, default, events from firing.
Summary: confirm() pauses thread execution but doesn't prevent new, default, events fr...
Status: RESOLVED INVALID
Alias: None
Product: WebKit
Classification: Unclassified
Component: UI Events (show other bugs)
Version: 528+ (Nightly build)
Hardware: Mac (Intel) OS X 10.6
: P2 Normal
Assignee: Nobody
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2012-07-13 14:42 PDT by ryan
Modified: 2012-07-15 00:20 PDT (History)
1 user (show)

See Also:


Attachments
Test case illustrating confirm() not blocking new event threads (465 bytes, text/html)
2012-07-13 14:42 PDT, ryan
no flags Details
Test case with keydown event binding and expectations included. (1.53 KB, text/html)
2012-07-14 13:55 PDT, ryan
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description ryan 2012-07-13 14:42:10 PDT
Created attachment 152338 [details]
Test case illustrating confirm() not blocking new event threads

Calling confirm() inside an event handler does not stop the dom from creating new, default events, while the confirm box is waiting to be dismissed. This makes it impossible to prevent those default events from triggering as the event context is lost when the thread is paused.

See attached test case.
Tested in Firefox 11 and WebKit r122567
Comment 1 Alexey Proskuryakov 2012-07-14 00:34:55 PDT
I'm not seeing any difference between Safari and Firefox on this test. What should I do to observe the bug?
Comment 2 ryan 2012-07-14 05:13:54 PDT
Of course, here are the steps for the attached test case. 

Steps to reproduce:
1. Open the test case file
2. Type the Enter/return key into the text field
3. Observe that a confirm dialog has been opened. Do not dismiss it. 

Expected:
The usual Form.submit event should not be triggered. 

Actual:
The Form.submit event is fired before the confirm() dialog box is closed. 
The test case calls console.error() when this happens. 


I hope that illustrates the difference easily enough.
Comment 3 Alexey Proskuryakov 2012-07-14 11:10:08 PDT
What I observe in Safari is that the submit event is dispatched before keyup, which doesn't appear to be related to suspending events during a confirm(). One can check this by replacing console.log() with an alert(), making relative timing obvious.
Comment 4 ryan 2012-07-14 13:24:14 PDT
Comment on attachment 152338 [details]
Test case illustrating confirm() not blocking new event threads

><!DOCTYPE html>
><html>
><body>
>	<form>
>		<input type="text" />
>	</form>
>
>	<script>
>		document.getElementsByTagName('INPUT')[0].addEventListener('keydown', function(evt) {
>			evt.preventDefault();
>			evt.stopPropagation();
>			confirm('until this is dismissed, no code should run');
>		});
>
>		document.getElementsByTagName('FORM')[0].addEventListener('submit', function(evt) {
>			console.error('submitted', evt);
>
>			evt.preventDefault();
>		});
>	</script>
></body>
></html>
Comment 5 ryan 2012-07-14 13:55:22 PDT
Created attachment 152432 [details]
Test case with keydown event binding and expectations included.
Comment 6 ryan 2012-07-14 14:01:15 PDT
I think that replacing the console.error with an alert makes the test invalid. It seems like the dialog stack would surpress the alert() until after the confirm is done, making things appear to work correctly. 

As you can see, i've attached what i hope is a better testcase, using console.group to try to illustrate the execution order a little clearer. 

Also keyup was the wrong event to bind earlier, it gets triggered too late. keydown is what i should've had the first time around.
Comment 7 Alexey Proskuryakov 2012-07-15 00:20:15 PDT
I cannot get results anywhere near what's described in the new test case.

I think that what you are actually seeing is that Web Inspector display is not updated while there is a confirm() on screen. In fact, this is roughly in line with the expectation of events not firing. It's not a good idea to test timing of events with a mix of console.log and alerts/confirms.

> It seems like the dialog stack would surpress the alert()

I don't know what dialog stack you are talking about. There is no re-ordering of alert and confirm dialogs.