This is not surprising to me at all.  The problem is even more complicated when you consider window.showModalDialog.<div><br></div><div>I recently changed Chromium to suppress WebKit&#39;s shared timer during calls to alert, confirm, prompt, and the beforeunload prompt.  That may be why you aren&#39;t seeing the problem with one-shot timers.  However, that&#39;s a hack since the same can&#39;t be done for showModalDialog.  It would be better if we extended the PageGroupLoadDeferrer (bad name btw) to suspend the right set of timers / callbacks properly.</div>
<div><br></div><div>-Darin</div><div><br><br><div class="gmail_quote">On Mon, Mar 8, 2010 at 11:21 AM, Drew Wilson <span dir="ltr">&lt;<a href="mailto:atwilson@google.com">atwilson@google.com</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
Hi all,<div><br></div><div>This weekend I spent some time trying to track down a regression caused by r55593. In particular:</div><div><br></div><div><a href="http://trac.webkit.org/changeset/55593/trunk/WebCore/dom/Document.cpp" target="_blank">http://trac.webkit.org/changeset/55593/trunk/WebCore/dom/Document.cpp</a></div>

<div><br></div><div>This was a change to Document.postTask() to always use callOnMainThread() (previously, calls to postTask() on the main thread were using one-shot timers).</div><div><br></div><div>We&#39;ve since reverted r55593, but I&#39;ve been playing around locally with that same change to Document.postTask(), and I noticed that it *appeared* that tasks posted via callOnMainThread() were still being executed even though the main thread was displaying a javascript alert. The end result is that if a worker thread was sending messages to the main thread via a message port, the event handlers for incoming messages would still be invoked (so we&#39;d run javascript even though the javascript execution context should be blocked on the alert()). In my test, I ended up trying to display nested alert() dialogs, which resulted in a failed assertion.</div>

<div><br></div><div>So, my question is: does it surprise anyone that tasks posted via callOnMainThread() are getting executed even though there&#39;s a modal dialog shown? And is there anything I should be doing in my task handler to make sure we aren&#39;t re-entering JS execution inappropriately in these cases? I&#39;m just concerned that the way we&#39;re posting tasks from worker threads to the main thread may cause reentrancy problems.</div>

<div><br></div><div>Here&#39;s the stack from my nested call to alert():</div><div><br></div><div><div>#0  0x03ff073d in WebCore::DOMTimer::suspend (this=0x15c8a5b0) at /Volumes/source/chrome.git/src/third_party/WebKit/WebCore/page/DOMTimer.cpp:181</div>

<div>#1  0x046b2945 in WebCore::ScriptExecutionContext::suspendActiveDOMObjects (this=0x81d8434) at /Volumes/source/chrome.git/src/third_party/WebKit/WebCore/dom/ScriptExecutionContext.cpp:206</div><div>#2  0x04538ae5 in WebCore::PageGroupLoadDeferrer::PageGroupLoadDeferrer (this=0xbfffc6bc, page=0xc97940, deferSelf=true) at /Volumes/source/chrome.git/src/third_party/WebKit/WebCore/page/PageGroupLoadDeferrer.cpp:47</div>

<div>#3  0x03e0d977 in WebCore::Chrome::runJavaScriptAlert (this=0xc8ddb0, frame=0x805a600, message=@0xbfffc790) at /Volumes/source/chrome.git/src/third_party/WebKit/WebCore/page/Chrome.cpp:264</div><div>#4  0x03ff6c2c in WebCore::DOMWindow::alert (this=0x147e23f0, message=@0xbfffc790) at /Volumes/source/chrome.git/src/third_party/WebKit/WebCore/page/DOMWindow.cpp:795</div>

<div>#5  0x04266617 in WebCore::jsDOMWindowPrototypeFunctionAlert (exec=0x14f0c1b0, thisValue={u = {asEncodedJSValue = -8455721472, asDouble = -nan(0xffffe07ffee00), asBits = {payload = 134213120, tag = -2}}}, args=@0xbfffc7bc) at /Volumes/source/chrome.git/src/third_party/WebKit/WebKitBuild/Debug/DerivedSources/WebCore/JSDOMWindow.cpp:8320</div>

