Changeset 43289 in webkit
- Timestamp:
- May 6, 2009 1:25:21 AM (15 years ago)
- Location:
- trunk
- Files:
-
- 3 added
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/LayoutTests/ChangeLog
r43286 r43289 1 2009-05-06 Soren Gjesse <sgjesse@chromium.org> 2 3 Reviewed by Eric Seidel. 4 5 Changed the toString behaviour for non document dom node event handlers in the V8 bindings. 6 https://bugs.webkit.org/show_bug.cgi?id=25544 7 8 * fast/events/event-function-toString.html: Added. 9 * fast/events/resources/event-function-toString.js: Added. 10 (normalizedFunctionString): 11 1 12 2009-05-06 Dan Bernstein <mitz@apple.com> 2 13 -
trunk/WebCore/ChangeLog
r43288 r43289 1 2009-05-06 Soren Gjesse <sgjesse@chromium.org> 2 3 Reviewed by Eric Seidel. 4 5 Changed the toString behaviour for non document dom node event handlers in the V8 bindings. 6 https://bugs.webkit.org/show_bug.cgi?id=25544 7 8 In the V8 bindings non document dom node event handlers are wrapped in a number of with blocks and uses an inner 9 function. This causes the default toString on such a handler to return all this wrapper code. As some web sites 10 use the source of an event handler to create new functions this wrapper code causes compatibility problems. 11 12 Create a specific toString function for these handlers which will return a function source compatible with the 13 source returned by the JSC bindings and other browsers. 14 15 Test: fast/events/event-function-toString.html 16 17 * bindings/v8/ScriptEventListener.cpp: 18 (WebCore::createAttributeEventListener): 19 * bindings/v8/V8LazyEventListener.cpp: 20 (WebCore::V8LazyEventListener::V8LazyEventListener): 21 (WebCore::V8LazyEventListener::getListenerFunction): 22 (WebCore::V8LazyEventListenerToString): 23 (WebCore::V8LazyEventListener::getWrappedListenerFunction): 24 * bindings/v8/V8LazyEventListener.h: 25 (WebCore::V8LazyEventListener::create): 26 1 27 2009-05-06 Tor Arne Vestbø <tor.arne.vestbo@nokia.com> 2 28 -
trunk/WebCore/bindings/v8/ScriptEventListener.cpp
r42843 r43289 47 47 return 0; 48 48 49 return V8LazyEventListener::create(frame, attr->value(), attr->localName().string() );49 return V8LazyEventListener::create(frame, attr->value(), attr->localName().string(), node->isSVGElement()); 50 50 } 51 51 … … 55 55 return 0; 56 56 57 return V8LazyEventListener::create(frame, attr->value(), attr->localName().string() );57 return V8LazyEventListener::create(frame, attr->value(), attr->localName().string(), frame->document()->isSVGDocument()); 58 58 } 59 59 -
trunk/WebCore/bindings/v8/V8LazyEventListener.cpp
r41880 r43289 38 38 namespace WebCore { 39 39 40 V8LazyEventListener::V8LazyEventListener(Frame *frame, const String& code, const String& functionName )40 V8LazyEventListener::V8LazyEventListener(Frame *frame, const String& code, const String& functionName, bool isSVGEvent) 41 41 : V8AbstractEventListener(frame, true) 42 42 , m_code(code) 43 43 , m_functionName(functionName) 44 , m_isSVGEvent(isSVGEvent) 44 45 , m_compiled(false) 45 46 , m_wrappedFunctionCompiled(false) … … 94 95 // 95 96 // The ECMAScript spec says (very obliquely) that the parameter to an event handler is named "evt". 96 String code = "(function (evt) {\n ";97 String code = "(function (evt) {\n "; 97 98 code.append(m_code); 98 99 code.append("\n})"); … … 133 134 return proxy->CallFunction(handlerFunction, receiver, 1, parameters); 134 135 } 136 137 138 static v8::Handle<v8::Value> V8LazyEventListenerToString(const v8::Arguments& args) 139 { 140 return args.Callee()->GetHiddenValue(v8::String::New("toStringString")); 141 } 142 135 143 136 144 v8::Local<v8::Function> V8LazyEventListener::getWrappedListenerFunction() … … 184 192 185 193 m_wrappedFunction = v8::Persistent<v8::Function>::New(v8::Local<v8::Function>::Cast(value)); 194 195 // Change the toString function on the wrapper function to avoid it returning the source for the actual wrapper function. Instead 196 // it returns source for a clean wrapper function with the event argument wrapping the event source code. The reason for this 197 // is that some web sites uses toString on event functions and the evals the source returned (some times a RegExp is applied as 198 // well) for some other use. That fails miserably if the actual wrapper source is returned. 199 v8::Local<v8::FunctionTemplate> toStringTemplate = v8::FunctionTemplate::New(V8LazyEventListenerToString); 200 v8::Local<v8::Function> toStringFunction = toStringTemplate->GetFunction(); 201 String toStringResult = "function "; 202 toStringResult.append(m_functionName); 203 toStringResult.append("("); 204 if (m_isSVGEvent) 205 toStringResult.append("evt"); 206 else 207 toStringResult.append("event"); 208 toStringResult.append(") {\n "); 209 toStringResult.append(m_code); 210 toStringResult.append( "\n}"); 211 toStringFunction->SetHiddenValue(v8::String::New("toStringString"), v8ExternalString(toStringResult)); 212 m_wrappedFunction->Set(v8::String::New("toString"), toStringFunction); 213 186 214 #ifndef NDEBUG 187 215 V8Proxy::RegisterGlobalHandle(EVENT_LISTENER, this, m_wrappedFunction); -
trunk/WebCore/bindings/v8/V8LazyEventListener.h
r42838 r43289 46 46 class V8LazyEventListener : public V8AbstractEventListener { 47 47 public: 48 static PassRefPtr<V8LazyEventListener> create(Frame* frame, const String& code, const String& functionName )48 static PassRefPtr<V8LazyEventListener> create(Frame* frame, const String& code, const String& functionName, bool isSVGEvent) 49 49 { 50 return adoptRef(new V8LazyEventListener(frame, code, functionName ));50 return adoptRef(new V8LazyEventListener(frame, code, functionName, isSVGEvent)); 51 51 } 52 52 … … 56 56 57 57 private: 58 V8LazyEventListener(Frame*, const String& code, const String& functionName );58 V8LazyEventListener(Frame*, const String& code, const String& functionName, bool isSVGEvent); 59 59 virtual ~V8LazyEventListener(); 60 60 … … 63 63 String m_code; 64 64 String m_functionName; 65 bool m_isSVGEvent; 65 66 bool m_compiled; 66 67
Note: See TracChangeset
for help on using the changeset viewer.