2009-02-26 Dimitri Glazkov <dglazkov@chromium.org>
authordglazkov@chromium.org <dglazkov@chromium.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 26 Feb 2009 19:43:12 +0000 (19:43 +0000)
committerdglazkov@chromium.org <dglazkov@chromium.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 26 Feb 2009 19:43:12 +0000 (19:43 +0000)
        Reviewed by Eric Seidel.

        https://bugs.webkit.org/show_bug.cgi?id=24182
        Add NodeFilter, NodeIterator, and TreeWalker custom V8 bindings.

        * bindings/v8/custom/V8NodeFilterCustom.cpp: Added.
        (WebCore::CALLBACK_FUNC_DECL):
        * bindings/v8/custom/V8NodeIteratorCustom.cpp: Added.
        (WebCore::toV8):
        (WebCore::CALLBACK_FUNC_DECL):
        * bindings/v8/custom/V8TreeWalkerCustom.cpp: Added.
        (WebCore::toV8):
        (WebCore::CALLBACK_FUNC_DECL):

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

WebCore/ChangeLog
WebCore/bindings/v8/custom/V8NodeFilterCustom.cpp [new file with mode: 0644]
WebCore/bindings/v8/custom/V8NodeIteratorCustom.cpp [new file with mode: 0644]
WebCore/bindings/v8/custom/V8TreeWalkerCustom.cpp [new file with mode: 0644]

index 6dd6d1589cd6e33cbfb0a3f2301940a14570c1f5..d00f916927360e92ea2dbd8f0799e5d2437a4b04 100644 (file)
@@ -1,3 +1,19 @@
+2009-02-26  Dimitri Glazkov  <dglazkov@chromium.org>
+
+        Reviewed by Eric Seidel.
+
+        https://bugs.webkit.org/show_bug.cgi?id=24182
+        Add NodeFilter, NodeIterator, and TreeWalker custom V8 bindings.
+
+        * bindings/v8/custom/V8NodeFilterCustom.cpp: Added.
+        (WebCore::CALLBACK_FUNC_DECL):
+        * bindings/v8/custom/V8NodeIteratorCustom.cpp: Added.
+        (WebCore::toV8):
+        (WebCore::CALLBACK_FUNC_DECL):
+        * bindings/v8/custom/V8TreeWalkerCustom.cpp: Added.
+        (WebCore::toV8):
+        (WebCore::CALLBACK_FUNC_DECL):
+
 2009-02-26  Alexey Proskuryakov  <ap@webkit.org>
 
         Reviewed by Darin Adler.