<div>#6  0x00d8b166 in ?? ()</div><div>#7  0x0070bd6b in JSC::JITCode::execute (this=0x147a7690, registerFile=0x1473a7fc, callFrame=0x14f0c150, globalData=0x818e800, exception=0x818f60c) at JITCode.h:77</div><div>#8  0x006f542f in JSC::Interpreter::execute (this=0x1473a7f0, functionExecutable=0x147a7680, callFrame=0x81ed664, function=0x7fd5400, thisObj=0x7fd5200, args=@0xbfffca64, scopeChain=0x147a8920, exception=0x818f60c) at /Volumes/source/chrome.git/src/third_party/WebKit/JavaScriptCore/interpreter/Interpreter.cpp:687</div>

<div>#9  0x0074d767 in JSC::JSFunction::call (this=0x7fd5400, exec=0x81ed664, thisValue={u = {asEncodedJSValue = -8455892480, asDouble = -nan(0xffffe07fd5200), asBits = {payload = 134042112, tag = -2}}}, args=@0xbfffca64) at /Volumes/source/chrome.git/src/third_party/WebKit/JavaScriptCore/runtime/JSFunction.cpp:122</div>

<div>#10 0x0069d481 in JSC::call (exec=0x81ed664, functionObject={u = {asEncodedJSValue = -8455891968, asDouble = -nan(0xffffe07fd5400), asBits = {payload = 134042624, tag = -2}}}, callType=JSC::CallTypeJS, callData=@0xbfffca34, thisValue={u = {asEncodedJSValue = -8455892480, asDouble = -nan(0xffffe07fd5200), asBits = {payload = 134042112, tag = -2}}}, args=@0xbfffca64) at /Volumes/source/chrome.git/src/third_party/WebKit/JavaScriptCore/runtime/CallData.cpp:39</div>

<div>#11 0x0429f5bb in WebCore::JSEventListener::handleEvent (this=0x15c31ef0, scriptExecutionContext=0x81d8434, event=0xc34d40) at /Volumes/source/chrome.git/src/third_party/WebKit/WebCore/bindings/js/JSEventListener.cpp:115</div>

<div>#12 0x04037da0 in WebCore::EventTarget::fireEventListeners (this=0x15c9c400, event=0xc34d40) at /Volumes/source/chrome.git/src/third_party/WebKit/WebCore/dom/EventTarget.cpp:297</div><div>#13 0x04037e88 in WebCore::EventTarget::dispatchEvent (this=0x15c9c400, event=@0xbfffcbac) at /Volumes/source/chrome.git/src/third_party/WebKit/WebCore/dom/EventTarget.cpp:262</div>

<div>#14 0x0403769a in WebCore::EventTarget::dispatchEvent (this=0x15c9c400, event=@0xbfffcc2c, ec=@0xbfffcbfc) at /Volumes/source/chrome.git/src/third_party/WebKit/WebCore/dom/EventTarget.cpp:254</div><div>#15 0x044eeaa8 in WebCore::MessagePort::dispatchMessages (this=0x15c9c400) at /Volumes/source/chrome.git/src/third_party/WebKit/WebCore/dom/MessagePort.cpp:177</div>

<div>#16 0x046b3173 in WebCore::ScriptExecutionContext::dispatchMessagePortEvents (this=0x81d8434) at /Volumes/source/chrome.git/src/third_party/WebKit/WebCore/dom/ScriptExecutionContext.cpp:162</div><div>#17 0x046b7a63 in WebCore::ProcessMessagesSoonTask::performTask (this=0x147d36f0, context=0x81d8434) at /Volumes/source/chrome.git/src/third_party/WebKit/WebCore/dom/ScriptExecutionContext.cpp:56</div>

<div>#18 0x03f4781a in WebCore::performTask (ctx=0x15d12cd0) at /Volumes/source/chrome.git/src/third_party/WebKit/WebCore/dom/Document.cpp:4726</div><div>#19 0x00776c1e in WTF::dispatchFunctionsFromMainThread () at /Volumes/source/chrome.git/src/third_party/WebKit/JavaScriptCore/wtf/MainThread.cpp:96</div>

