Changeset 58330 in webkit


Ignore:
Timestamp:
Apr 27, 2010 1:26:16 PM (14 years ago)
Author:
abarth@webkit.org
Message:

2010-04-27 Adam Barth <abarth@webkit.org>

Reviewed by Darin Adler.

Remove copy/paste addEventListener "custom" bindings via code generation
https://bugs.webkit.org/show_bug.cgi?id=38210

It's somewhat lame to special case addEventListener and
removeEventListener in the code generator, but it saves a large amount
of boilerplate "custom" bindings code.

Idea shamelessly stolen from the V8 code generator.

This patch points to some good refactoring opportunities in
CodeGeneratorJS.pm, but I'm going to hold off on those for a future
patch. By generating test coverage for the code generator, we make
these future refactorings easier.

  • bindings/js/JSAbstractWorkerCustom.cpp:
  • bindings/js/JSDOMApplicationCacheCustom.cpp:
  • bindings/js/JSDesktopNotificationsCustom.cpp:
  • bindings/js/JSEventSourceCustom.cpp:
  • bindings/js/JSMessagePortCustom.cpp:
  • bindings/js/JSNodeCustom.cpp:
  • bindings/js/JSSVGElementInstanceCustom.cpp:
  • bindings/js/JSWebSocketCustom.cpp:
  • bindings/js/JSWorkerContextCustom.cpp:
  • bindings/js/JSXMLHttpRequestCustom.cpp:
  • bindings/js/JSXMLHttpRequestUploadCustom.cpp:
  • bindings/scripts/CodeGeneratorJS.pm:
  • bindings/scripts/test/GObject/WebKitDOMTestObj.cpp:
  • bindings/scripts/test/GObject/WebKitDOMTestObj.h:
  • bindings/scripts/test/JS/JSTestObj.cpp: (WebCore::): (WebCore::jsTestObjPrototypeFunctionAddEventListener): (WebCore::jsTestObjPrototypeFunctionRemoveEventListener):
  • bindings/scripts/test/JS/JSTestObj.h:
  • bindings/scripts/test/ObjC/DOMTestObj.h:
  • bindings/scripts/test/ObjC/DOMTestObj.mm: (-[DOMTestObj addEventListener:listener:useCapture:]): (-[DOMTestObj removeEventListener:listener:useCapture:]):
  • bindings/scripts/test/TestObj.idl:
  • bindings/scripts/test/V8/V8TestObj.cpp: (WebCore::TestObjInternal::addEventListenerCallback): (WebCore::TestObjInternal::removeEventListenerCallback): (WebCore::):
  • dom/MessagePort.idl:
  • dom/Node.idl:
  • loader/appcache/DOMApplicationCache.idl:
  • notifications/Notification.idl:
  • page/EventSource.idl:
  • svg/SVGElementInstance.idl:
  • websockets/WebSocket.idl:
  • workers/AbstractWorker.idl:
  • workers/WorkerContext.idl:
  • xml/XMLHttpRequest.idl:
  • xml/XMLHttpRequestUpload.idl:
Location:
trunk/WebCore
Files:
32 edited

Legend:

