Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1065)

Unified Diff: Source/core/frame/LocalDOMWindow.cpp

Issue 823263002: ScriptState used by EventListener::handleEvent() is wrong (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 5 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: Source/core/frame/LocalDOMWindow.cpp
diff --git a/Source/core/frame/LocalDOMWindow.cpp b/Source/core/frame/LocalDOMWindow.cpp
index 0eb295eb957c3f684cf3e37a0385ced090dc1e5f..6497b0e0be294306c55a9fb2215736cd9cc33a12 100644
--- a/Source/core/frame/LocalDOMWindow.cpp
+++ b/Source/core/frame/LocalDOMWindow.cpp
@@ -34,6 +34,7 @@
#include "bindings/core/v8/ScriptCallStackFactory.h"
#include "bindings/core/v8/ScriptController.h"
#include "bindings/core/v8/SerializedScriptValue.h"
+#include "bindings/core/v8/V8AbstractEventListener.h"
#include "bindings/core/v8/V8DOMActivityLogger.h"
#include "core/css/CSSComputedStyleDeclaration.h"
#include "core/css/CSSRuleList.h"
@@ -1570,8 +1571,9 @@ DOMWindowCSS* LocalDOMWindow::css() const
return m_css.get();
}
-bool LocalDOMWindow::addEventListener(const AtomicString& eventType, PassRefPtr<EventListener> listener, bool useCapture)
+bool LocalDOMWindow::addEventListener(const AtomicString& eventType, PassRefPtr<EventListener> prpListener, bool useCapture)
{
+ RefPtr<EventListener> listener = prpListener;
if (!EventTarget::addEventListener(eventType, listener, useCapture))
return false;
@@ -1588,6 +1590,18 @@ bool LocalDOMWindow::addEventListener(const AtomicString& eventType, PassRefPtr<
UseCounter::count(document(), UseCounter::DocumentUnloadRegistered);
addUnloadEventListener(this);
} else if (eventType == EventTypeNames::beforeunload) {
+ v8::Isolate* isolate = v8::Isolate::GetCurrent();
+ if (isolate->InContext()) {
+ // This is weird code to keep compatibility.
Jens Widell 2015/01/05 10:00:59 What compatibility is this achieving? Do you have
haraken 2015/01/05 10:04:46 before-unload-return-bad-value.html :) https://co
+ // When a beforeunload event is fired, a return value of the
+ // beforeunload event must be evaluated in a context that installed
+ // a beforeunload event listener. Thus we record the current
+ // ScriptState onto the event listener.
+ ScriptState* scriptState = ScriptState::current(v8::Isolate::GetCurrent());
+ ASSERT(scriptState);
+ static_cast<V8AbstractEventListener*>(listener.get())->setScriptStateForBeforeUnload(scriptState);
+ }
+
UseCounter::count(document(), UseCounter::DocumentBeforeUnloadRegistered);
if (allowsBeforeUnloadListeners(this)) {
// This is confusingly named. It doesn't actually add the listener. It just increments a count

Powered by Google App Engine
This is Rietveld 408576698