diff --git a/WebCore/bindings/v8/custom/V8NodeFilterCustom.cpp b/WebCore/bindings/v8/custom/V8NodeFilterCustom.cpp
new file mode 100644 (file)
index 0000000..8839420
--- /dev/null
@@ -0,0 +1,48 @@
+/*
+ * Copyright (C) 2007-2009 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 "NodeFilter.h"
+
+#include "ExceptionCode.h"
+
+#include "V8Binding.h"
+#include "V8CustomBinding.h"
+#include "V8Proxy.h"
+
+namespace WebCore {
+
+CALLBACK_FUNC_DECL(NodeFilterAcceptNode)
+{
+    INC_STATS("DOM.NodeFilter.acceptNode()");
+    return throwError(NOT_SUPPORTED_ERR);
+}
+
+} // namespace WebCore
diff --git a/WebCore/bindings/v8/custom/V8NodeIteratorCustom.cpp b/WebCore/bindings/v8/custom/V8NodeIteratorCustom.cpp
new file mode 100644 (file)
index 0000000..85269f3
--- /dev/null
@@ -0,0 +1,81 @@
+/*
+ * Copyright (C) 2007-2009 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 "NodeIterator.h"
+
+#include "ScriptState.h"
+
+#include "V8Binding.h"
+#include "V8CustomBinding.h"
+#include "V8Proxy.h"
+
+#include <wtf/PassRefPtr.h>
+#include <wtf/RefPtr.h>
+
+namespace WebCore {
+
+static inline v8::Handle<v8::Value> toV8(PassRefPtr<Node> object, ExceptionCode ec, ScriptState* state)
+{
+    if (ec)
+        return throwError(ec);
+
+    if (state->hadException())
+        return throwError(state->exception());
+
+    if (!object)
+        return v8::Undefined();
+
+    return V8Proxy::NodeToV8Object(object.get());
+}
+
+CALLBACK_FUNC_DECL(NodeIteratorNextNode)
+{
+    INC_STATS("DOM.NodeIterator.nextNode()");
+    NodeIterator* nodeIterator = V8Proxy::ToNativeObject<NodeIterator>(V8ClassIndex::NODEITERATOR, args.Holder());
+
+    ExceptionCode ec = 0;
+    ScriptState state;
+    RefPtr<Node> result = nodeIterator->nextNode(&state, ec);
+    return toV8(result.release(), ec, &state);
+}
+
+CALLBACK_FUNC_DECL(NodeIteratorPreviousNode)
+{
+    INC_STATS("DOM.NodeIterator.previousNode()");
+    NodeIterator* nodeIterator = V8Proxy::ToNativeObject<NodeIterator>(V8ClassIndex::NODEITERATOR, args.Holder());
+
+    ExceptionCode ec = 0;
+    ScriptState state;
+    RefPtr<Node> result = nodeIterator->previousNode(&state, ec);
+    return toV8(result.release(), ec, &state);
+}
+
+} // namespace WebCore
diff --git a/WebCore/bindings/v8/custom/V8TreeWalkerCustom.cpp b/WebCore/bindings/v8/custom/V8TreeWalkerCustom.cpp
new file mode 100644 (file)
index 0000000..08fd66b
--- /dev/null
@@ -0,0 +1,127 @@
+/*
+ * Copyright (C) 2007-2009 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 "TreeWalker.h"
+
+#include "Node.h"
+#include "ScriptState.h"
+
+#include "V8Binding.h"
+#include "V8CustomBinding.h"
+#include "V8Proxy.h"
+
+#include <wtf/PassRefPtr.h>
+#include <wtf/RefPtr.h>
+
+namespace WebCore {
+
+static inline v8::Handle<v8::Value> toV8(PassRefPtr<Node> object, ScriptState* state)
+{
+    if (state->hadException())
+        return throwError(state->exception());
+
+    if (!object)
+        return v8::Undefined();
+
+    return V8Proxy::NodeToV8Object(object.get());
+}
+
+CALLBACK_FUNC_DECL(TreeWalkerParentNode)
+{
+    INC_STATS("DOM.TreeWalker.parentNode()");
+    TreeWalker* treeWalker = V8Proxy::ToNativeObject<TreeWalker>(V8ClassIndex::TREEWALKER, args.Holder());
+
+    ScriptState state;
+    RefPtr<Node> result = treeWalker->parentNode(&state);
+    return toV8(result.release(), &state);
+}
+
+CALLBACK_FUNC_DECL(TreeWalkerFirstChild)
+{
+    INC_STATS("DOM.TreeWalker.firstChild()");
+    TreeWalker* treeWalker = V8Proxy::ToNativeObject<TreeWalker>(V8ClassIndex::TREEWALKER, args.Holder());
+
+    ScriptState state;
+    RefPtr<Node> result = treeWalker->firstChild(&state);
+    return toV8(result.release(), &state);
+}
+
+CALLBACK_FUNC_DECL(TreeWalkerLastChild)
+{
+    INC_STATS("DOM.TreeWalker.lastChild()");
+    TreeWalker* treeWalker = V8Proxy::ToNativeObject<TreeWalker>(V8ClassIndex::TREEWALKER, args.Holder());
+
+    ScriptState state;
+    RefPtr<Node> result = treeWalker->lastChild(&state);
+    return toV8(result.release(), &state);
+}
+
+CALLBACK_FUNC_DECL(TreeWalkerNextNode)
+{
+    INC_STATS("DOM.TreeWalker.nextNode()");
+    TreeWalker* treeWalker = V8Proxy::ToNativeObject<TreeWalker>(V8ClassIndex::TREEWALKER, args.Holder());
+
+    ScriptState state;
+    RefPtr<Node> result = treeWalker->nextNode(&state);
+    return toV8(result.release(), &state);
+}
+
+CALLBACK_FUNC_DECL(TreeWalkerPreviousNode)
+{
+    INC_STATS("DOM.TreeWalker.previousNode()");
+    TreeWalker* treeWalker = V8Proxy::ToNativeObject<TreeWalker>(V8ClassIndex::TREEWALKER, args.Holder());
+
+    ScriptState state;
+    RefPtr<Node> result = treeWalker->previousNode(&state);
+    return toV8(result.release(), &state);
+}
+
+CALLBACK_FUNC_DECL(TreeWalkerNextSibling)
+{
+    INC_STATS("DOM.TreeWalker.nextSibling()");
+    TreeWalker* treeWalker = V8Proxy::ToNativeObject<TreeWalker>(V8ClassIndex::TREEWALKER, args.Holder());
+
+    ScriptState state;
+    RefPtr<Node> result = treeWalker->nextSibling(&state);
+    return toV8(result.release(), &state);
+}
+
+CALLBACK_FUNC_DECL(TreeWalkerPreviousSibling)
+{
+    INC_STATS("DOM.TreeWalker.previousSibling()");
+    TreeWalker* treeWalker = V8Proxy::ToNativeObject<TreeWalker>(V8ClassIndex::TREEWALKER, args.Holder());
+
+    ScriptState state;
+    RefPtr<Node> result = treeWalker->previousSibling(&state);
+    return toV8(result.release(), &state);
+}
+
+} // namespace WebCore