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 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
130 // We do this by using 'with' statement. | 130 // We do this by using 'with' statement. |
131 // See chrome/fast/forms/form-action.html | 131 // See chrome/fast/forms/form-action.html |
132 // chrome/fast/forms/selected-index-value.html | 132 // chrome/fast/forms/selected-index-value.html |
133 // base/fast/overflow/onscroll-layer-self-destruct.html | 133 // base/fast/overflow/onscroll-layer-self-destruct.html |
134 // | 134 // |
135 // Don't use new lines so that lines in the modified handler | 135 // Don't use new lines so that lines in the modified handler |
136 // have the same numbers as in the original code. | 136 // have the same numbers as in the original code. |
137 // FIXME: V8 does not allow us to programmatically create object environment
s so | 137 // FIXME: V8 does not allow us to programmatically create object environment
s so |
138 // we have to do this hack! What if m_code escapes to run arbitrary s
cript? | 138 // we have to do this hack! What if m_code escapes to run arbitrary s
cript? |
139 // | 139 // |
| 140 // Call with 4 arguments instead of 3, pass additional null as the last para
meter. |
| 141 // By calling the function with 4 arguments, we create a setter on arguments
object |
| 142 // which would shadow property "3" on the prototype. |
140 String code = "(function() {" \ | 143 String code = "(function() {" \ |
141 "with (arguments[2]) {" \ | 144 "arguments[3] = function() {" \ |
142 "with (arguments[1]) {" \ | 145 "with (this[2]) {" \ |
143 "with (arguments[0]) {"; | 146 "with (this[1]) {" \ |
| 147 "with (this[0]) {"; |
144 code.append("return function("); | 148 code.append("return function("); |
145 code.append(m_eventParameterName); | 149 code.append(m_eventParameterName); |
146 code.append(") {"); | 150 code.append(") {"); |
147 code.append(m_code); | 151 code.append(m_code); |
148 // Insert '\n' otherwise //-style comments could break the handler. | 152 // Insert '\n' otherwise //-style comments could break the handler. |
149 code.append("\n};}}}})"); | 153 code.append("\n};}}}};"); |
| 154 code.append("return arguments[3]();})"); |
150 v8::Handle<v8::String> codeExternalString = v8ExternalString(code); | 155 v8::Handle<v8::String> codeExternalString = v8ExternalString(code); |
151 | 156 |
152 v8::Handle<v8::Script> script = V8Proxy::compileScript(codeExternalString, m
_sourceURL, m_position); | 157 v8::Handle<v8::Script> script = V8Proxy::compileScript(codeExternalString, m
_sourceURL, m_position); |
153 if (script.IsEmpty()) | 158 if (script.IsEmpty()) |
154 return; | 159 return; |
155 | 160 |
156 // FIXME: Remove this code when we stop doing the 'with' hack above. | 161 // FIXME: Remove this code when we stop doing the 'with' hack above. |
157 v8::Local<v8::Value> value; | 162 v8::Local<v8::Value> value; |
158 { | 163 { |
159 V8RecursionScope::MicrotaskSuppression scope; | 164 V8RecursionScope::MicrotaskSuppression scope; |
160 value = script->Run(); | 165 value = script->Run(); |
161 } | 166 } |
162 if (value.IsEmpty()) | 167 if (value.IsEmpty()) |
163 return; | 168 return; |
164 | 169 |
165 // Call the outer function to get the inner function. | 170 // Call the outer function to get the inner function. |
166 ASSERT(value->IsFunction()); | 171 ASSERT(value->IsFunction()); |
167 v8::Local<v8::Function> intermediateFunction = value.As<v8::Function>(); | 172 v8::Local<v8::Function> intermediateFunction = value.As<v8::Function>(); |
168 | 173 |
169 HTMLFormElement* formElement = 0; | 174 HTMLFormElement* formElement = 0; |
170 if (m_node && m_node->isHTMLElement()) | 175 if (m_node && m_node->isHTMLElement()) |
171 formElement = static_cast<HTMLElement*>(m_node)->form(); | 176 formElement = static_cast<HTMLElement*>(m_node)->form(); |
172 | 177 |
173 v8::Handle<v8::Object> nodeWrapper = toObjectWrapper<Node>(m_node); | 178 v8::Handle<v8::Object> nodeWrapper = toObjectWrapper<Node>(m_node); |
174 v8::Handle<v8::Object> formWrapper = toObjectWrapper<HTMLFormElement>(formEl
ement); | 179 v8::Handle<v8::Object> formWrapper = toObjectWrapper<HTMLFormElement>(formEl
ement); |
175 v8::Handle<v8::Object> documentWrapper = toObjectWrapper<Document>(m_node ?
m_node->ownerDocument() : 0); | 180 v8::Handle<v8::Object> documentWrapper = toObjectWrapper<Document>(m_node ?
m_node->ownerDocument() : 0); |
176 | 181 |
177 v8::Handle<v8::Value> parameters[3] = { nodeWrapper, formWrapper, documentWr
apper }; | 182 v8::Handle<v8::Value> parameters[4] = { nodeWrapper, formWrapper, documentWr
apper, v8::Handle<v8::Value>(v8::Null()) }; |
178 | 183 |
179 // FIXME: Remove this code when we stop doing the 'with' hack above. | 184 // FIXME: Remove this code when we stop doing the 'with' hack above. |
180 v8::Local<v8::Value> innerValue; | 185 v8::Local<v8::Value> innerValue; |
181 { | 186 { |
182 V8RecursionScope::MicrotaskSuppression scope; | 187 V8RecursionScope::MicrotaskSuppression scope; |
183 innerValue = intermediateFunction->Call(v8Context->Global(), 3, paramete
rs); | 188 innerValue = intermediateFunction->Call(v8Context->Global(), 3, paramete
rs); |
184 } | 189 } |
185 if (innerValue.IsEmpty() || !innerValue->IsFunction()) | 190 if (innerValue.IsEmpty() || !innerValue->IsFunction()) |
186 return; | 191 return; |
187 | 192 |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
224 // // Since we only parse once, there's no need to keep data used for parsin
g around anymore. | 229 // // Since we only parse once, there's no need to keep data used for parsin
g around anymore. |
225 // m_functionName = String(); | 230 // m_functionName = String(); |
226 // m_code = String(); | 231 // m_code = String(); |
227 // m_eventParameterName = String(); | 232 // m_eventParameterName = String(); |
228 // m_sourceURL = String(); | 233 // m_sourceURL = String(); |
229 | 234 |
230 setListenerObject(wrappedFunction); | 235 setListenerObject(wrappedFunction); |
231 } | 236 } |
232 | 237 |
233 } // namespace WebCore | 238 } // namespace WebCore |
OLD | NEW |