Bug 74961

Summary: window.prompt() returns empty string instead of null when Cancel is pressed
Product: WebKit Reporter: Paul Wieland <p>
Component: WebCore Misc.Assignee: Nobody <webkit-unassigned>
Status: NEW    
Severity: Normal CC: andersca, ap, darin, dbates, sam
Priority: P2 Keywords: InRadar
Version: 528+ (Nightly build)   
Hardware: Unspecified   
OS: Unspecified   

Paul Wieland
Reported 2011-12-20 15:02:49 PST
JavaScript window.prompt() should return null when the user clicks the cancel button. Instead an empty string is returned. This seems to be a newly introduced bug with Safari version 5.1. Sample: console.log(null != window.prompt('this is a test')); Pressing escape / clicking cancel should log false. Hitting enter / clicking OK should log true. Instead, window.prompt() returns true no matter which button is pressed.
Attachments
Daniel Bates
Comment 1 2012-01-10 15:58:46 PST
From briefly debugging, m_client.runJavaScriptPrompt() (*) in WebUIClient::runJavaScriptPrompt() returns the empty string when the Cancel button is pressed in the NSAlert dialog. Concatenating the multi-process call chains into one chain, the call chain leading up to WebUIClient::runJavaScriptPrompt() has the form: ... => DOMWindow::prompt() => Chrome::runJavaScriptPrompt() => WebChromeClient::runJavaScriptPrompt() => ... => WebUIClient::runJavaScriptPrompt() Ultimately WebUIClient::runJavaScriptPrompt() returns the empty string through this chain (in reverse order) to JavaScript. Therefore we return the empty string when the Cancel button is pressed in the JavaScript prompt() dialog. (*) <http://trac.webkit.org/browser/trunk/Source/WebKit2/UIProcess/WebUIClient.cpp?rev=102935#L142> For completeness, this bug doesn't occur in single-process mode in Mac Safari Version 5.1.2 (7534.52.7). That is, window.prompt() returns null when the Cancel button is pressed in the JavaScript prompt() dialog.
Alexey Proskuryakov
Comment 2 2012-01-11 11:10:53 PST
Note You need to log in before you can comment on or make changes to this bug.