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

Side by Side Diff: Source/WebCore/bindings/v8/V8LazyEventListener.cpp

Issue 10007027: Merge 113086 - [v8] Fix memory leak in V8LazyEventListener (Closed) Base URL: http://svn.webkit.org/repository/webkit/branches/chromium/1084/
Patch Set: Created 8 years, 8 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
« no previous file with comments | « Source/WebCore/bindings/v8/V8LazyEventListener.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2006, 2007, 2008, 2009 Google Inc. All rights reserved. 2 * Copyright (C) 2006, 2007, 2008, 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 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
43 #include "V8HTMLFormElement.h" 43 #include "V8HTMLFormElement.h"
44 #include "V8HiddenPropertyName.h" 44 #include "V8HiddenPropertyName.h"
45 #include "V8Node.h" 45 #include "V8Node.h"
46 #include "V8Proxy.h" 46 #include "V8Proxy.h"
47 #include "WorldContextHandle.h" 47 #include "WorldContextHandle.h"
48 48
49 #include <wtf/StdLibExtras.h> 49 #include <wtf/StdLibExtras.h>
50 50
51 namespace WebCore { 51 namespace WebCore {
52 52
53 V8LazyEventListener::V8LazyEventListener(const AtomicString& functionName, const AtomicString& eventParameterName, const String& code, const String sourceURL, c onst TextPosition& position, PassRefPtr<Node> node, const WorldContextHandle& wo rldContext) 53 V8LazyEventListener::V8LazyEventListener(const AtomicString& functionName, const AtomicString& eventParameterName, const String& code, const String sourceURL, c onst TextPosition& position, Node* node, const WorldContextHandle& worldContext)
54 : V8AbstractEventListener(true, worldContext) 54 : V8AbstractEventListener(true, worldContext)
55 , m_functionName(functionName) 55 , m_functionName(functionName)
56 , m_eventParameterName(eventParameterName) 56 , m_eventParameterName(eventParameterName)
57 , m_code(code) 57 , m_code(code)
58 , m_sourceURL(sourceURL) 58 , m_sourceURL(sourceURL)
59 , m_node(node) 59 , m_node(node)
60 , m_formElement(0)
61 , m_position(position) 60 , m_position(position)
62 { 61 {
63 if (m_node && m_node->isHTMLElement())
64 m_formElement = static_cast<HTMLElement*>(m_node.get())->form();
65 } 62 }
66 63
67 template<typename T> 64 template<typename T>
68 v8::Handle<v8::Object> toObjectWrapper(T* domObject) 65 v8::Handle<v8::Object> toObjectWrapper(T* domObject)
69 { 66 {
70 if (!domObject) 67 if (!domObject)
71 return v8::Object::New(); 68 return v8::Object::New();
72 v8::Handle<v8::Value> value = toV8(domObject); 69 v8::Handle<v8::Value> value = toV8(domObject);
73 if (value.IsEmpty()) 70 if (value.IsEmpty())
74 return v8::Object::New(); 71 return v8::Object::New();
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
158 // Call v8::Script::Run() directly to avoid an erroneous call to V8Recursion Scope::didLeaveScriptContext(). 155 // Call v8::Script::Run() directly to avoid an erroneous call to V8Recursion Scope::didLeaveScriptContext().
159 // FIXME: Remove this code when we stop doing the 'with' hack above. 156 // FIXME: Remove this code when we stop doing the 'with' hack above.
160 v8::Local<v8::Value> value = script->Run(); 157 v8::Local<v8::Value> value = script->Run();
161 if (value.IsEmpty()) 158 if (value.IsEmpty())
162 return; 159 return;
163 160
164 // Call the outer function to get the inner function. 161 // Call the outer function to get the inner function.
165 ASSERT(value->IsFunction()); 162 ASSERT(value->IsFunction());
166 v8::Local<v8::Function> intermediateFunction = value.As<v8::Function>(); 163 v8::Local<v8::Function> intermediateFunction = value.As<v8::Function>();
167 164
168 v8::Handle<v8::Object> nodeWrapper = toObjectWrapper<Node>(m_node.get()); 165 HTMLFormElement* formElement = 0;
169 v8::Handle<v8::Object> formWrapper = toObjectWrapper<HTMLFormElement>(m_form Element.get()); 166 if (m_node && m_node->isHTMLElement())
167 formElement = static_cast<HTMLElement*>(m_node)->form();
168
169 v8::Handle<v8::Object> nodeWrapper = toObjectWrapper<Node>(m_node);
170 v8::Handle<v8::Object> formWrapper = toObjectWrapper<HTMLFormElement>(formEl ement);
170 v8::Handle<v8::Object> documentWrapper = toObjectWrapper<Document>(m_node ? m_node->ownerDocument() : 0); 171 v8::Handle<v8::Object> documentWrapper = toObjectWrapper<Document>(m_node ? m_node->ownerDocument() : 0);
171 172
172 m_node.clear();
173 m_formElement.clear();
174
175 v8::Handle<v8::Value> parameters[3] = { nodeWrapper, formWrapper, documentWr apper }; 173 v8::Handle<v8::Value> parameters[3] = { nodeWrapper, formWrapper, documentWr apper };
176 174
177 // Use Call directly to avoid an erroneous call to V8RecursionScope::didLeav eScriptContext(). 175 // Use Call directly to avoid an erroneous call to V8RecursionScope::didLeav eScriptContext().
178 // FIXME: Remove this code when we stop doing the 'with' hack above. 176 // FIXME: Remove this code when we stop doing the 'with' hack above.
179 v8::Local<v8::Value> innerValue = intermediateFunction->Call(v8Context->Glob al(), 3, parameters); 177 v8::Local<v8::Value> innerValue = intermediateFunction->Call(v8Context->Glob al(), 3, parameters);
180 178
181 if (innerValue.IsEmpty() || !innerValue->IsFunction()) 179 if (innerValue.IsEmpty() || !innerValue->IsFunction())
182 return; 180 return;
183 181
184 v8::Local<v8::Function> wrappedFunction = innerValue.As<v8::Function>(); 182 v8::Local<v8::Function> wrappedFunction = innerValue.As<v8::Function>();
(...skipping 20 matching lines...) Expand all
205 toStringResult.append(m_eventParameterName); 203 toStringResult.append(m_eventParameterName);
206 toStringResult.append(") {\n "); 204 toStringResult.append(") {\n ");
207 toStringResult.append(m_code); 205 toStringResult.append(m_code);
208 toStringResult.append("\n}"); 206 toStringResult.append("\n}");
209 wrappedFunction->SetHiddenValue(V8HiddenPropertyName::toStringString(), v8ExternalString(toStringResult)); 207 wrappedFunction->SetHiddenValue(V8HiddenPropertyName::toStringString(), v8ExternalString(toStringResult));
210 wrappedFunction->Set(v8::String::NewSymbol("toString"), toStringFunction ); 208 wrappedFunction->Set(v8::String::NewSymbol("toString"), toStringFunction );
211 } 209 }
212 210
213 wrappedFunction->SetName(v8::String::New(fromWebCoreString(m_functionName), m_functionName.length())); 211 wrappedFunction->SetName(v8::String::New(fromWebCoreString(m_functionName), m_functionName.length()));
214 212
213 // Since we only parse once, there's no need to keep data used for parsing a round anymore.
214 m_functionName = String();
215 m_code = String();
216 m_eventParameterName = String();
217 m_sourceURL = String();
218
215 setListenerObject(wrappedFunction); 219 setListenerObject(wrappedFunction);
216 } 220 }
217 221
218 } // namespace WebCore 222 } // namespace WebCore
OLDNEW
« no previous file with comments | « Source/WebCore/bindings/v8/V8LazyEventListener.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698