Unmodified
Added
Removed
  • trunk/WebCore/ChangeLog

    r58324 r58330  
     12010-04-27  Adam Barth  <abarth@webkit.org>
     2
     3        Reviewed by Darin Adler.
     4
     5        Remove copy/paste addEventListener "custom" bindings via code generation
     6        https://bugs.webkit.org/show_bug.cgi?id=38210
     7
     8        It's somewhat lame to special case addEventListener and
     9        removeEventListener in the code generator, but it saves a large amount
     10        of boilerplate "custom" bindings code.
     11
     12        Idea shamelessly stolen from the V8 code generator.
     13
     14        This patch points to some good refactoring opportunities in
     15        CodeGeneratorJS.pm, but I'm going to hold off on those for a future
     16        patch.  By generating test coverage for the code generator, we make
     17        these future refactorings easier.
     18
     19        * bindings/js/JSAbstractWorkerCustom.cpp:
     20        * bindings/js/JSDOMApplicationCacheCustom.cpp:
     21        * bindings/js/JSDesktopNotificationsCustom.cpp:
     22        * bindings/js/JSEventSourceCustom.cpp:
     23        * bindings/js/JSMessagePortCustom.cpp:
     24        * bindings/js/JSNodeCustom.cpp:
     25        * bindings/js/JSSVGElementInstanceCustom.cpp:
     26        * bindings/js/JSWebSocketCustom.cpp:
     27        * bindings/js/JSWorkerContextCustom.cpp:
     28        * bindings/js/JSXMLHttpRequestCustom.cpp:
     29        * bindings/js/JSXMLHttpRequestUploadCustom.cpp:
     30        * bindings/scripts/CodeGeneratorJS.pm:
     31        * bindings/scripts/test/GObject/WebKitDOMTestObj.cpp:
     32        * bindings/scripts/test/GObject/WebKitDOMTestObj.h:
     33        * bindings/scripts/test/JS/JSTestObj.cpp:
     34        (WebCore::):
     35        (WebCore::jsTestObjPrototypeFunctionAddEventListener):
     36        (WebCore::jsTestObjPrototypeFunctionRemoveEventListener):
     37        * bindings/scripts/test/JS/JSTestObj.h:
     38        * bindings/scripts/test/ObjC/DOMTestObj.h:
     39        * bindings/scripts/test/ObjC/DOMTestObj.mm:
     40        (-[DOMTestObj addEventListener:listener:useCapture:]):
     41        (-[DOMTestObj removeEventListener:listener:useCapture:]):
     42        * bindings/scripts/test/TestObj.idl:
     43        * bindings/scripts/test/V8/V8TestObj.cpp:
     44        (WebCore::TestObjInternal::addEventListenerCallback):
     45        (WebCore::TestObjInternal::removeEventListenerCallback):
     46        (WebCore::):
     47        * dom/MessagePort.idl:
     48        * dom/Node.idl:
     49        * loader/appcache/DOMApplicationCache.idl:
     50        * notifications/Notification.idl:
     51        * page/EventSource.idl:
     52        * svg/SVGElementInstance.idl:
     53        * websockets/WebSocket.idl:
     54        * workers/AbstractWorker.idl:
     55        * workers/WorkerContext.idl:
     56        * xml/XMLHttpRequest.idl:
     57        * xml/XMLHttpRequestUpload.idl:
     58
    1592010-04-27  Sam Weinig  <sam@webkit.org>
    260
  • trunk/WebCore/bindings/js/JSAbstractWorkerCustom.cpp

    r57766 r58330  
    4545namespace WebCore {
    4646
    47 JSValue JSAbstractWorker::addEventListener(ExecState* exec, const ArgList& args)
    48 {
    49     JSValue listener = args.at(1);
    50     if (!listener.isObject())
    51         return jsUndefined();
    52 
    53     impl()->addEventListener(ustringToAtomicString(args.at(0).toString(exec)), JSEventListener::create(asObject(listener), this, false, currentWorld(exec)), args.at(2).toBoolean(exec));
    54     return jsUndefined();
    55 }
    56 
    57 JSValue JSAbstractWorker::removeEventListener(ExecState* exec, const ArgList& args)
    58 {
    59     JSValue listener = args.at(1);
    60     if (!listener.isObject())
    61         return jsUndefined();
    62 
    63     impl()->removeEventListener(ustringToAtomicString(args.at(0).toString(exec)), JSEventListener::create(asObject(listener), this, false, currentWorld(exec)).get(), args.at(2).toBoolean(exec));
    64     return jsUndefined();
    65 }
     47// FIXME: Remove this file.
    6648
    6749} // namespace WebCore
  • trunk/WebCore/bindings/js/JSDOMApplicationCacheCustom.cpp

    r57766 r58330  
    8686#endif // ENABLE(APPLICATION_CACHE_DYNAMIC_ENTRIES)
    8787
    88 JSValue JSDOMApplicationCache::addEventListener(ExecState* exec, const ArgList& args)
    89 {
    90     JSValue listener = args.at(1);
    91     if (!listener.isObject())
    92         return jsUndefined();
    93 
    94     impl()->addEventListener(ustringToAtomicString(args.at(0).toString(exec)), JSEventListener::create(asObject(listener), this, false, currentWorld(exec)), args.at(2).toBoolean(exec));
    95     return jsUndefined();
    96 }
    97 
    98 JSValue JSDOMApplicationCache::removeEventListener(ExecState* exec, const ArgList& args)
    99 {
    100     JSValue listener = args.at(1);
    101     if (!listener.isObject())
    102         return jsUndefined();
    103 
    104     impl()->removeEventListener(ustringToAtomicString(args.at(0).toString(exec)), JSEventListener::create(asObject(listener), this, false, currentWorld(exec)).get(), args.at(2).toBoolean(exec));
    105     return jsUndefined();
    106 }
    107 
    10888} // namespace WebCore
    10989
  • trunk/WebCore/bindings/js/JSDesktopNotificationsCustom.cpp

    r57769 r58330  
    6262}
    6363
    64 JSValue JSNotification::addEventListener(ExecState* exec, const ArgList& args)
    65 {
    66     JSValue listener = args.at(1);
    67     if (!listener.isObject())
    68         return jsUndefined();
    69 
    70     impl()->addEventListener(ustringToAtomicString(args.at(0).toString(exec)), JSEventListener::create(asObject(listener), this, false, currentWorld(exec)), args.at(2).toBoolean(exec));
    71     return jsUndefined();
    72 }
    73 
    74 JSValue JSNotification::removeEventListener(ExecState* exec, const ArgList& args)
    75 {
    76     JSValue listener = args.at(1);
    77     if (!listener.isObject())
    78         return jsUndefined();
    79 
    80     impl()->removeEventListener(ustringToAtomicString(args.at(0).toString(exec)), JSEventListener::create(asObject(listener), this, false, currentWorld(exec)).get(), args.at(2).toBoolean(exec));
    81     return jsUndefined();
    82 }
    83 
    84 
    8564} // namespace
    8665
  • trunk/WebCore/bindings/js/JSEventSourceCustom.cpp

    r57766 r58330  
    4444namespace WebCore {
    4545
    46 JSValue JSEventSource::addEventListener(ExecState* exec, const ArgList& args)
    47 {
    48     JSValue listener = args.at(1);
    49     if (!listener.isObject())
    50         return jsUndefined();
    51 
    52     impl()->addEventListener(ustringToAtomicString(args.at(0).toString(exec)), JSEventListener::create(asObject(listener), this, false, currentWorld(exec)).get(), args.at(2).toBoolean(exec));
    53     return jsUndefined();
    54 }
    55 
    56 JSValue JSEventSource::removeEventListener(ExecState* exec, const ArgList& args)
    57 {
    58     JSValue listener = args.at(1);
    59     if (!listener.isObject())
    60         return jsUndefined();
    61 
    62     impl()->removeEventListener(ustringToAtomicString(args.at(0).toString(exec)), JSEventListener::create(asObject(listener), this, false, currentWorld(exec)).get(), args.at(2).toBoolean(exec));
    63     return jsUndefined();
    64 }
     46// FIXME: Remove this file.
    6547
    6648} // namespace WebCore
  • trunk/WebCore/bindings/js/JSMessagePortCustom.cpp

    r57766 r58330  
    5353}
    5454
    55 JSValue JSMessagePort::addEventListener(ExecState* exec, const ArgList& args)
    56 {
    57     JSValue listener = args.at(1);
    58     if (!listener.isObject())
    59         return jsUndefined();
    60 
    61     impl()->addEventListener(ustringToAtomicString(args.at(0).toString(exec)), JSEventListener::create(asObject(listener), this, false, currentWorld(exec)).get(), args.at(2).toBoolean(exec));
    62     return jsUndefined();
    63 }
    64 
    65 JSValue JSMessagePort::removeEventListener(ExecState* exec, const ArgList& args)
    66 {
    67     JSValue listener = args.at(1);
    68     if (!listener.isObject())
    69         return jsUndefined();
    70 
    71     impl()->removeEventListener(ustringToAtomicString(args.at(0).toString(exec)), JSEventListener::create(asObject(listener), this, false, currentWorld(exec)).get(), args.at(2).toBoolean(exec));
    72     return jsUndefined();
    73 }
    74 
    7555JSC::JSValue JSMessagePort::postMessage(JSC::ExecState* exec, const JSC::ArgList& args)
    7656{
  • trunk/WebCore/bindings/js/JSNodeCustom.cpp

    r57766 r58330  
    170170}
    171171
    172 JSValue JSNode::addEventListener(ExecState* exec, const ArgList& args)
    173 {
    174     JSValue listener = args.at(1);
    175     if (!listener.isObject())
    176         return jsUndefined();
    177 
    178     impl()->addEventListener(ustringToAtomicString(args.at(0).toString(exec)), JSEventListener::create(asObject(listener), this, false, currentWorld(exec)), args.at(2).toBoolean(exec));
    179     return jsUndefined();
    180 }
    181 
    182 JSValue JSNode::removeEventListener(ExecState* exec, const ArgList& args)
    183 {
    184     JSValue listener = args.at(1);
    185     if (!listener.isObject())
    186         return jsUndefined();
    187 
    188     impl()->removeEventListener(ustringToAtomicString(args.at(0).toString(exec)), JSEventListener::create(asObject(listener), this, false, currentWorld(exec)).get(), args.at(2).toBoolean(exec));
    189     return jsUndefined();
    190 }
    191 
    192172void JSNode::pushEventHandlerScope(ExecState*, ScopeChain&) const
    193173{
  • trunk/WebCore/bindings/js/JSSVGElementInstanceCustom.cpp

    r57766 r58330  
    4747}
    4848
    49 JSValue JSSVGElementInstance::addEventListener(ExecState* exec, const ArgList& args)
    50 {
    51     JSValue listener = args.at(1);
    52     if (!listener.isObject())
    53         return jsUndefined();
    54 
    55     impl()->addEventListener(ustringToAtomicString(args.at(0).toString(exec)), JSEventListener::create(asObject(listener), this, false, currentWorld(exec)), args.at(2).toBoolean(exec));
    56     return jsUndefined();
    57 }
    58 
    59 JSValue JSSVGElementInstance::removeEventListener(ExecState* exec, const ArgList& args)
    60 {
    61     JSValue listener = args.at(1);
    62     if (!listener.isObject())
    63         return jsUndefined();
    64 
    65     impl()->removeEventListener(ustringToAtomicString(args.at(0).toString(exec)), JSEventListener::create(asObject(listener), this, false, currentWorld(exec)).get(), args.at(2).toBoolean(exec));
    66     return jsUndefined();
    67 }
    68 
    6949void JSSVGElementInstance::pushEventHandlerScope(ExecState*, ScopeChain&) const
    7050{
  • trunk/WebCore/bindings/js/JSWebSocketCustom.cpp

    r57766 r58330  
    6060}
    6161
    62 JSValue JSWebSocket::addEventListener(ExecState* exec, const ArgList& args)
    63 {
    64     JSValue listener = args.at(1);
    65     if (!listener.isObject())
    66         return jsUndefined();
    67 
    68     impl()->addEventListener(ustringToAtomicString(args.at(0).toString(exec)), JSEventListener::create(asObject(listener), this, false, currentWorld(exec)), args.at(2).toBoolean(exec));
    69     return jsUndefined();
    70 }
    71 
    72 JSValue JSWebSocket::removeEventListener(ExecState* exec, const ArgList& args)
    73 {
    74     JSValue listener = args.at(1);
    75     if (!listener.isObject())
    76         return jsUndefined();
    77 
    78     impl()->removeEventListener(ustringToAtomicString(args.at(0).toString(exec)), JSEventListener::create(asObject(listener), this, false, currentWorld(exec)).get(), args.at(2).toBoolean(exec));
    79     return jsUndefined();
    80 }
    81 
    8262}  // namespace WebCore
    8363
  • trunk/WebCore/bindings/js/JSWorkerContextCustom.cpp

    r57766 r58330  
    117117}
    118118
    119 JSValue JSWorkerContext::addEventListener(ExecState* exec, const ArgList& args)
    120 {
    121     JSValue listener = args.at(1);
    122     if (!listener.isObject())
    123         return jsUndefined();
    124 
    125     impl()->addEventListener(ustringToAtomicString(args.at(0).toString(exec)), JSEventListener::create(asObject(listener), this, false, currentWorld(exec)), args.at(2).toBoolean(exec));
    126     return jsUndefined();
    127 }
    128 
    129 JSValue JSWorkerContext::removeEventListener(ExecState* exec, const ArgList& args)
    130 {
    131     JSValue listener = args.at(1);
    132     if (!listener.isObject())
    133         return jsUndefined();
    134 
    135     impl()->removeEventListener(ustringToAtomicString(args.at(0).toString(exec)), JSEventListener::create(asObject(listener), this, false, currentWorld(exec)).get(), args.at(2).toBoolean(exec));
    136     return jsUndefined();
    137 }
    138 
    139119JSValue JSWorkerContext::setTimeout(ExecState* exec, const ArgList& args)
    140120{
  • trunk/WebCore/bindings/js/JSXMLHttpRequestCustom.cpp

    r57766 r58330  
    154154}
    155155
    156 JSValue JSXMLHttpRequest::addEventListener(ExecState* exec, const ArgList& args)
    157 {
    158     JSValue listener = args.at(1);
    159     if (!listener.isObject())
    160         return jsUndefined();
    161 
    162     impl()->addEventListener(ustringToAtomicString(args.at(0).toString(exec)), JSEventListener::create(asObject(listener), this, false, currentWorld(exec)), args.at(2).toBoolean(exec));
    163     return jsUndefined();
    164 }
    165 
    166 JSValue JSXMLHttpRequest::removeEventListener(ExecState* exec, const ArgList& args)
    167 {
    168     JSValue listener = args.at(1);
    169     if (!listener.isObject())
    170         return jsUndefined();
    171 
    172     impl()->removeEventListener(ustringToAtomicString(args.at(0).toString(exec)), JSEventListener::create(asObject(listener), this, false, currentWorld(exec)).get(), args.at(2).toBoolean(exec));
    173     return jsUndefined();
    174 }
    175 
    176156JSValue JSXMLHttpRequest::responseText(ExecState* exec) const
    177157{
  • trunk/WebCore/bindings/js/JSXMLHttpRequestUploadCustom.cpp

    r57766 r58330  
    5252}
    5353
    54 JSValue JSXMLHttpRequestUpload::addEventListener(ExecState* exec, const ArgList& args)
    55 {
    56     JSValue listener = args.at(1);
    57     if (!listener.isObject())
    58         return jsUndefined();
    59 
    60     impl()->addEventListener(ustringToAtomicString(args.at(0).toString(exec)), JSEventListener::create(asObject(listener), this, false, currentWorld(exec)), args.at(2).toBoolean(exec));
    61     return jsUndefined();
    62 }
    63 
    64 JSValue JSXMLHttpRequestUpload::removeEventListener(ExecState* exec, const ArgList& args)
    65 {
    66     JSValue listener = args.at(1);
    67     if (!listener.isObject())
    68         return jsUndefined();
    69 
    70     impl()->removeEventListener(ustringToAtomicString(args.at(0).toString(exec)), JSEventListener::create(asObject(listener), this, false, currentWorld(exec)).get(), args.at(2).toBoolean(exec));
    71     return jsUndefined();
    72 }
    73 
    7454} // namespace WebCore
  • trunk/WebCore/bindings/scripts/CodeGeneratorJS.pm

    r58298 r58330  
    120120        open($DEPS, ">$depsFileName") || die "Couldn't open file $depsFileName";
    121121    }
     122}
     123
     124sub GenerateEventListenerCall
     125{
     126    my $className = shift;
     127    my $functionName = shift;
     128    my $passRefPtrHandling = ($functionName eq "add") ? "" : ".get()";
     129
     130    $implIncludes{"JSEventListener.h"} = 1;
     131
     132    my @GenerateEventListenerImpl = ();
     133    push(@GenerateEventListenerImpl, <<END);
     134    JSValue listener = args.at(1);
     135    if (!listener.isObject())
     136        return jsUndefined();
     137    imp->${functionName}EventListener(ustringToAtomicString(args.at(0).toString(exec)), JSEventListener::create(asObject(listener), castedThisObj, false, currentWorld(exec))$passRefPtrHandling, args.at(2).toBoolean(exec));
     138    return jsUndefined();
     139END
     140    return @GenerateEventListenerImpl;
    122141}
    123142
     
    16941713                }
    16951714
    1696                 my $paramIndex = 0;
    1697                 my $functionString = ($podType ? "podImp." : "imp->") . $functionImplementationName . "(";
    1698 
    1699                 my $hasOptionalArguments = 0;
    1700 
    1701                 if ($function->signature->extendedAttributes->{"CustomArgumentHandling"}) {
    1702                     push(@implContent, "    ScriptCallStack callStack(exec, args, $numParameters);\n");
    1703                     $implIncludes{"ScriptCallStack.h"} = 1;
     1715                if ($function->signature->name eq "addEventListener") {
     1716                    push(@implContent, GenerateEventListenerCall($className, "add"));
     1717                } elsif ($function->signature->name eq "removeEventListener") {
     1718                    push(@implContent, GenerateEventListenerCall($className, "remove"));
     1719                } else {
     1720                    my $paramIndex = 0;
     1721                    my $functionString = ($podType ? "podImp." : "imp->") . $functionImplementationName . "(";
     1722
     1723                    my $hasOptionalArguments = 0;
     1724
     1725                    if ($function->signature->extendedAttributes->{"CustomArgumentHandling"}) {
     1726                        push(@implContent, "    ScriptCallStack callStack(exec, args, $numParameters);\n");
     1727                        $implIncludes{"ScriptCallStack.h"} = 1;
     1728                    }
     1729
     1730                    my $callWith = $function->signature->extendedAttributes->{"CallWith"};
     1731                    if ($callWith) {
     1732                        my $callWithArg = "COMPILE_ASSERT(false)";
     1733                        if ($callWith eq "DynamicFrame") {
     1734                            push(@implContent, "    Frame* dynamicFrame = toDynamicFrame(exec);\n");
     1735                            push(@implContent, "    if (!dynamicFrame)\n");
     1736                            push(@implContent, "        return jsUndefined();\n");
     1737                            $callWithArg = "dynamicFrame";
     1738                        } elsif ($callWith eq "ScriptState") {
     1739                            $callWithArg = "exec";
     1740                        }
     1741                        $functionString .= ", " if $paramIndex;
     1742                        $functionString .= $callWithArg;
     1743                        $paramIndex++;
     1744                    }
     1745
     1746                    foreach my $parameter (@{$function->parameters}) {
     1747                        if (!$hasOptionalArguments && $parameter->extendedAttributes->{"Optional"}) {
     1748                            push(@implContent, "\n    int argsCount = args.size();\n");
     1749                            $hasOptionalArguments = 1;
     1750                        }
     1751
     1752                        if ($hasOptionalArguments) {
     1753                            push(@implContent, "    if (argsCount < " . ($paramIndex + 1) . ") {\n");
     1754                            GenerateImplementationFunctionCall($function, $functionString, $paramIndex, "    " x 2, $podType, $implClassName);
     1755                            push(@implContent, "    }\n\n");
     1756                        }
     1757
     1758                        my $name = $parameter->name;
     1759                   
     1760                        if ($parameter->type eq "XPathNSResolver") {
     1761                            push(@implContent, "    RefPtr<XPathNSResolver> customResolver;\n");
     1762                            push(@implContent, "    XPathNSResolver* resolver = toXPathNSResolver(args.at($paramIndex));\n");
     1763                            push(@implContent, "    if (!resolver) {\n");
     1764                            push(@implContent, "        customResolver = JSCustomXPathNSResolver::create(exec, args.at($paramIndex));\n");
     1765                            push(@implContent, "        if (exec->hadException())\n");
     1766                            push(@implContent, "            return jsUndefined();\n");
     1767                            push(@implContent, "        resolver = customResolver.get();\n");
     1768                            push(@implContent, "    }\n");
     1769                        } else {
     1770                            push(@implContent, "    " . GetNativeTypeFromSignature($parameter) . " $name = " . JSValueToNative($parameter, "args.at($paramIndex)") . ";\n");
     1771
     1772                            # If a parameter is "an index" and it's negative it should throw an INDEX_SIZE_ERR exception.
     1773                            # But this needs to be done in the bindings, because the type is unsigned and the fact that it
     1774                            # was negative will be lost by the time we're inside the DOM.
     1775                            if ($parameter->extendedAttributes->{"IsIndex"}) {
     1776                                $implIncludes{"ExceptionCode.h"} = 1;
     1777                                push(@implContent, "    if ($name < 0) {\n");
     1778                                push(@implContent, "        setDOMException(exec, INDEX_SIZE_ERR);\n");
     1779                                push(@implContent, "        return jsUndefined();\n");
     1780                                push(@implContent, "    }\n");
     1781                            }
     1782                        }
     1783
     1784                        $functionString .= ", " if $paramIndex;
     1785
     1786                        if ($parameter->type eq "NodeFilter") {
     1787                            $functionString .= "$name.get()";
     1788                        } else {
     1789                            $functionString .= $name;
     1790                        }
     1791                        $paramIndex++;
     1792                    }
     1793
     1794                    if ($function->signature->extendedAttributes->{"NeedsUserGestureCheck"}) {
     1795                        $functionString .= ", " if $paramIndex;
     1796                        $functionString .= "processingUserGesture(exec)";
     1797                        $paramIndex++;
     1798                    }
     1799
     1800                    push(@implContent, "\n");
     1801                    GenerateImplementationFunctionCall($function, $functionString, $paramIndex, "    ", $podType, $implClassName);
    17041802                }
    1705 
    1706                 my $callWith = $function->signature->extendedAttributes->{"CallWith"};
    1707                 if ($callWith) {
    1708                     my $callWithArg = "COMPILE_ASSERT(false)";
    1709                     if ($callWith eq "DynamicFrame") {
    1710                         push(@implContent, "    Frame* dynamicFrame = toDynamicFrame(exec);\n");
    1711                         push(@implContent, "    if (!dynamicFrame)\n");
    1712                         push(@implContent, "        return jsUndefined();\n");
    1713                         $callWithArg = "dynamicFrame";
    1714                     } elsif ($callWith eq "ScriptState") {
    1715                         $callWithArg = "exec";
    1716                     }
    1717                     $functionString .= ", " if $paramIndex;
    1718                     $functionString .= $callWithArg;
    1719                     $paramIndex++;
    1720                 }
    1721 
    1722                 foreach my $parameter (@{$function->parameters}) {
    1723                     if (!$hasOptionalArguments && $parameter->extendedAttributes->{"Optional"}) {
    1724                         push(@implContent, "\n    int argsCount = args.size();\n");
    1725                         $hasOptionalArguments = 1;
    1726                     }
    1727 
    1728                     if ($hasOptionalArguments) {
    1729                         push(@implContent, "    if (argsCount < " . ($paramIndex + 1) . ") {\n");
    1730                         GenerateImplementationFunctionCall($function, $functionString, $paramIndex, "    " x 2, $podType, $implClassName);
    1731                         push(@implContent, "    }\n\n");
    1732                     }
    1733 
    1734                     my $name = $parameter->name;
    1735                    
    1736                     if ($parameter->type eq "XPathNSResolver") {
    1737                         push(@implContent, "    RefPtr<XPathNSResolver> customResolver;\n");
    1738                         push(@implContent, "    XPathNSResolver* resolver = toXPathNSResolver(args.at($paramIndex));\n");
    1739                         push(@implContent, "    if (!resolver) {\n");
    1740                         push(@implContent, "        customResolver = JSCustomXPathNSResolver::create(exec, args.at($paramIndex));\n");
    1741                         push(@implContent, "        if (exec->hadException())\n");
    1742                         push(@implContent, "            return jsUndefined();\n");
    1743                         push(@implContent, "        resolver = customResolver.get();\n");
    1744                         push(@implContent, "    }\n");
    1745                     } else {
    1746                         push(@implContent, "    " . GetNativeTypeFromSignature($parameter) . " $name = " . JSValueToNative($parameter, "args.at($paramIndex)") . ";\n");
    1747 
    1748                         # If a parameter is "an index" and it's negative it should throw an INDEX_SIZE_ERR exception.
    1749                         # But this needs to be done in the bindings, because the type is unsigned and the fact that it
    1750                         # was negative will be lost by the time we're inside the DOM.
    1751                         if ($parameter->extendedAttributes->{"IsIndex"}) {
    1752                             $implIncludes{"ExceptionCode.h"} = 1;
    1753                             push(@implContent, "    if ($name < 0) {\n");
    1754                             push(@implContent, "        setDOMException(exec, INDEX_SIZE_ERR);\n");
    1755                             push(@implContent, "        return jsUndefined();\n");
    1756                             push(@implContent, "    }\n");
    1757                         }
    1758                     }
    1759 
    1760                     $functionString .= ", " if $paramIndex;
    1761 
    1762                     if ($parameter->type eq "NodeFilter") {
    1763                         $functionString .= "$name.get()";
    1764                     } else {
    1765                         $functionString .= $name;
    1766                     }
    1767                     $paramIndex++;
    1768                 }
    1769 
    1770                 if ($function->signature->extendedAttributes->{"NeedsUserGestureCheck"}) {
    1771                     $functionString .= ", " if $paramIndex;
    1772                     $functionString .= "processingUserGesture(exec)";
    1773                     $paramIndex++;
    1774                 }
    1775 
    1776                 push(@implContent, "\n");
    1777                 GenerateImplementationFunctionCall($function, $functionString, $paramIndex, "    ", $podType, $implClassName);
    17781803            }
    17791804            push(@implContent, "}\n\n");
  • trunk/WebCore/bindings/scripts/test/GObject/WebKitDOMTestObj.cpp

    r58298 r58330  
    141141
    142142/* TODO: custom function webkit_dom_test_obj_custom_args_and_exception */
     143
     144
     145/* TODO: event function webkit_dom_test_obj_add_event_listener */
     146
     147
     148/* TODO: event function webkit_dom_test_obj_remove_event_listener */
    143149
    144150void
  • trunk/WebCore/bindings/scripts/test/GObject/WebKitDOMTestObj.h

    r58298 r58330  
    7070
    7171/* TODO: custom function webkit_dom_test_obj_custom_args_and_exception */
     72
     73
     74/* TODO: event function webkit_dom_test_obj_add_event_listener */
     75
     76
     77/* TODO: event function webkit_dom_test_obj_remove_event_listener */
    7278
    7379WEBKIT_API void
  • trunk/WebCore/bindings/scripts/test/JS/JSTestObj.cpp

    r58298 r58330  
    2222#include "JSTestObj.h"
    2323
     24#include "JSEventListener.h"
    2425#include "JSTestObj.h"
    2526#include "JSlog.h"
     
    129130#endif
    130131
    131 static const HashTableValue JSTestObjPrototypeTableValues[21] =
     132static const HashTableValue JSTestObjPrototypeTableValues[23] =
    132133{
    133134    { "voidMethod", DontDelete|Function, (intptr_t)static_cast<NativeFunction>(jsTestObjPrototypeFunctionVoidMethod), (intptr_t)0 THUNK_GENERATOR(0) },
     
    141142    { "customMethodWithArgs", DontDelete|Function, (intptr_t)static_cast<NativeFunction>(jsTestObjPrototypeFunctionCustomMethodWithArgs), (intptr_t)3 THUNK_GENERATOR(0) },
    142143    { "customArgsAndException", DontDelete|Function, (intptr_t)static_cast<NativeFunction>(jsTestObjPrototypeFunctionCustomArgsAndException), (intptr_t)1 THUNK_GENERATOR(0) },
     144    { "addEventListener", DontDelete|Function, (intptr_t)static_cast<NativeFunction>(jsTestObjPrototypeFunctionAddEventListener), (intptr_t)3 THUNK_GENERATOR(0) },
     145    { "removeEventListener", DontDelete|Function, (intptr_t)static_cast<NativeFunction>(jsTestObjPrototypeFunctionRemoveEventListener), (intptr_t)3 THUNK_GENERATOR(0) },
    143146    { "withDynamicFrame", DontDelete|Function, (intptr_t)static_cast<NativeFunction>(jsTestObjPrototypeFunctionWithDynamicFrame), (intptr_t)0 THUNK_GENERATOR(0) },
    144147    { "withDynamicFrameAndArg", DontDelete|Function, (intptr_t)static_cast<NativeFunction>(jsTestObjPrototypeFunctionWithDynamicFrameAndArg), (intptr_t)1 THUNK_GENERATOR(0) },
     
    489492}
    490493
     494JSValue JSC_HOST_CALL jsTestObjPrototypeFunctionAddEventListener(ExecState* exec, JSObject*, JSValue thisValue, const ArgList& args)
     495{
     496    UNUSED_PARAM(args);
     497    if (!thisValue.inherits(&JSTestObj::s_info))
     498        return throwError(exec, TypeError);
     499    JSTestObj* castedThisObj = static_cast<JSTestObj*>(asObject(thisValue));
     500    TestObj* imp = static_cast<TestObj*>(castedThisObj->impl());
     501    JSValue listener = args.at(1);
     502    if (!listener.isObject())
     503        return jsUndefined();
     504    imp->addEventListener(ustringToAtomicString(args.at(0).toString(exec)), JSEventListener::create(asObject(listener), castedThisObj, false, currentWorld(exec)), args.at(2).toBoolean(exec));
     505    return jsUndefined();
     506}
     507
     508JSValue JSC_HOST_CALL jsTestObjPrototypeFunctionRemoveEventListener(ExecState* exec, JSObject*, JSValue thisValue, const ArgList& args)
     509{
     510    UNUSED_PARAM(args);
     511    if (!thisValue.inherits(&JSTestObj::s_info))
     512        return throwError(exec, TypeError);
     513    JSTestObj* castedThisObj = static_cast<JSTestObj*>(asObject(thisValue));
     514    TestObj* imp = static_cast<TestObj*>(castedThisObj->impl());
     515    JSValue listener = args.at(1);
     516    if (!listener.isObject())
     517        return jsUndefined();
     518    imp->removeEventListener(ustringToAtomicString(args.at(0).toString(exec)), JSEventListener::create(asObject(listener), castedThisObj, false, currentWorld(exec)).get(), args.at(2).toBoolean(exec));
     519    return jsUndefined();
     520}
     521
    491522JSValue JSC_HOST_CALL jsTestObjPrototypeFunctionWithDynamicFrame(ExecState* exec, JSObject*, JSValue thisValue, const ArgList& args)
    492523{
  • trunk/WebCore/bindings/scripts/test/JS/JSTestObj.h

    r58298 r58330  
    9696JSC::JSValue JSC_HOST_CALL jsTestObjPrototypeFunctionCustomMethodWithArgs(JSC::ExecState*, JSC::JSObject*, JSC::JSValue, const JSC::ArgList&);
    9797JSC::JSValue JSC_HOST_CALL jsTestObjPrototypeFunctionCustomArgsAndException(JSC::ExecState*, JSC::JSObject*, JSC::JSValue, const JSC::ArgList&);
     98JSC::JSValue JSC_HOST_CALL jsTestObjPrototypeFunctionAddEventListener(JSC::ExecState*, JSC::JSObject*, JSC::JSValue, const JSC::ArgList&);
     99JSC::JSValue JSC_HOST_CALL jsTestObjPrototypeFunctionRemoveEventListener(JSC::ExecState*, JSC::JSObject*, JSC::JSValue, const JSC::ArgList&);
    98100JSC::JSValue JSC_HOST_CALL jsTestObjPrototypeFunctionWithDynamicFrame(JSC::ExecState*, JSC::JSObject*, JSC::JSValue, const JSC::ArgList&);
    99101JSC::JSValue JSC_HOST_CALL jsTestObjPrototypeFunctionWithDynamicFrameAndArg(JSC::ExecState*, JSC::JSObject*, JSC::JSValue, const JSC::ArgList&);
  • trunk/WebCore/bindings/scripts/test/ObjC/DOMTestObj.h

    r58298 r58330  
    3232@class DOMlog;
    3333@class NSString;
     34@protocol DOMEventListener;
    3435
    3536@interface DOMTestObj : DOMObject
     
    6162- (void)customMethodWithArgs:(int)intArg strArg:(NSString *)strArg objArg:(DOMTestObj *)objArg;
    6263- (void)customArgsAndException:(DOMlog *)intArg;
     64- (void)addEventListener:(NSString *)type listener:(id <DOMEventListener>)listener useCapture:(BOOL)useCapture;
     65- (void)removeEventListener:(NSString *)type listener:(id <DOMEventListener>)listener useCapture:(BOOL)useCapture;
    6366- (void)withDynamicFrame;
    6467- (void)withDynamicFrameAndArg:(int)intArg;
  • trunk/WebCore/bindings/scripts/test/ObjC/DOMTestObj.mm

    r58298 r58330  
    3838#import "DOMTestObjInternal.h"
    3939#import "DOMlogInternal.h"
     40#import "EventListener.h"
    4041#import "ExceptionHandlers.h"
    4142#import "KURL.h"
     43#import "ObjCEventListener.h"
    4244#import "TestObj.h"
    4345#import "ThreadCheck.h"
     
    207209    IMPL->customArgsAndException(core(intArg), ec);
    208210    WebCore::raiseOnDOMError(ec);
     211}
     212
     213- (void)addEventListener:(NSString *)type listener:(id <DOMEventListener>)listener useCapture:(BOOL)useCapture
     214{
     215    RefPtr<WebCore::EventListener> nativeEventListener = WebCore::ObjCEventListener::wrap(listener);
     216    IMPL->addEventListener(type, WTF::getPtr(nativeEventListener), useCapture);
     217}
     218
     219- (void)removeEventListener:(NSString *)type listener:(id <DOMEventListener>)listener useCapture:(BOOL)useCapture
     220{
     221    RefPtr<WebCore::EventListener> nativeEventListener = WebCore::ObjCEventListener::wrap(listener);
     222    IMPL->removeEventListener(type, WTF::getPtr(nativeEventListener), useCapture);
    209223}
    210224
  • trunk/WebCore/bindings/scripts/test/TestObj.idl

    r58298 r58330  
    6161            raises(DOMException);
    6262
     63        void addEventListener(in DOMString type,
     64                              in EventListener listener,
     65                              in boolean useCapture);
     66        void removeEventListener(in DOMString type,
     67                                 in EventListener listener,
     68                                 in boolean useCapture);
     69
    6370        // 'CallWith' extended attribute
    6471        [CallWith=DynamicFrame] void withDynamicFrame();
  • trunk/WebCore/bindings/scripts/test/V8/V8TestObj.cpp

    r58315 r58330  
    254254    V8Proxy::setDOMException(ec);
    255255    return v8::Handle<v8::Value>();
     256}
     257
     258static v8::Handle<v8::Value> addEventListenerCallback(const v8::Arguments& args)
     259{
     260    INC_STATS("DOM.TestObj.addEventListener()");
     261    RefPtr<EventListener> listener = V8DOMWrapper::getEventListener(args[1], false, ListenerFindOrCreate);
     262    if (listener) {
     263        V8TestObj::toNative(args.Holder())->addEventListener(v8ValueToAtomicWebCoreString(args[0]), listener, args[2]->BooleanValue());
     264        createHiddenDependency(args.Holder(), args[1], V8TestObj::eventListenerCacheIndex);
     265    }
     266    return v8::Undefined();
     267}
     268
     269static v8::Handle<v8::Value> removeEventListenerCallback(const v8::Arguments& args)
     270{
     271    INC_STATS("DOM.TestObj.removeEventListener()");
     272    RefPtr<EventListener> listener = V8DOMWrapper::getEventListener(args[1], false, ListenerFindOnly);
     273    if (listener) {
     274        V8TestObj::toNative(args.Holder())->removeEventListener(v8ValueToAtomicWebCoreString(args[0]), listener.get(), args[2]->BooleanValue());
     275        removeHiddenDependency(args.Holder(), args[1], V8TestObj::eventListenerCacheIndex);
     276    }
     277    return v8::Undefined();
    256278}
    257279
     
    483505    {"customMethod", V8TestObj::customMethodCallback},
    484506    {"customMethodWithArgs", V8TestObj::customMethodWithArgsCallback},
     507    {"addEventListener", TestObjInternal::addEventListenerCallback},
     508    {"removeEventListener", TestObjInternal::removeEventListenerCallback},
    485509    {"withDynamicFrame", TestObjInternal::withDynamicFrameCallback},
    486510    {"withDynamicFrameAndArg", TestObjInternal::withDynamicFrameAndArgCallback},
  • trunk/WebCore/dom/MessagePort.idl

    r55096 r58330  
    4444
    4545        // EventTarget interface
    46         [JSCCustom] void addEventListener(in DOMString type,
    47                                           in EventListener listener,
    48                                           in boolean useCapture);
    49         [JSCCustom] void removeEventListener(in DOMString type,
    50                                              in EventListener listener,
    51                                              in boolean useCapture);
     46        void addEventListener(in DOMString type,
     47                              in EventListener listener,
     48                              in boolean useCapture);
     49        void removeEventListener(in DOMString type,
     50                                 in EventListener listener,
     51                                 in boolean useCapture);
    5252        boolean dispatchEvent(in Event evt)
    5353            raises(EventException);
  • trunk/WebCore/dom/Node.idl

    r58108 r58330  
    135135#if !defined(LANGUAGE_OBJECTIVE_C) || !LANGUAGE_OBJECTIVE_C
    136136#if !defined(LANGUAGE_GOBJECT) || !LANGUAGE_GOBJECT
    137         [JSCCustom] void addEventListener(in DOMString type,
    138                                           in EventListener listener,
    139                                           in boolean useCapture);
    140         [JSCCustom] void removeEventListener(in DOMString type,
    141                                              in EventListener listener,
    142                                              in boolean useCapture);
     137        void addEventListener(in DOMString type,
     138                              in EventListener listener,
     139                              in boolean useCapture);
     140        void removeEventListener(in DOMString type,
     141                                 in EventListener listener,
     142                                 in boolean useCapture);
    143143        boolean dispatchEvent(in Event event)
    144144            raises(EventException);
  • trunk/WebCore/loader/appcache/DOMApplicationCache.idl

    r55096 r58330  
    5656
    5757        // EventTarget interface
    58         [JSCCustom] void addEventListener(in DOMString type,
    59                                           in EventListener listener,
    60                                           in boolean useCapture);
    61         [JSCCustom] void removeEventListener(in DOMString type,
    62                                              in EventListener listener,
    63                                              in boolean useCapture);
     58        void addEventListener(in DOMString type,
     59                              in EventListener listener,
     60                              in boolean useCapture);
     61        void removeEventListener(in DOMString type,
     62                                 in EventListener listener,
     63                                 in boolean useCapture);
    6464        boolean dispatchEvent(in Event evt)
    6565            raises(EventException);
  • trunk/WebCore/notifications/Notification.idl

    r55096 r58330  
    4444
    4545        // EventTarget interface
    46         [JSCCustom] void addEventListener(in DOMString type,
    47                                           in EventListener listener,
    48                                           in boolean useCapture);
    49         [JSCCustom] void removeEventListener(in DOMString type,
    50                                              in EventListener listener,
    51                                              in boolean useCapture);
     46        void addEventListener(in DOMString type,
     47                              in EventListener listener,
     48                              in boolean useCapture);
     49        void removeEventListener(in DOMString type,
     50                                 in EventListener listener,
     51                                 in boolean useCapture);
    5252        boolean dispatchEvent(in Event evt)
    5353            raises(EventException);
  • trunk/WebCore/page/EventSource.idl

    r55096 r58330  
    5454
    5555        // EventTarget interface
    56         [JSCCustom] void addEventListener(in DOMString type,
    57                                           in EventListener listener,
    58                                           in boolean useCapture);
    59         [JSCCustom] void removeEventListener(in DOMString type,
    60                                              in EventListener listener,
    61                                              in boolean useCapture);
     56        void addEventListener(in DOMString type,
     57                              in EventListener listener,
     58                              in boolean useCapture);
     59        void removeEventListener(in DOMString type,
     60                                 in EventListener listener,
     61                                 in boolean useCapture);
    6262        boolean dispatchEvent(in Event evt)
    6363            raises(EventException);
  • trunk/WebCore/svg/SVGElementInstance.idl

    r55096 r58330  
    9191        attribute [DontEnum] EventListener onunload;
    9292
    93         [JSCCustom] void addEventListener(in DOMString type,
    94                                           in EventListener listener,
    95                                           in boolean useCapture);
    96         [JSCCustom] void removeEventListener(in DOMString type,
    97                                              in EventListener listener,
    98                                              in boolean useCapture);
     93        void addEventListener(in DOMString type,
     94                              in EventListener listener,
     95                              in boolean useCapture);
     96        void removeEventListener(in DOMString type,
     97                                 in EventListener listener,
     98                                 in boolean useCapture);
    9999        boolean dispatchEvent(in Event event)
    100100            raises(EventException);
  • trunk/WebCore/websockets/WebSocket.idl

    r55573 r58330  
    5858
    5959        // EventTarget interface
    60         [JSCCustom] void addEventListener(in DOMString type,
    61                                           in EventListener listener,
    62                                           in boolean useCapture);
    63         [JSCCustom] void removeEventListener(in DOMString type,
    64                                              in EventListener listener,
    65                                              in boolean useCapture);
     60        void addEventListener(in DOMString type,
     61                              in EventListener listener,
     62                              in boolean useCapture);
     63        void removeEventListener(in DOMString type,
     64                                 in EventListener listener,
     65                                 in boolean useCapture);
    6666        boolean dispatchEvent(in Event evt)
    6767            raises(EventException);
  • trunk/WebCore/workers/AbstractWorker.idl

    r55096 r58330  
    3939        attribute EventListener onerror;
    4040
    41         [JSCCustom] void addEventListener(in DOMString type,
    42                                           in EventListener listener,
    43                                           in boolean useCapture);
    44         [JSCCustom] void removeEventListener(in DOMString type,
    45                                              in EventListener listener,
    46                                              in boolean useCapture);
     41        void addEventListener(in DOMString type,
     42                              in EventListener listener,
     43                              in boolean useCapture);
     44        void removeEventListener(in DOMString type,
     45                                 in EventListener listener,
     46                                 in boolean useCapture);
    4747        boolean dispatchEvent(in Event evt)
    4848            raises(EventException);
  • trunk/WebCore/workers/WorkerContext.idl

    r57704 r58330  
    6363
    6464        // EventTarget interface
    65         [JSCCustom] void addEventListener(in DOMString type,
    66                                           in EventListener listener,
    67                                           in boolean useCapture);
    68         [JSCCustom] void removeEventListener(in DOMString type,
    69                                              in EventListener listener,
    70                                              in boolean useCapture);
     65        void addEventListener(in DOMString type,
     66                              in EventListener listener,
     67                              in boolean useCapture);
     68        void removeEventListener(in DOMString type,
     69                                 in EventListener listener,
     70                                 in boolean useCapture);
    7171        boolean dispatchEvent(in Event evt)
    7272            raises(EventException);
  • trunk/WebCore/xml/XMLHttpRequest.idl

    r55096 r58330  
    9292
    9393        // EventTarget interface
    94         [JSCCustom] void addEventListener(in DOMString type,
    95                                           in EventListener listener,
    96                                           in boolean useCapture);
    97         [JSCCustom] void removeEventListener(in DOMString type,
    98                                              in EventListener listener,
    99                                              in boolean useCapture);
     94        void addEventListener(in DOMString type,
     95                              in EventListener listener,
     96                              in boolean useCapture);
     97        void removeEventListener(in DOMString type,
     98                                 in EventListener listener,
     99                                 in boolean useCapture);
    100100        boolean dispatchEvent(in Event evt)
    101101            raises(EventException);
  • trunk/WebCore/xml/XMLHttpRequestUpload.idl

    r55096 r58330  
    4343
    4444        // EventTarget interface
    45         [JSCCustom] void addEventListener(in DOMString type,
    46                                           in EventListener listener,
    47                                           in boolean useCapture);
    48         [JSCCustom] void removeEventListener(in DOMString type,
    49                                              in EventListener listener,
    50                                              in boolean useCapture);
     45        void addEventListener(in DOMString type,
     46                              in EventListener listener,
     47                              in boolean useCapture);
     48        void removeEventListener(in DOMString type,
     49                                 in EventListener listener,
     50                                 in boolean useCapture);
    5151        boolean dispatchEvent(in Event evt)
    5252            raises(EventException);
Note: See TracChangeset for help on using the changeset viewer.