From 60766ba5a6bea79efaac17baacf444e86e4c7abc Mon Sep 17 00:00:00 2001 From: "jianli@chromium.org" Date: Tue, 22 Sep 2009 00:07:49 +0000 Subject: [PATCH] [V8] Run-time exception in onmessage handler is not forwarded to the worker object. https://bugs.webkit.org/show_bug.cgi?id=28980 Reviewed by David Levin. The previous fix was partially reverted due to a reliability build break in chromium. The break happens when an exception is thrown without setting a message. We need to check for this scenario and handle it. Tested by worker-close.html. * bindings/v8/V8AbstractEventListener.cpp: (WebCore::V8AbstractEventListener::invokeEventHandler): * bindings/v8/V8Utilities.cpp: (WebCore::reportException): git-svn-id: https://svn.webkit.org/repository/webkit/trunk@48610 268f45cc-cd09-0410-ab3c-d52691b4dbfc --- WebCore/ChangeLog | 19 +++++++++++++++++++ WebCore/bindings/v8/V8AbstractEventListener.cpp | 9 ++++++++- WebCore/bindings/v8/V8Utilities.cpp | 15 ++++++++++++++- 3 files changed, 41 insertions(+), 2 deletions(-) diff --git a/WebCore/ChangeLog b/WebCore/ChangeLog index 8773a8d..3fdd939 100644 --- a/WebCore/ChangeLog +++ b/WebCore/ChangeLog @@ -1,3 +1,22 @@ +2009-09-21 Jian Li + + Reviewed by David Levin. + + [V8] Run-time exception in onmessage handler is not forwarded to the + worker object. + https://bugs.webkit.org/show_bug.cgi?id=28980 + + The previous fix was partially reverted due to a reliability build break + in chromium. The break happens when an exception is thrown without + setting a message. We need to check for this scenario and handle it. + + Tested by worker-close.html. + + * bindings/v8/V8AbstractEventListener.cpp: + (WebCore::V8AbstractEventListener::invokeEventHandler): + * bindings/v8/V8Utilities.cpp: + (WebCore::reportException): + 2009-09-21 Greg Bolsinga Reviewed by Simon Fraser & Sam Weinig. diff --git a/WebCore/bindings/v8/V8AbstractEventListener.cpp b/WebCore/bindings/v8/V8AbstractEventListener.cpp index 588ea6c..c0efea5 100644 --- a/WebCore/bindings/v8/V8AbstractEventListener.cpp +++ b/WebCore/bindings/v8/V8AbstractEventListener.cpp @@ -82,10 +82,17 @@ void V8AbstractEventListener::invokeEventHandler(v8::Handle v8Conte tryCatch.Reset(); // Call the event handler. + tryCatch.SetVerbose(false); // We do not want to report the exception to the inspector console. returnValue = callListenerFunction(jsEvent, event, isWindowEvent); - tryCatch.Reset(); + + // If an error occurs while handling the event, it should be reported. + if (tryCatch.HasCaught()) { + reportException(0, tryCatch); + tryCatch.Reset(); + } // Restore the old event. This must be done for all exit paths through this method. + tryCatch.SetVerbose(true); if (savedEvent.IsEmpty()) v8Context->Global()->SetHiddenValue(eventSymbol, v8::Undefined()); else diff --git a/WebCore/bindings/v8/V8Utilities.cpp b/WebCore/bindings/v8/V8Utilities.cpp index a8aa924..f8f7d7c 100644 --- a/WebCore/bindings/v8/V8Utilities.cpp +++ b/WebCore/bindings/v8/V8Utilities.cpp @@ -129,8 +129,21 @@ ScriptExecutionContext* getScriptExecutionContext(ScriptState* scriptState) void reportException(ScriptState* scriptState, v8::TryCatch& exceptionCatcher) { + String errorMessage; + int lineNumber = 0; + String sourceURL; + + // There can be a situation that an exception is thrown without setting a message. v8::Local message = exceptionCatcher.Message(); - getScriptExecutionContext(scriptState)->reportException(toWebCoreString(message->Get()), message->GetLineNumber(), toWebCoreString(message->GetScriptResourceName())); + if (message.IsEmpty()) + errorMessage = toWebCoreString(exceptionCatcher.Exception()->ToString()); + else { + errorMessage = toWebCoreString(message->Get()); + lineNumber = message->GetLineNumber(); + sourceURL = toWebCoreString(message->GetScriptResourceName()); + } + + getScriptExecutionContext(scriptState)->reportException(errorMessage, lineNumber, sourceURL); exceptionCatcher.Reset(); } -- 1.8.3.1