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

Side by Side Diff: Source/bindings/v8/custom/V8DocumentCustom.cpp

Issue 21274004: Fix Document leak from NodeFilter. (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: add TreeWalker leak test Created 7 years, 4 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2007-2009 Google Inc. All rights reserved. 2 * Copyright (C) 2007-2009 Google Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are 5 * modification, are permitted provided that the following conditions are
6 * met: 6 * met:
7 * 7 *
8 * * Redistributions of source code must retain the above copyright 8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above 10 * * Redistributions in binary form must reproduce the above
(...skipping 17 matching lines...) Expand all
28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 */ 29 */
30 30
31 #include "config.h" 31 #include "config.h"
32 #include "V8Document.h" 32 #include "V8Document.h"
33 33
34 #include "V8CanvasRenderingContext2D.h" 34 #include "V8CanvasRenderingContext2D.h"
35 #include "V8DOMImplementation.h" 35 #include "V8DOMImplementation.h"
36 #include "V8HTMLDocument.h" 36 #include "V8HTMLDocument.h"
37 #include "V8Node.h" 37 #include "V8Node.h"
38 #include "V8NodeFilter.h"
39 #include "V8NodeIterator.h"
38 #include "V8SVGDocument.h" 40 #include "V8SVGDocument.h"
39 #include "V8Touch.h" 41 #include "V8Touch.h"
40 #include "V8TouchList.h" 42 #include "V8TouchList.h"
43 #include "V8TreeWalker.h"
41 #include "V8WebGLRenderingContext.h" 44 #include "V8WebGLRenderingContext.h"
42 #include "V8XPathNSResolver.h" 45 #include "V8XPathNSResolver.h"
43 #include "V8XPathResult.h" 46 #include "V8XPathResult.h"
44 #include "bindings/v8/ExceptionState.h" 47 #include "bindings/v8/ExceptionState.h"
45 #include "bindings/v8/ScriptController.h" 48 #include "bindings/v8/ScriptController.h"
46 #include "bindings/v8/V8Binding.h" 49 #include "bindings/v8/V8Binding.h"
47 #include "bindings/v8/V8DOMWrapper.h" 50 #include "bindings/v8/V8DOMWrapper.h"
51 #include "bindings/v8/V8HiddenPropertyName.h"
52 #include "bindings/v8/V8NodeFilterCondition.h"
48 #include "bindings/v8/V8WindowShell.h" 53 #include "bindings/v8/V8WindowShell.h"
49 #include "bindings/v8/custom/V8CustomXPathNSResolver.h" 54 #include "bindings/v8/custom/V8CustomXPathNSResolver.h"
50 #include "core/dom/Document.h" 55 #include "core/dom/Document.h"
51 #include "core/dom/ExceptionCode.h" 56 #include "core/dom/ExceptionCode.h"
52 #include "core/dom/Node.h" 57 #include "core/dom/Node.h"
53 #include "core/dom/TouchList.h" 58 #include "core/dom/TouchList.h"
54 #include "core/html/canvas/CanvasRenderingContext.h" 59 #include "core/html/canvas/CanvasRenderingContext.h"
55 #include "core/page/Frame.h" 60 #include "core/page/Frame.h"
56 #include "core/xml/DocumentXPathEvaluator.h" 61 #include "core/xml/DocumentXPathEvaluator.h"
57 #include "core/xml/XPathNSResolver.h" 62 #include "core/xml/XPathNSResolver.h"
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
109 RefPtr<TouchList> touchList = TouchList::create(); 114 RefPtr<TouchList> touchList = TouchList::create();
110 115
111 for (int i = 0; i < args.Length(); i++) { 116 for (int i = 0; i < args.Length(); i++) {
112 Touch* touch = V8DOMWrapper::isWrapperOfType(args[i], &V8Touch::info) ? V8Touch::toNative(args[i]->ToObject()) : 0; 117 Touch* touch = V8DOMWrapper::isWrapperOfType(args[i], &V8Touch::info) ? V8Touch::toNative(args[i]->ToObject()) : 0;
113 touchList->append(touch); 118 touchList->append(touch);
114 } 119 }
115 120
116 v8SetReturnValue(args, toV8(touchList.release(), args.Holder(), args.GetIsol ate())); 121 v8SetReturnValue(args, toV8(touchList.release(), args.Holder(), args.GetIsol ate()));
117 } 122 }
118 123
124 namespace {
125
126 PassRefPtr<NodeFilter> toNodeFilterWithWrapper(v8::Handle<v8::Object>* filterWra pper, v8::Handle<v8::Value> callback, v8::Handle<v8::Object> creationContext, v8 ::Isolate* isolate)
haraken 2013/08/01 03:44:15 I'd really want to avoid writing custom bindings h
kouhei (in TOK) 2013/08/01 05:09:58 I had offline discussion with haraken. The conclus
127 {
128 RefPtr<NodeFilter> filter = NodeFilter::create();
129 *filterWrapper = toV8(filter.get(), creationContext, isolate).As<v8::Object> ();
130
131 RefPtr<NodeFilterCondition> condition = V8NodeFilterCondition::create(callba ck, *filterWrapper);
132 filter->setCondition(condition.release());
133
134 return filter.release();
135 }
136
137 } // namespace
138
139 void V8Document::createNodeIteratorMethodCustom(const v8::FunctionCallbackInfo<v 8::Value>& args)
140 {
141 if (args.Length() < 1) {
142 throwNotEnoughArgumentsError(args.GetIsolate());
143 return;
144 }
145
146 Document* document = V8Document::toNative(args.Holder());
147 ExceptionState es(args.GetIsolate());
148
149 V8TRYCATCH_VOID(Node*, root, V8Node::HasInstance(args[0], args.GetIsolate(), worldType(args.GetIsolate())) ? V8Node::toNative(v8::Handle<v8::Object>::Cast(a rgs[0])) : 0);
150 V8TRYCATCH_VOID(unsigned, whatToShow, (args.Length() > 2) ? toUInt32(args[1] ) : NodeFilter::SHOW_ALL);
151
152 v8::Handle<v8::Object> filterWrapper;
153 RefPtr<NodeFilter> filter;
154 if (args.Length() > 3)
155 filter = toNodeFilterWithWrapper(&filterWrapper, args[2], args.Holder(), args.GetIsolate());
156
157 V8TRYCATCH_VOID(bool, expandEntityReferences, args[3]->BooleanValue());
158
159 RefPtr<NodeIterator> nodeIterator = document->createNodeIterator(root, whatT oShow, filter.get(), expandEntityReferences, es);
160 if (es.throwIfNeeded())
161 return;
162
163 v8::Handle<v8::Object> nodeIteratorWrapper = toV8Fast(nodeIterator.get(), ar gs, document).As<v8::Object>();
164 if (!filterWrapper.IsEmpty())
165 V8HiddenPropertyName::setNamedHiddenReference(nodeIteratorWrapper, "filt er", filterWrapper);
166 v8SetReturnValue(args, nodeIteratorWrapper);
167 }
168
169 void V8Document::createTreeWalkerMethodCustom(const v8::FunctionCallbackInfo<v8: :Value>& args)
170 {
171 if (args.Length() < 1) {
172 throwNotEnoughArgumentsError(args.GetIsolate());
173 return;
174 }
175
176 Document* document = V8Document::toNative(args.Holder());
177 ExceptionState es(args.GetIsolate());
178
179 V8TRYCATCH_VOID(Node*, root, V8Node::HasInstance(args[0], args.GetIsolate(), worldType(args.GetIsolate())) ? V8Node::toNative(v8::Handle<v8::Object>::Cast(a rgs[0])) : 0);
180 V8TRYCATCH_VOID(unsigned, whatToShow, (args.Length() > 2) ? toUInt32(args[1] ) : NodeFilter::SHOW_ALL);
181
182 v8::Handle<v8::Object> filterWrapper;
183 RefPtr<NodeFilter> filter;
184 if (args.Length() > 3)
185 filter = toNodeFilterWithWrapper(&filterWrapper, args[2], args.Holder(), args.GetIsolate());
186
187 V8TRYCATCH_VOID(bool, expandEntityReferences, args[3]->BooleanValue());
188
189 RefPtr<TreeWalker> treeWalker = document->createTreeWalker(root, whatToShow, filter.get(), expandEntityReferences, es);
190 if (es.throwIfNeeded())
191 return;
192
193 v8::Handle<v8::Object> treeWalkerWrapper = toV8Fast(treeWalker.get(), args, document).As<v8::Object>();
194 if (!filterWrapper.IsEmpty())
195 V8HiddenPropertyName::setNamedHiddenReference(treeWalkerWrapper, "filter ", filterWrapper);
196 v8SetReturnValue(args, treeWalkerWrapper);
197 }
198
119 } // namespace WebCore 199 } // namespace WebCore
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698