• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2007-2009 Google Inc. All rights reserved.
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions are
6  * met:
7  *
8  *     * Redistributions of source code must retain the above copyright
9  * notice, this list of conditions and the following disclaimer.
10  *     * Redistributions in binary form must reproduce the above
11  * copyright notice, this list of conditions and the following disclaimer
12  * in the documentation and/or other materials provided with the
13  * distribution.
14  *     * Neither the name of Google Inc. nor the names of its
15  * contributors may be used to endorse or promote products derived from
16  * this software without specific prior written permission.
17  *
18  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29  */
30 
31 #include "config.h"
32 #include "TreeWalker.h"
33 
34 #include "Node.h"
35 #include "ScriptState.h"
36 
37 #include "V8Binding.h"
38 #include "V8CustomBinding.h"
39 #include "V8Proxy.h"
40 
41 #include <wtf/PassRefPtr.h>
42 #include <wtf/RefPtr.h>
43 
44 namespace WebCore {
45 
toV8(PassRefPtr<Node> object,ScriptState * state)46 static inline v8::Handle<v8::Value> toV8(PassRefPtr<Node> object, ScriptState* state)
47 {
48     if (state->hadException())
49         return throwError(state->exception());
50 
51     if (!object)
52         return v8::Null();
53 
54     return V8DOMWrapper::convertNodeToV8Object(object);
55 }
56 
CALLBACK_FUNC_DECL(TreeWalkerParentNode)57 CALLBACK_FUNC_DECL(TreeWalkerParentNode)
58 {
59     INC_STATS("DOM.TreeWalker.parentNode()");
60     TreeWalker* treeWalker = V8DOMWrapper::convertToNativeObject<TreeWalker>(V8ClassIndex::TREEWALKER, args.Holder());
61 
62     ScriptState state;
63     RefPtr<Node> result = treeWalker->parentNode(&state);
64     return toV8(result.release(), &state);
65 }
66 
CALLBACK_FUNC_DECL(TreeWalkerFirstChild)67 CALLBACK_FUNC_DECL(TreeWalkerFirstChild)
68 {
69     INC_STATS("DOM.TreeWalker.firstChild()");
70     TreeWalker* treeWalker = V8DOMWrapper::convertToNativeObject<TreeWalker>(V8ClassIndex::TREEWALKER, args.Holder());
71 
72     ScriptState state;
73     RefPtr<Node> result = treeWalker->firstChild(&state);
74     return toV8(result.release(), &state);
75 }
76 
CALLBACK_FUNC_DECL(TreeWalkerLastChild)77 CALLBACK_FUNC_DECL(TreeWalkerLastChild)
78 {
79     INC_STATS("DOM.TreeWalker.lastChild()");
80     TreeWalker* treeWalker = V8DOMWrapper::convertToNativeObject<TreeWalker>(V8ClassIndex::TREEWALKER, args.Holder());
81 
82     ScriptState state;
83     RefPtr<Node> result = treeWalker->lastChild(&state);
84     return toV8(result.release(), &state);
85 }
86 
CALLBACK_FUNC_DECL(TreeWalkerNextNode)87 CALLBACK_FUNC_DECL(TreeWalkerNextNode)
88 {
89     INC_STATS("DOM.TreeWalker.nextNode()");
90     TreeWalker* treeWalker = V8DOMWrapper::convertToNativeObject<TreeWalker>(V8ClassIndex::TREEWALKER, args.Holder());
91 
92     ScriptState state;
93     RefPtr<Node> result = treeWalker->nextNode(&state);
94     return toV8(result.release(), &state);
95 }
96 
CALLBACK_FUNC_DECL(TreeWalkerPreviousNode)97 CALLBACK_FUNC_DECL(TreeWalkerPreviousNode)
98 {
99     INC_STATS("DOM.TreeWalker.previousNode()");
100     TreeWalker* treeWalker = V8DOMWrapper::convertToNativeObject<TreeWalker>(V8ClassIndex::TREEWALKER, args.Holder());
101 
102     ScriptState state;
103     RefPtr<Node> result = treeWalker->previousNode(&state);
104     return toV8(result.release(), &state);
105 }
106 
CALLBACK_FUNC_DECL(TreeWalkerNextSibling)107 CALLBACK_FUNC_DECL(TreeWalkerNextSibling)
108 {
109     INC_STATS("DOM.TreeWalker.nextSibling()");
110     TreeWalker* treeWalker = V8DOMWrapper::convertToNativeObject<TreeWalker>(V8ClassIndex::TREEWALKER, args.Holder());
111 
112     ScriptState state;
113     RefPtr<Node> result = treeWalker->nextSibling(&state);
114     return toV8(result.release(), &state);
115 }
116 
CALLBACK_FUNC_DECL(TreeWalkerPreviousSibling)117 CALLBACK_FUNC_DECL(TreeWalkerPreviousSibling)
118 {
119     INC_STATS("DOM.TreeWalker.previousSibling()");
120     TreeWalker* treeWalker = V8DOMWrapper::convertToNativeObject<TreeWalker>(V8ClassIndex::TREEWALKER, args.Holder());
121 
122     ScriptState state;
123     RefPtr<Node> result = treeWalker->previousSibling(&state);
124     return toV8(result.release(), &state);
125 }
126 
127 } // namespace WebCore
128