Changeset 43289 in webkit


Ignore:
Timestamp:
May 6, 2009 1:25:21 AM (15 years ago)
Author:
eric@webkit.org
Message:

2009-05-06 Soren Gjesse <sgjesse@chromium.org>

Reviewed by Eric Seidel.

Changed the toString behaviour for non document dom node event handlers in the V8 bindings.
https://bugs.webkit.org/show_bug.cgi?id=25544

In the V8 bindings non document dom node event handlers are wrapped in a number of with blocks and uses an inner
function. This causes the default toString on such a handler to return all this wrapper code. As some web sites
use the source of an event handler to create new functions this wrapper code causes compatibility problems.

Create a specific toString function for these handlers which will return a function source compatible with the
source returned by the JSC bindings and other browsers.

Test: fast/events/event-function-toString.html

  • bindings/v8/ScriptEventListener.cpp: (WebCore::createAttributeEventListener):
  • bindings/v8/V8LazyEventListener.cpp: (WebCore::V8LazyEventListener::V8LazyEventListener): (WebCore::V8LazyEventListener::getListenerFunction): (WebCore::V8LazyEventListenerToString): (WebCore::V8LazyEventListener::getWrappedListenerFunction):
  • bindings/v8/V8LazyEventListener.h: (WebCore::V8LazyEventListener::create):
Location:
trunk
Files:
3 added
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r43286 r43289  
     12009-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
    1122009-05-06  Dan Bernstein  <mitz@apple.com>
    213
  • trunk/WebCore/ChangeLog

    r43288 r43289  
     12009-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
    1272009-05-06  Tor Arne Vestbø  <tor.arne.vestbo@nokia.com>
    228
  • trunk/WebCore/bindings/v8/ScriptEventListener.cpp

    r42843 r43289  
    4747        return 0;
    4848
    49     return V8LazyEventListener::create(frame, attr->value(), attr->localName().string());
     49    return V8LazyEventListener::create(frame, attr->value(), attr->localName().string(), node->isSVGElement());
    5050}
    5151
     
    5555        return 0;
    5656
    57     return V8LazyEventListener::create(frame, attr->value(), attr->localName().string());
     57    return V8LazyEventListener::create(frame, attr->value(), attr->localName().string(), frame->document()->isSVGDocument());
    5858}
    5959
  • trunk/WebCore/bindings/v8/V8LazyEventListener.cpp

    r41880 r43289  
    3838namespace WebCore {
    3939
    40 V8LazyEventListener::V8LazyEventListener(Frame *frame, const String& code, const String& functionName)
     40V8LazyEventListener::V8LazyEventListener(Frame *frame, const String& code, const String& functionName, bool isSVGEvent)
    4141    : V8AbstractEventListener(frame, true)
    4242    , m_code(code)
    4343    , m_functionName(functionName)
     44    , m_isSVGEvent(isSVGEvent)
    4445    , m_compiled(false)
    4546    , m_wrappedFunctionCompiled(false)
     
    9495        //
    9596        // 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  ";
    9798        code.append(m_code);
    9899        code.append("\n})");
     
    133134    return proxy->CallFunction(handlerFunction, receiver, 1, parameters);
    134135}
     136
     137
     138static v8::Handle<v8::Value> V8LazyEventListenerToString(const v8::Arguments& args)
     139{
     140    return args.Callee()->GetHiddenValue(v8::String::New("toStringString"));
     141}
     142
    135143
    136144v8::Local<v8::Function> V8LazyEventListener::getWrappedListenerFunction()
     
    184192
    185193                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
    186214#ifndef NDEBUG
    187215                V8Proxy::RegisterGlobalHandle(EVENT_LISTENER, this, m_wrappedFunction);
  • trunk/WebCore/bindings/v8/V8LazyEventListener.h

    r42838 r43289  
    4646    class V8LazyEventListener : public V8AbstractEventListener {
    4747    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)
    4949        {
    50             return adoptRef(new V8LazyEventListener(frame, code, functionName));
     50            return adoptRef(new V8LazyEventListener(frame, code, functionName, isSVGEvent));
    5151        }
    5252
     
    5656
    5757    private:
    58         V8LazyEventListener(Frame*, const String& code, const String& functionName);
     58        V8LazyEventListener(Frame*, const String& code, const String& functionName, bool isSVGEvent);
    5959        virtual ~V8LazyEventListener();
    6060
     
    6363        String m_code;
    6464        String m_functionName;
     65        bool m_isSVGEvent;
    6566        bool m_compiled;
    6667
Note: See TracChangeset for help on using the changeset viewer.