Diff
Modified: trunk/Source/WebCore/ChangeLog (136549 => 136550)
--- trunk/Source/WebCore/ChangeLog 2012-12-04 20:37:28 UTC (rev 136549)
+++ trunk/Source/WebCore/ChangeLog 2012-12-04 20:47:30 UTC (rev 136550)
@@ -1,3 +1,30 @@
+2012-12-04 Adam Barth <[email protected]>
+
+ [V8] EventTarget shouldn't be a special snowflake
+ https://bugs.webkit.org/show_bug.cgi?id=104018
+
+ Reviewed by Eric Seidel.
+
+ Previously we special-cased the toV8 operation for event targets.
+ There's no need for that. We can use IDL attribute to handle
+ EventTarget using the same general-purpose code that we use for other
+ interfaces.
+
+ * WebCore.gypi:
+ * bindings/scripts/CodeGeneratorV8.pm:
+ (NativeToJSValue):
+ * bindings/v8/V8AbstractEventListener.cpp:
+ (WebCore::V8AbstractEventListener::getReceiverObject):
+ * bindings/v8/V8DOMWrapper.cpp:
+ * bindings/v8/V8DOMWrapper.h:
+ (V8DOMWrapper):
+ * bindings/v8/V8WorkerContextEventListener.cpp:
+ (WebCore::V8WorkerContextEventListener::getReceiverObject):
+ * bindings/v8/custom/V8EventTargetCustom.cpp: Added.
+ (WebCore):
+ (WebCore::toV8):
+ * dom/EventTarget.idl:
+
2012-12-04 Florin Malita <[email protected]>
Stale SVGUseElement reference in CachedResource::checkNotify()
Modified: trunk/Source/WebCore/WebCore.gypi (136549 => 136550)
--- trunk/Source/WebCore/WebCore.gypi 2012-12-04 20:37:28 UTC (rev 136549)
+++ trunk/Source/WebCore/WebCore.gypi 2012-12-04 20:47:30 UTC (rev 136550)
@@ -2377,6 +2377,7 @@
'bindings/v8/custom/V8EntryCustom.cpp',
'bindings/v8/custom/V8EntrySyncCustom.cpp',
'bindings/v8/custom/V8EventCustom.cpp',
+ 'bindings/v8/custom/V8EventTargetCustom.cpp',
'bindings/v8/custom/V8FileReaderCustom.cpp',
'bindings/v8/custom/V8GeolocationCustom.cpp',
'bindings/v8/custom/V8HTMLAllCollectionCustom.cpp',
Modified: trunk/Source/WebCore/bindings/scripts/CodeGeneratorV8.pm (136549 => 136550)
--- trunk/Source/WebCore/bindings/scripts/CodeGeneratorV8.pm 2012-12-04 20:37:28 UTC (rev 136549)
+++ trunk/Source/WebCore/bindings/scripts/CodeGeneratorV8.pm 2012-12-04 20:47:30 UTC (rev 136550)
@@ -4108,14 +4108,10 @@
AddIncludesForType($type);
- if (IsDOMNodeType($type)) {
+ if (IsDOMNodeType($type) || $type eq "EventTarget") {
return "toV8($value$getCreationContextArg$getIsolateArg)";
}
- if ($type eq "EventTarget") {
- return "V8DOMWrapper::convertEventTargetToV8Object($value$getCreationContextArg$getIsolateArg)";
- }
-
if ($type eq "EventListener") {
AddToImplIncludes("V8AbstractEventListener.h");
return "${value} ? v8::Handle<v8::Value>(static_cast<V8AbstractEventListener*>(${value})->getListenerObject(imp->scriptExecutionContext())) : v8::Handle<v8::Value>(" . ($getIsolate ? "v8Null($getIsolate)" : "v8::Null()") . ")";
Modified: trunk/Source/WebCore/bindings/v8/V8AbstractEventListener.cpp (136549 => 136550)
--- trunk/Source/WebCore/bindings/v8/V8AbstractEventListener.cpp 2012-12-04 20:37:28 UTC (rev 136549)
+++ trunk/Source/WebCore/bindings/v8/V8AbstractEventListener.cpp 2012-12-04 20:47:30 UTC (rev 136550)
@@ -40,6 +40,7 @@
#include "V8Binding.h"
#include "V8Event.h"
#include "V8EventListenerList.h"
+#include "V8EventTarget.h"
#include "V8HiddenPropertyName.h"
#include "V8Utilities.h"
#include "WorkerContext.h"
@@ -187,7 +188,7 @@
return v8::Local<v8::Object>::New(m_listener.get());
EventTarget* target = event->currentTarget();
- v8::Handle<v8::Value> value = V8DOMWrapper::convertEventTargetToV8Object(target);
+ v8::Handle<v8::Value> value = toV8(target);
if (value.IsEmpty())
return v8::Local<v8::Object>();
return v8::Local<v8::Object>::New(v8::Handle<v8::Object>::Cast(value));
Modified: trunk/Source/WebCore/bindings/v8/V8DOMWrapper.cpp (136549 => 136550)
--- trunk/Source/WebCore/bindings/v8/V8DOMWrapper.cpp 2012-12-04 20:37:28 UTC (rev 136549)
+++ trunk/Source/WebCore/bindings/v8/V8DOMWrapper.cpp 2012-12-04 20:47:30 UTC (rev 136550)
@@ -33,14 +33,13 @@
#include <wtf/ArrayBufferView.h>
#include "DocumentLoader.h"
-#include "EventTargetHeaders.h"
-#include "EventTargetInterfaces.h"
#include "Frame.h"
#include "FrameLoaderClient.h"
#include "StylePropertySet.h"
#include "V8AbstractEventListener.h"
#include "V8Binding.h"
#include "V8Collection.h"
+#include "V8DOMWindow.h"
#include "V8EventListener.h"
#include "V8EventListenerList.h"
#include "V8HTMLCollection.h"
@@ -176,23 +175,6 @@
return typeInfo == type;
}
-#define TRY_TO_WRAP_WITH_INTERFACE(interfaceName) \
- if (eventNames().interfaceFor##interfaceName == desiredInterface) \
- return toV8(static_cast<interfaceName*>(target), creationContext, isolate);
-
-// A JS object of type EventTarget is limited to a small number of possible classes.
-v8::Handle<v8::Value> V8DOMWrapper::convertEventTargetToV8Object(EventTarget* target, v8::Handle<v8::Object> creationContext, v8::Isolate* isolate)
-{
- if (!target)
- return v8NullWithCheck(isolate);
-
- AtomicString desiredInterface = target->interfaceName();
- DOM_EVENT_TARGET_INTERFACES_FOR_EACH(TRY_TO_WRAP_WITH_INTERFACE)
-
- ASSERT_NOT_REACHED();
- return v8Undefined();
-}
-
PassRefPtr<EventListener> V8DOMWrapper::getEventListener(v8::Local<v8::Value> value, bool isAttribute, ListenerLookupType lookup)
{
v8::Handle<v8::Context> context = v8::Context::GetCurrent();
Modified: trunk/Source/WebCore/bindings/v8/V8DOMWrapper.h (136549 => 136550)
--- trunk/Source/WebCore/bindings/v8/V8DOMWrapper.h 2012-12-04 20:37:28 UTC (rev 136549)
+++ trunk/Source/WebCore/bindings/v8/V8DOMWrapper.h 2012-12-04 20:47:30 UTC (rev 136550)
@@ -90,13 +90,6 @@
static WrapperTypeInfo* domWrapperType(v8::Handle<v8::Object>);
- static v8::Handle<v8::Value> convertEventTargetToV8Object(PassRefPtr<EventTarget> eventTarget, v8::Handle<v8::Object> creationContext = v8::Handle<v8::Object>(), v8::Isolate* isolate = 0)
- {
- return convertEventTargetToV8Object(eventTarget.get(), creationContext, isolate);
- }
-
- static v8::Handle<v8::Value> convertEventTargetToV8Object(EventTarget*, v8::Handle<v8::Object> creationContext = v8::Handle<v8::Object>(), v8::Isolate* = 0);
-
static PassRefPtr<EventListener> getEventListener(v8::Local<v8::Value> value, bool isAttribute, ListenerLookupType lookup);
// Wrap JS node filter in C++.
Modified: trunk/Source/WebCore/bindings/v8/V8WorkerContextEventListener.cpp (136549 => 136550)
--- trunk/Source/WebCore/bindings/v8/V8WorkerContextEventListener.cpp 2012-12-04 20:37:28 UTC (rev 136549)
+++ trunk/Source/WebCore/bindings/v8/V8WorkerContextEventListener.cpp 2012-12-04 20:47:30 UTC (rev 136550)
@@ -38,6 +38,7 @@
#include "V8Binding.h"
#include "V8DOMWrapper.h"
#include "V8Event.h"
+#include "V8EventTarget.h"
#include "V8GCController.h"
#include "V8RecursionScope.h"
#include "WorkerContext.h"
@@ -117,7 +118,7 @@
return listener;
EventTarget* target = event->currentTarget();
- v8::Handle<v8::Value> value = V8DOMWrapper::convertEventTargetToV8Object(target);
+ v8::Handle<v8::Value> value = toV8(target);
if (value.IsEmpty())
return v8::Local<v8::Object>();
return v8::Local<v8::Object>::New(v8::Handle<v8::Object>::Cast(value));
Added: trunk/Source/WebCore/bindings/v8/custom/V8EventTargetCustom.cpp (0 => 136550)
--- trunk/Source/WebCore/bindings/v8/custom/V8EventTargetCustom.cpp (rev 0)
+++ trunk/Source/WebCore/bindings/v8/custom/V8EventTargetCustom.cpp 2012-12-04 20:47:30 UTC (rev 136550)
@@ -0,0 +1,58 @@
+/*
+ * Copyright (C) 2012 Google Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following disclaimer
+ * in the documentation and/or other materials provided with the
+ * distribution.
+ * * Neither the name of Google Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "config.h"
+#include "EventTarget.h"
+
+#include "EventTargetHeaders.h"
+#include "EventTargetInterfaces.h"
+#include "V8EventTarget.h"
+
+namespace WebCore {
+
+#define TRY_TO_WRAP_WITH_INTERFACE(interfaceName) \
+ if (eventNames().interfaceFor##interfaceName == desiredInterface) \
+ return toV8(static_cast<interfaceName*>(impl), creationContext, isolate);
+
+v8::Handle<v8::Value> toV8(EventTarget* impl, v8::Handle<v8::Object> creationContext, v8::Isolate* isolate)
+{
+ if (!impl)
+ return v8NullWithCheck(isolate);
+
+ AtomicString desiredInterface = impl->interfaceName();
+ DOM_EVENT_TARGET_INTERFACES_FOR_EACH(TRY_TO_WRAP_WITH_INTERFACE)
+
+ ASSERT_NOT_REACHED();
+ return v8Undefined();
+}
+
+#undef TRY_TO_WRAP_WITH_INTERFACE
+
+} // namespace WebCore
Modified: trunk/Source/WebCore/dom/EventTarget.idl (136549 => 136550)
--- trunk/Source/WebCore/dom/EventTarget.idl 2012-12-04 20:37:28 UTC (rev 136549)
+++ trunk/Source/WebCore/dom/EventTarget.idl 2012-12-04 20:47:30 UTC (rev 136550)
@@ -23,8 +23,9 @@
ObjCProtocol,
CPPPureInterface,
OmitConstructor,
- JSCustomToJSObject,
- JSCustomToNativeObject
+ CustomToJSObject,
+ JSCustomToNativeObject,
+ V8NoWrapperCache
] interface EventTarget {
[ObjCLegacyUnnamedParameters] void addEventListener(in DOMString type,
in EventListener listener,