OLD | NEW |
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 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
148 // which would shadow property "3" on the prototype. | 148 // which would shadow property "3" on the prototype. |
149 String code = "(function() {" | 149 String code = "(function() {" |
150 "with (this[2]) {" | 150 "with (this[2]) {" |
151 "with (this[1]) {" | 151 "with (this[1]) {" |
152 "with (this[0]) {" | 152 "with (this[0]) {" |
153 "return function(" + m_eventParameterName + ") {" + | 153 "return function(" + m_eventParameterName + ") {" + |
154 m_code + "\n" // Insert '\n' otherwise //-style comments could b
reak the handler. | 154 m_code + "\n" // Insert '\n' otherwise //-style comments could b
reak the handler. |
155 "};" | 155 "};" |
156 "}}}})"; | 156 "}}}})"; |
157 | 157 |
158 v8::Handle<v8::String> codeExternalString = v8String(code, v8Context->GetIso
late()); | 158 v8::Handle<v8::String> codeExternalString = deprecatedV8String(code); |
159 | 159 |
160 v8::Handle<v8::Script> script = ScriptSourceCode::compileScript(codeExternal
String, m_sourceURL, m_position); | 160 v8::Handle<v8::Script> script = ScriptSourceCode::compileScript(codeExternal
String, m_sourceURL, m_position); |
161 if (script.IsEmpty()) | 161 if (script.IsEmpty()) |
162 return; | 162 return; |
163 | 163 |
164 // FIXME: Remove this code when we stop doing the 'with' hack above. | 164 // FIXME: Remove this code when we stop doing the 'with' hack above. |
165 v8::Local<v8::Value> value; | 165 v8::Local<v8::Value> value; |
166 { | 166 { |
167 V8RecursionScope::MicrotaskSuppression scope; | 167 V8RecursionScope::MicrotaskSuppression scope; |
168 value = script->Run(); | 168 value = script->Run(); |
169 } | 169 } |
170 if (value.IsEmpty()) | 170 if (value.IsEmpty()) |
171 return; | 171 return; |
172 | 172 |
173 // Call the outer function to get the inner function. | 173 // Call the outer function to get the inner function. |
174 ASSERT(value->IsFunction()); | 174 ASSERT(value->IsFunction()); |
175 v8::Local<v8::Function> intermediateFunction = value.As<v8::Function>(); | 175 v8::Local<v8::Function> intermediateFunction = value.As<v8::Function>(); |
176 | 176 |
177 HTMLFormElement* formElement = 0; | 177 HTMLFormElement* formElement = 0; |
178 if (m_node && m_node->isHTMLElement()) | 178 if (m_node && m_node->isHTMLElement()) |
179 formElement = static_cast<HTMLElement*>(m_node)->form(); | 179 formElement = static_cast<HTMLElement*>(m_node)->form(); |
180 | 180 |
181 v8::Handle<v8::Object> nodeWrapper = toObjectWrapper<Node>(m_node, v8Context
->GetIsolate()); | 181 v8::Handle<v8::Object> nodeWrapper = toObjectWrapper<Node>(m_node, v8Context
->GetIsolate()); |
182 v8::Handle<v8::Object> formWrapper = toObjectWrapper<HTMLFormElement>(formEl
ement, v8Context->GetIsolate()); | 182 v8::Handle<v8::Object> formWrapper = toObjectWrapper<HTMLFormElement>(formEl
ement, v8Context->GetIsolate()); |
183 v8::Handle<v8::Object> documentWrapper = toObjectWrapper<Document>(m_node ?
m_node->ownerDocument() : 0, v8Context->GetIsolate()); | 183 v8::Handle<v8::Object> documentWrapper = toObjectWrapper<Document>(m_node ?
m_node->ownerDocument() : 0, v8Context->GetIsolate()); |
184 | 184 |
185 v8::Local<v8::Object> thisObject = v8::Object::New(); | 185 v8::Local<v8::Object> thisObject = v8::Object::New(); |
186 if (thisObject.IsEmpty()) | 186 if (thisObject.IsEmpty()) |
187 return; | 187 return; |
188 if (!thisObject->ForceSet(v8Integer(0, v8Context->GetIsolate()), nodeWrapper
)) | 188 if (!thisObject->ForceSet(deprecatedV8Integer(0), nodeWrapper)) |
189 return; | 189 return; |
190 if (!thisObject->ForceSet(v8Integer(1, v8Context->GetIsolate()), formWrapper
)) | 190 if (!thisObject->ForceSet(deprecatedV8Integer(1), formWrapper)) |
191 return; | 191 return; |
192 if (!thisObject->ForceSet(v8Integer(2, v8Context->GetIsolate()), documentWra
pper)) | 192 if (!thisObject->ForceSet(deprecatedV8Integer(2), documentWrapper)) |
193 return; | 193 return; |
194 | 194 |
195 // FIXME: Remove this code when we stop doing the 'with' hack above. | 195 // FIXME: Remove this code when we stop doing the 'with' hack above. |
196 v8::Local<v8::Value> innerValue; | 196 v8::Local<v8::Value> innerValue; |
197 { | 197 { |
198 V8RecursionScope::MicrotaskSuppression scope; | 198 V8RecursionScope::MicrotaskSuppression scope; |
199 innerValue = intermediateFunction->Call(thisObject, 0, 0); | 199 innerValue = intermediateFunction->Call(thisObject, 0, 0); |
200 } | 200 } |
201 if (innerValue.IsEmpty() || !innerValue->IsFunction()) | 201 if (innerValue.IsEmpty() || !innerValue->IsFunction()) |
202 return; | 202 return; |
(...skipping 10 matching lines...) Expand all Loading... |
213 // returned. | 213 // returned. |
214 v8::Persistent<v8::FunctionTemplate>& toStringTemplate = | 214 v8::Persistent<v8::FunctionTemplate>& toStringTemplate = |
215 V8PerIsolateData::current()->lazyEventListenerToStringTemplate(); | 215 V8PerIsolateData::current()->lazyEventListenerToStringTemplate(); |
216 if (toStringTemplate.IsEmpty()) | 216 if (toStringTemplate.IsEmpty()) |
217 toStringTemplate = v8::Persistent<v8::FunctionTemplate>::New(v8::Functio
nTemplate::New(V8LazyEventListenerToString)); | 217 toStringTemplate = v8::Persistent<v8::FunctionTemplate>::New(v8::Functio
nTemplate::New(V8LazyEventListenerToString)); |
218 v8::Local<v8::Function> toStringFunction; | 218 v8::Local<v8::Function> toStringFunction; |
219 if (!toStringTemplate.IsEmpty()) | 219 if (!toStringTemplate.IsEmpty()) |
220 toStringFunction = toStringTemplate->GetFunction(); | 220 toStringFunction = toStringTemplate->GetFunction(); |
221 if (!toStringFunction.IsEmpty()) { | 221 if (!toStringFunction.IsEmpty()) { |
222 String toStringString = "function " + m_functionName + "(" + m_eventPara
meterName + ") {\n " + m_code + "\n}"; | 222 String toStringString = "function " + m_functionName + "(" + m_eventPara
meterName + ") {\n " + m_code + "\n}"; |
223 wrappedFunction->SetHiddenValue(V8HiddenPropertyName::toStringString(),
v8String(toStringString, v8Context->GetIsolate())); | 223 wrappedFunction->SetHiddenValue(V8HiddenPropertyName::toStringString(),
deprecatedV8String(toStringString)); |
224 wrappedFunction->Set(v8::String::NewSymbol("toString"), toStringFunction
); | 224 wrappedFunction->Set(v8::String::NewSymbol("toString"), toStringFunction
); |
225 } | 225 } |
226 | 226 |
227 wrappedFunction->SetName(v8String(m_functionName, v8Context->GetIsolate())); | 227 wrappedFunction->SetName(deprecatedV8String(m_functionName)); |
228 | 228 |
229 // FIXME: Remove the following comment-outs. | 229 // FIXME: Remove the following comment-outs. |
230 // See https://bugs.webkit.org/show_bug.cgi?id=85152 for more details. | 230 // See https://bugs.webkit.org/show_bug.cgi?id=85152 for more details. |
231 // | 231 // |
232 // For the time being, we comment out the following code since the | 232 // For the time being, we comment out the following code since the |
233 // second parsing can happen. | 233 // second parsing can happen. |
234 // // Since we only parse once, there's no need to keep data used for parsin
g around anymore. | 234 // // Since we only parse once, there's no need to keep data used for parsin
g around anymore. |
235 // m_functionName = String(); | 235 // m_functionName = String(); |
236 // m_code = String(); | 236 // m_code = String(); |
237 // m_eventParameterName = String(); | 237 // m_eventParameterName = String(); |
238 // m_sourceURL = String(); | 238 // m_sourceURL = String(); |
239 | 239 |
240 setListenerObject(wrappedFunction); | 240 setListenerObject(wrappedFunction); |
241 } | 241 } |
242 | 242 |
243 } // namespace WebCore | 243 } // namespace WebCore |
OLD | NEW |