From bdf287fe15293515a5beb97b43722136b2ea9e5a Mon Sep 17 00:00:00 2001 From: "jianli@chromium.org" Date: Tue, 28 Jul 2009 01:11:18 +0000 Subject: [PATCH] 2009-07-27 Jian Li Reviewed by David Levin. [V8] Implement EventListener::reportError for V8 event listeners in worker context. https://bugs.webkit.org/show_bug.cgi?id=27731 * bindings/v8/V8WorkerContextEventListener.cpp: (WebCore::V8WorkerContextEventListener::reportError): * bindings/v8/V8WorkerContextEventListener.h: git-svn-id: https://svn.webkit.org/repository/webkit/trunk@46448 268f45cc-cd09-0410-ab3c-d52691b4dbfc --- WebCore/ChangeLog | 11 +++++ .../bindings/v8/V8WorkerContextEventListener.cpp | 47 ++++++++++++++++++++++ WebCore/bindings/v8/V8WorkerContextEventListener.h | 1 + 3 files changed, 59 insertions(+) diff --git a/WebCore/ChangeLog b/WebCore/ChangeLog index 46cc3bf..9c8ace1 100644 --- a/WebCore/ChangeLog +++ b/WebCore/ChangeLog @@ -1,3 +1,14 @@ +2009-07-27 Jian Li + + Reviewed by David Levin. + + [V8] Implement EventListener::reportError for V8 event listeners in worker context. + https://bugs.webkit.org/show_bug.cgi?id=27731 + + * bindings/v8/V8WorkerContextEventListener.cpp: + (WebCore::V8WorkerContextEventListener::reportError): + * bindings/v8/V8WorkerContextEventListener.h: + 2009-07-27 Stephen White Reviewed by Eric Seidel and David Levin. diff --git a/WebCore/bindings/v8/V8WorkerContextEventListener.cpp b/WebCore/bindings/v8/V8WorkerContextEventListener.cpp index 9bb48fb..9ae5cd8 100644 --- a/WebCore/bindings/v8/V8WorkerContextEventListener.cpp +++ b/WebCore/bindings/v8/V8WorkerContextEventListener.cpp @@ -35,6 +35,7 @@ #include "V8WorkerContextEventListener.h" #include "Event.h" +#include "V8Binding.h" #include "WorkerContextExecutionProxy.h" namespace WebCore { @@ -77,6 +78,52 @@ void V8WorkerContextEventListener::handleEvent(Event* event, bool isWindowEvent) invokeEventHandler(context, event, jsEvent, isWindowEvent); } +bool V8WorkerContextEventListener::reportError(const String& message, const String& url, int lineNumber) +{ + // Is the EventListener disconnected? + if (disconnected()) + return false; + + // The callback function can clear the event listener and destroy 'this' object. Keep a local reference to it. + RefPtr protect(this); + + v8::HandleScope handleScope; + + v8::Handle context = m_proxy->GetContext(); + if (context.IsEmpty()) + return false; + + // Enter the V8 context in which to perform the event handling. + v8::Context::Scope scope(context); + + v8::Local returnValue; + { + // Catch exceptions thrown in calling the function so they do not propagate to javascript code that caused the event to fire. + v8::TryCatch tryCatch; + tryCatch.SetVerbose(true); + + // Call the function. + if (!m_listener.IsEmpty() && m_listener->IsFunction()) { + v8::Local callFunction = v8::Local::New(v8::Persistent::Cast(m_listener)); + v8::Local thisValue = v8::Context::GetCurrent()->Global(); + + v8::Handle parameters[3] = { v8String(message), v8String(url), v8::Integer::New(lineNumber) }; + returnValue = callFunction->Call(thisValue, 3, parameters); + } + + // If an error occurs while handling the script error, it should be bubbled up. + if (tryCatch.HasCaught()) { + tryCatch.Reset(); + return false; + } + } + + // If the function returns false, then the error is handled. Otherwise, the error is not handled. + bool errorHandled = returnValue->IsBoolean() && !returnValue->BooleanValue(); + + return errorHandled; +} + v8::Local V8WorkerContextEventListener::callListenerFunction(v8::Handle jsEvent, Event* event, bool isWindowEvent) { v8::Local handlerFunction = getListenerFunction(); diff --git a/WebCore/bindings/v8/V8WorkerContextEventListener.h b/WebCore/bindings/v8/V8WorkerContextEventListener.h index 8e56a73..c901c51 100644 --- a/WebCore/bindings/v8/V8WorkerContextEventListener.h +++ b/WebCore/bindings/v8/V8WorkerContextEventListener.h @@ -52,6 +52,7 @@ namespace WebCore { virtual ~V8WorkerContextEventListener(); virtual void handleEvent(Event*, bool isWindowEvent); + virtual bool reportError(const String& message, const String& url, int lineNumber); virtual bool disconnected() const { return !m_proxy; } WorkerContextExecutionProxy* proxy() const { return m_proxy; } -- 1.8.3.1