<div>#20 0x0077766f in -[WTFMainThreadCaller call] (self=0xc1b2e0, _cmd=0x848956) at /Volumes/source/chrome.git/src/third_party/WebKit/JavaScriptCore/wtf/mac/MainThreadMac.mm:44</div><div>#21 0x904549ac in __NSThreadPerformPerform ()</div>

<div>#22 0x973903c5 in CFRunLoopRunSpecific ()</div><div>#23 0x97390aa8 in CFRunLoopRunInMode ()</div><div>#24 0x90c982ac in RunCurrentEventLoopInMode ()</div><div>#25 0x90c97ffe in ReceiveNextEventCommon ()</div><div>#26 0x90c97f39 in BlockUntilNextEventMatchingListInMode ()</div>

<div>#27 0x960b76d5 in _DPSNextEvent ()</div><div>#28 0x960b6f88 in -[NSApplication nextEventMatchingMask:untilDate:inMode:dequeue:] ()</div><div>#29 0x0000c045 in ?? ()</div><div>#30 0x962f438d in -[NSApplication _realDoModalLoop:peek:] ()</div>

<div>#31 0x962eeacb in -[NSApplication runModalForWindow:] ()</div><div>#32 0x00113e5d in ?? ()</div><div>#33 0x00113cf4 in ?? ()</div><div>#34 0x000c7118 in ?? ()</div><div>#35 0x000c7044 in ?? ()</div><div>#36 0x00303030 in CallDelegate (self=0xc93db0, delegate=0xc93db0, selector=0x3d0268, object1=0x15c15868, object2=0xc99770) at /Volumes/source/chrome.git/src/third_party/WebKit/WebKit/mac/WebView/WebDelegateImplementationCaching.mm:131</div>

<div>#37 0x003030b9 in CallUIDelegate (self=0xc93db0, selector=0x3d0268, object1=0x15c15868, object2=0xc99770) at /Volumes/source/chrome.git/src/third_party/WebKit/WebKit/mac/WebView/WebDelegateImplementationCaching.mm:440</div>

<div>#38 0x002f6e60 in WebChromeClient::runJavaScriptAlert (this=0xc59020, frame=0x805a600, message=@0xbfffdfbc) at /Volumes/source/chrome.git/src/third_party/WebKit/WebKit/mac/WebCoreSupport/WebChromeClient.mm:368</div>
<div>
#39 0x03e0d9fb in WebCore::Chrome::runJavaScriptAlert (this=0xc8ddb0, frame=0x805a600, message=@0xbfffe040) at /Volumes/source/chrome.git/src/third_party/WebKit/WebCore/page/Chrome.cpp:267</div><div>#40 0x03ff6c2c in WebCore::DOMWindow::alert (this=0x147e23f0, message=@0xbfffe040) at /Volumes/source/chrome.git/src/third_party/WebKit/WebCore/page/DOMWindow.cpp:795</div>

<div>#41 0x04266617 in WebCore::jsDOMWindowPrototypeFunctionAlert (exec=0x14f0c0a8, thisValue={u = {asEncodedJSValue = -8455721472, asDouble = -nan(0xffffe07ffee00), asBits = {payload = 134213120, tag = -2}}}, args=@0xbfffe06c) at /Volumes/source/chrome.git/src/third_party/WebKit/WebKitBuild/Debug/DerivedSources/WebCore/JSDOMWindow.cpp:8320</div>

<div>#42 0x00d8b166 in ?? ()</div><div>#43 0x0070bd6b in JSC::JITCode::execute (this=0x147067f0, registerFile=0x1473a7fc, callFrame=0x14f0c050, globalData=0x818e800, exception=0x818f60c) at JITCode.h:77</div><div>#44 0x006f542f in JSC::Interpreter::execute (this=0x1473a7f0, functionExecutable=0x147067e0, callFrame=0x81ed664, function=0x7fc2440, thisObj=0x7fc22c0, args=@0xbfffe314, scopeChain=0x147bc080, exception=0x818f60c) at /Volumes/source/chrome.git/src/third_party/WebKit/JavaScriptCore/interpreter/Interpreter.cpp:687</div>

