[v8] Stop using an IDL to generate V8MutationCallback
authoradamk@chromium.org <adamk@chromium.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 4 Jan 2013 21:03:20 +0000 (21:03 +0000)
committeradamk@chromium.org <adamk@chromium.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 4 Jan 2013 21:03:20 +0000 (21:03 +0000)
https://bugs.webkit.org/show_bug.cgi?id=106122

Reviewed by Adam Barth.

The only real code in the generated V8MutationCallback.{h,cpp} files
were specifically written in CodeGeneratorV8 for its use. By instead
Using completely-hand-written versions of these files, the
CodeGenerator can be simplified (as can all generated Callbacks).
All the actually shared code is still shared via subclassing of
ActiveDOMCallback.

This introduces additional flexibility into the implementation of
MutationCallback which will be used when fixing the MutationObserver
memory leak (http://webkit.org/b/90661) for JSC.

No changes to JSC for now, just a FIXME in the IDL file.

No new tests, refactoringonly.

* WebCore.gypi:
* bindings/scripts/CodeGeneratorV8.pm:
(GenerateCallbackHeader):
(GenerateCallbackImplementation):
* bindings/scripts/test/V8/V8TestCallback.cpp:
(WebCore::V8TestCallback::V8TestCallback):
* bindings/scripts/test/V8/V8TestCallback.h:
(WebCore::V8TestCallback::create):
(V8TestCallback):
* bindings/v8/V8MutationCallback.cpp: Renamed from Source/WebCore/bindings/v8/custom/V8MutationCallbackCustom.cpp.
(WebCore::V8MutationCallback::V8MutationCallback):
(WebCore::V8MutationCallback::handleEvent):
* bindings/v8/V8MutationCallback.h: Added.
(V8MutationCallback):
(WebCore::V8MutationCallback::create):
(WebCore::V8MutationCallback::weakCallback):
* dom/MutationCallback.idl:

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@138841 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Source/WebCore/ChangeLog
Source/WebCore/WebCore.gypi
Source/WebCore/bindings/scripts/CodeGeneratorV8.pm
Source/WebCore/bindings/scripts/test/V8/V8TestCallback.cpp
Source/WebCore/bindings/scripts/test/V8/V8TestCallback.h
Source/WebCore/bindings/v8/V8MutationCallback.cpp [moved from Source/WebCore/bindings/v8/custom/V8MutationCallbackCustom.cpp with 50% similarity]
Source/WebCore/bindings/v8/V8MutationCallback.h [new file with mode: 0644]
Source/WebCore/dom/MutationCallback.idl

index 4fc6bc4..8c568c4 100644 (file)
@@ -1,3 +1,43 @@
+2013-01-04  Adam Klein  <adamk@chromium.org>
+
+        [v8] Stop using an IDL to generate V8MutationCallback
+        https://bugs.webkit.org/show_bug.cgi?id=106122
+
+        Reviewed by Adam Barth.
+
+        The only real code in the generated V8MutationCallback.{h,cpp} files
+        were specifically written in CodeGeneratorV8 for its use. By instead
+        Using completely-hand-written versions of these files, the
+        CodeGenerator can be simplified (as can all generated Callbacks).
+        All the actually shared code is still shared via subclassing of
+        ActiveDOMCallback.
+
+        This introduces additional flexibility into the implementation of
+        MutationCallback which will be used when fixing the MutationObserver
+        memory leak (http://webkit.org/b/90661) for JSC.
+
+        No changes to JSC for now, just a FIXME in the IDL file.
+
+        No new tests, refactoringonly.
+
+        * WebCore.gypi:
+        * bindings/scripts/CodeGeneratorV8.pm:
+        (GenerateCallbackHeader):
+        (GenerateCallbackImplementation):
+        * bindings/scripts/test/V8/V8TestCallback.cpp:
+        (WebCore::V8TestCallback::V8TestCallback):
+        * bindings/scripts/test/V8/V8TestCallback.h:
+        (WebCore::V8TestCallback::create):
+        (V8TestCallback):
+        * bindings/v8/V8MutationCallback.cpp: Renamed from Source/WebCore/bindings/v8/custom/V8MutationCallbackCustom.cpp.
+        (WebCore::V8MutationCallback::V8MutationCallback):
+        (WebCore::V8MutationCallback::handleEvent):
+        * bindings/v8/V8MutationCallback.h: Added.
+        (V8MutationCallback):
+        (WebCore::V8MutationCallback::create):
+        (WebCore::V8MutationCallback::weakCallback):
+        * dom/MutationCallback.idl:
+
 2013-01-04  Tony Chang  <tony@chromium.org>
 
         Remove some autogenerated settings from InternalSettings.idl
index 5b26b67..484e76d 100644 (file)
             'dom/MessageEvent.idl',
             'dom/MessagePort.idl',
             'dom/MouseEvent.idl',
-            'dom/MutationCallback.idl',
             'dom/MutationEvent.idl',
             'dom/MutationObserver.idl',
             'dom/MutationRecord.idl',
             'bindings/v8/V8Initializer.h',
             'bindings/v8/V8LazyEventListener.cpp',
             'bindings/v8/V8LazyEventListener.h',
+            'bindings/v8/V8MutationCallback.cpp',
+            'bindings/v8/V8MutationCallback.h',
             'bindings/v8/V8NPObject.cpp',
             'bindings/v8/V8NPObject.h',
             'bindings/v8/V8NPUtils.cpp',
             'bindings/v8/custom/V8MessageEventCustom.cpp',
             'bindings/v8/custom/V8MessagePortCustom.cpp',
             'bindings/v8/custom/V8MicroDataItemValueCustom.cpp',
-            'bindings/v8/custom/V8MutationCallbackCustom.cpp',
             'bindings/v8/custom/V8MutationObserverCustom.cpp',
             'bindings/v8/custom/V8NamedNodeMapCustom.cpp',
             'bindings/v8/custom/V8NamedNodesCollection.cpp',
index 8fb9d93..07cb2dd 100644 (file)
@@ -3252,11 +3252,11 @@ sub GenerateCallbackHeader
 
     push(@headerContent, <<END);
 public:
-    static PassRefPtr<${v8InterfaceName}> create(v8::Handle<v8::Value> value, ScriptExecutionContext* context, v8::Handle<v8::Object> owner = v8::Handle<v8::Object>())
+    static PassRefPtr<${v8InterfaceName}> create(v8::Handle<v8::Value> value, ScriptExecutionContext* context)
     {
         ASSERT(value->IsObject());
         ASSERT(context);
-        return adoptRef(new ${v8InterfaceName}(v8::Handle<v8::Object>::Cast(value), context, owner));
+        return adoptRef(new ${v8InterfaceName}(v8::Handle<v8::Object>::Cast(value), context));
     }
 
     virtual ~${v8InterfaceName}();
@@ -3290,13 +3290,7 @@ END
     virtual ScriptExecutionContext* scriptExecutionContext() const { return ContextDestructionObserver::scriptExecutionContext(); }
 
 private:
-    ${v8InterfaceName}(v8::Handle<v8::Object>, ScriptExecutionContext*, v8::Handle<v8::Object>);
-
-    static void weakCallback(v8::Persistent<v8::Value> wrapper, void* parameter)
-    {
-        ${v8InterfaceName}* object = static_cast<${v8InterfaceName}*>(parameter);
-        object->m_callback.clear();
-    }
+    ${v8InterfaceName}(v8::Handle<v8::Object>, ScriptExecutionContext*);
 
     ScopedPersistent<v8::Object> m_callback;
     WorldContextHandle m_worldContext;
@@ -3328,15 +3322,11 @@ sub GenerateCallbackImplementation
     push(@implContent, "#include <wtf/Assertions.h>\n\n");
     push(@implContent, "namespace WebCore {\n\n");
     push(@implContent, <<END);
-${v8InterfaceName}::${v8InterfaceName}(v8::Handle<v8::Object> callback, ScriptExecutionContext* context, v8::Handle<v8::Object> owner)
+${v8InterfaceName}::${v8InterfaceName}(v8::Handle<v8::Object> callback, ScriptExecutionContext* context)
     : ActiveDOMCallback(context)
     , m_callback(callback)
     , m_worldContext(UseCurrentWorld)
 {
-    if (owner.IsEmpty())
-        return;
-    owner->SetHiddenValue(V8HiddenPropertyName::callback(), callback);
-    m_callback.get().MakeWeak(this, &${v8InterfaceName}::weakCallback);
 }
 
 ${v8InterfaceName}::~${v8InterfaceName}()
index bf0a995..82918c2 100644 (file)
 
 namespace WebCore {
 
-V8TestCallback::V8TestCallback(v8::Handle<v8::Object> callback, ScriptExecutionContext* context, v8::Handle<v8::Object> owner)
+V8TestCallback::V8TestCallback(v8::Handle<v8::Object> callback, ScriptExecutionContext* context)
     : ActiveDOMCallback(context)
     , m_callback(callback)
     , m_worldContext(UseCurrentWorld)
 {
-    if (owner.IsEmpty())
-        return;
-    owner->SetHiddenValue(V8HiddenPropertyName::callback(), callback);
-    m_callback.get().MakeWeak(this, &V8TestCallback::weakCallback);
 }
 
 V8TestCallback::~V8TestCallback()
index eb0c457..ec97769 100644 (file)
@@ -36,11 +36,11 @@ class ScriptExecutionContext;
 
 class V8TestCallback : public TestCallback, public ActiveDOMCallback {
 public:
-    static PassRefPtr<V8TestCallback> create(v8::Handle<v8::Value> value, ScriptExecutionContext* context, v8::Handle<v8::Object> owner = v8::Handle<v8::Object>())
+    static PassRefPtr<V8TestCallback> create(v8::Handle<v8::Value> value, ScriptExecutionContext* context)
     {
         ASSERT(value->IsObject());
         ASSERT(context);
-        return adoptRef(new V8TestCallback(v8::Handle<v8::Object>::Cast(value), context, owner));
+        return adoptRef(new V8TestCallback(v8::Handle<v8::Object>::Cast(value), context));
     }
 
     virtual ~V8TestCallback();
@@ -58,13 +58,7 @@ public:
     virtual ScriptExecutionContext* scriptExecutionContext() const { return ContextDestructionObserver::scriptExecutionContext(); }
 
 private:
-    V8TestCallback(v8::Handle<v8::Object>, ScriptExecutionContext*, v8::Handle<v8::Object>);
-
-    static void weakCallback(v8::Persistent<v8::Value> wrapper, void* parameter)
-    {
-        V8TestCallback* object = static_cast<V8TestCallback*>(parameter);
-        object->m_callback.clear();
-    }
+    V8TestCallback(v8::Handle<v8::Object>, ScriptExecutionContext*);
 
     ScopedPersistent<v8::Object> m_callback;
     WorldContextHandle m_worldContext;
@@ -1,35 +1,29 @@
 /*
- * Copyright (C) 2010, 2012 Google Inc. All rights reserved.
+ * Copyright (C) 2013 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:
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. 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.
  *
- *     * 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.
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS 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 APPLE INC. OR ITS 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 "V8MutationCallback.h"
 
 #include "ScriptExecutionContext.h"
 #include "V8MutationObserver.h"
 #include "V8MutationRecord.h"
 #include <wtf/Assertions.h>
-#include <wtf/GetPtr.h>
-#include <wtf/RefCounted.h>
-#include <wtf/RefPtr.h>
 
 namespace WebCore {
 
+V8MutationCallback::V8MutationCallback(v8::Handle<v8::Object> callback, ScriptExecutionContext* context, v8::Handle<v8::Object> owner)
+    : ActiveDOMCallback(context)
+    , m_callback(callback)
+    , m_worldContext(UseCurrentWorld)
+{
+    owner->SetHiddenValue(V8HiddenPropertyName::callback(), callback);
+    m_callback.get().MakeWeak(this, &V8MutationCallback::weakCallback);
+}
+
 bool V8MutationCallback::handleEvent(MutationRecordArray* mutations, MutationObserver* observer)
 {
     ASSERT(mutations);
diff --git a/Source/WebCore/bindings/v8/V8MutationCallback.h b/Source/WebCore/bindings/v8/V8MutationCallback.h
new file mode 100644 (file)
index 0000000..8b5f3e2
--- /dev/null
@@ -0,0 +1,66 @@
+/*
+ * Copyright (C) 2013 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:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. 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.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS 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 APPLE INC. OR ITS 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.
+ */
+
+#ifndef V8MutationCallback_h
+#define V8MutationCallback_h
+
+#include "ActiveDOMCallback.h"
+#include "MutationCallback.h"
+#include "ScopedPersistent.h"
+#include "WorldContextHandle.h"
+#include <v8.h>
+
+namespace WebCore {
+
+class ScriptExecutionContext;
+
+class V8MutationCallback : public MutationCallback, public ActiveDOMCallback {
+public:
+    static PassRefPtr<V8MutationCallback> create(v8::Handle<v8::Value> value, ScriptExecutionContext* context, v8::Handle<v8::Object> owner)
+    {
+        ASSERT(value->IsObject());
+        ASSERT(context);
+        return adoptRef(new V8MutationCallback(v8::Handle<v8::Object>::Cast(value), context, owner));
+    }
+
+    virtual bool handleEvent(MutationRecordArray*, MutationObserver*) OVERRIDE;
+    virtual ScriptExecutionContext* scriptExecutionContext() const OVERRIDE { return ContextDestructionObserver::scriptExecutionContext(); }
+
+private:
+    V8MutationCallback(v8::Handle<v8::Object>, ScriptExecutionContext*, v8::Handle<v8::Object>);
+
+    static void weakCallback(v8::Persistent<v8::Value> wrapper, void* parameter)
+    {
+        V8MutationCallback* object = static_cast<V8MutationCallback*>(parameter);
+        object->m_callback.clear();
+    }
+
+    ScopedPersistent<v8::Object> m_callback;
+    WorldContextHandle m_worldContext;
+};
+
+}
+
+#endif // V8MutationCallback_h
index 067e36f..7ff60b7 100644 (file)
@@ -28,6 +28,8 @@
  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
+// FIXME: This interface is only used to generate code for JSC.
+// It should be removed once http://webkit.org/b/93661 is fixed.
 [
     Callback
 ] interface MutationCallback {