<div>#45 0x0074d767 in JSC::JSFunction::call (this=0x7fc2440, exec=0x81ed664, thisValue={u = {asEncodedJSValue = -8455970112, asDouble = -nan(0xffffe07fc22c0), asBits = {payload = 133964480, tag = -2}}}, args=@0xbfffe314) at /Volumes/source/chrome.git/src/third_party/WebKit/JavaScriptCore/runtime/JSFunction.cpp:122</div>

<div>#46 0x0069d481 in JSC::call (exec=0x81ed664, functionObject={u = {asEncodedJSValue = -8455969728, asDouble = -nan(0xffffe07fc2440), asBits = {payload = 133964864, tag = -2}}}, callType=JSC::CallTypeJS, callData=@0xbfffe2e4, thisValue={u = {asEncodedJSValue = -8455970112, asDouble = -nan(0xffffe07fc22c0), asBits = {payload = 133964480, tag = -2}}}, args=@0xbfffe314) at /Volumes/source/chrome.git/src/third_party/WebKit/JavaScriptCore/runtime/CallData.cpp:39</div>

<div>#47 0x0429f5bb in WebCore::JSEventListener::handleEvent (this=0xcb2aa0, scriptExecutionContext=0x81d8434, event=0x15d08b90) at /Volumes/source/chrome.git/src/third_party/WebKit/WebCore/bindings/js/JSEventListener.cpp:115</div>

<div>#48 0x04037da0 in WebCore::EventTarget::fireEventListeners (this=0x1478c1e4, event=0x15d08b90) at /Volumes/source/chrome.git/src/third_party/WebKit/WebCore/dom/EventTarget.cpp:297</div><div>#49 0x04037e88 in WebCore::EventTarget::dispatchEvent (this=0x1478c1e4, event=@0xbfffe470) at /Volumes/source/chrome.git/src/third_party/WebKit/WebCore/dom/EventTarget.cpp:262</div>

<div>#50 0x04878a40 in WebCore::MessageWorkerTask::performTask (this=0x1470bb20, scriptContext=0x81d8434) at /Volumes/source/chrome.git/src/third_party/WebKit/WebCore/workers/WorkerMessagingProxy.cpp:97</div><div>#51 0x03f4781a in WebCore::performTask (ctx=0x15d12cb0) at /Volumes/source/chrome.git/src/third_party/WebKit/WebCore/dom/Document.cpp:4726</div>

<div>#52 0x00776c1e in WTF::dispatchFunctionsFromMainThread () at /Volumes/source/chrome.git/src/third_party/WebKit/JavaScriptCore/wtf/MainThread.cpp:96</div><div>#53 0x0077766f in -[WTFMainThreadCaller call] (self=0xc1b2e0, _cmd=0x848956) at /Volumes/source/chrome.git/src/third_party/WebKit/JavaScriptCore/wtf/mac/MainThreadMac.mm:44</div>

<div>#54 0x904549ac in __NSThreadPerformPerform ()</div><div>#55 0x973903c5 in CFRunLoopRunSpecific ()</div><div>#56 0x97390aa8 in CFRunLoopRunInMode ()</div><div>#57 0x90c982ac in RunCurrentEventLoopInMode ()</div><div>
#58 0x90c980c5 in ReceiveNextEventCommon ()</div>
<div>#59 0x90c97f39 in BlockUntilNextEventMatchingListInMode ()</div><div>#60 0x960b76d5 in _DPSNextEvent ()</div><div>#61 0x960b6f88 in -[NSApplication nextEventMatchingMask:untilDate:inMode:dequeue:] ()</div><div>#62 0x0000c045 in ?? ()</div>

<div>#63 0x960aff9f in -[NSApplication run] ()</div><div>#64 0x9607d1d8 in NSApplicationMain ()</div><div>#65 0x000029d2 in ?? ()</div><div>Current language:  auto; currently c++</div></div>
<br>_______________________________________________<br>
webkit-dev mailing list<br>
<a href="mailto:webkit-dev@lists.webkit.org">webkit-dev@lists.webkit.org</a><br>
<a href="http://lists.webkit.org/mailman/listinfo.cgi/webkit-dev" target="_blank">http://lists.webkit.org/mailman/listinfo.cgi/webkit-dev</a><br>
<br></blockquote></div><br></div>