Changeset 208028 in webkit


Ignore:
Timestamp:
Oct 27, 2016 8:56:50 PM (8 years ago)
Author:
Yusuke Suzuki
Message:

[DOM] Add JSEventType
https://bugs.webkit.org/show_bug.cgi?id=164096

Reviewed by Darin Adler.

Event is inherited by many Event classes. But, Event's accessors and interfaces are
frequently called. For example, event.{type, target, srcElement} for accessors. And
event.stopPropagation() and event.preventDefault() functions.

However, since the user-visible event instance is typically the instance of the subclass,
jsDynamicCast<JSEvent*>() walks several classes before it succeeds. It is costly.

In this patch, we add a new WebCore JSType JSEventType for JSEvent and add a new
function jsEventCast. That supports a super fast cast operation. And it paves the way
for implementing DOM accessors of Event in DOMJIT.

No behavior change.

  • WebCore.xcodeproj/project.pbxproj:
  • bindings/js/JSDOMWrapper.h:
  • bindings/js/JSEventCustom.h: Added.

(WebCore::jsEventCast):

  • bindings/scripts/CodeGeneratorJS.pm:

(GetJSTypeForNode):
(GenerateHeader):
(GetCastingHelperForThisObject):

  • bindings/scripts/test/JS/JSTestEventConstructor.h:

(WebCore::JSTestEventConstructor::createStructure):

  • dom/Event.idl:
  • domjit/DOMJITHelpers.h:

(WebCore::DOMJIT::branchIfEvent):
(WebCore::DOMJIT::branchIfNotEvent):

Location:
trunk/Source/WebCore
Files:
1 added
7 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r208026 r208028  
     12016-10-27  Yusuke Suzuki  <utatane.tea@gmail.com>
     2
     3        [DOM] Add JSEventType
     4        https://bugs.webkit.org/show_bug.cgi?id=164096
     5
     6        Reviewed by Darin Adler.
     7
     8        Event is inherited by many Event classes. But, Event's accessors and interfaces are
     9        frequently called. For example, event.{type, target, srcElement} for accessors. And
     10        event.stopPropagation() and event.preventDefault() functions.
     11
     12        However, since the user-visible event instance is typically the instance of the subclass,
     13        jsDynamicCast<JSEvent*>() walks several classes before it succeeds. It is costly.
     14
     15        In this patch, we add a new WebCore JSType JSEventType for JSEvent and add a new
     16        function jsEventCast. That supports a super fast cast operation. And it paves the way
     17        for implementing DOM accessors of Event in DOMJIT.
     18
     19        No behavior change.
     20
     21        * WebCore.xcodeproj/project.pbxproj:
     22        * bindings/js/JSDOMWrapper.h:
     23        * bindings/js/JSEventCustom.h: Added.
     24        (WebCore::jsEventCast):
     25        * bindings/scripts/CodeGeneratorJS.pm:
     26        (GetJSTypeForNode):
     27        (GenerateHeader):
     28        (GetCastingHelperForThisObject):
     29        * bindings/scripts/test/JS/JSTestEventConstructor.h:
     30        (WebCore::JSTestEventConstructor::createStructure):
     31        * dom/Event.idl:
     32        * domjit/DOMJITHelpers.h:
     33        (WebCore::DOMJIT::branchIfEvent):
     34        (WebCore::DOMJIT::branchIfNotEvent):
     35
    1362016-10-27  Simon Fraser  <simon.fraser@apple.com>
    237
  • trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj

    r208010 r208028  
    62026202                E3150EA61DA7219000194012 /* JSNodeDOMJIT.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E3AFA9641DA6E908002861BD /* JSNodeDOMJIT.cpp */; };
    62036203                E3150EA71DA7219300194012 /* DOMJITHelpers.h in Headers */ = {isa = PBXBuildFile; fileRef = E3150EA51DA7218D00194012 /* DOMJITHelpers.h */; };
     6204                E3565B7B1DC2D6C900217DBD /* JSEventCustom.h in Headers */ = {isa = PBXBuildFile; fileRef = E34EE49F1DC2D57500EAA9D3 /* JSEventCustom.h */; settings = {ATTRIBUTES = (Private, ); }; };
    62046205                E35CA14D1DBC3A3F00F83516 /* DOMJITAbstractHeapRepository.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E35CA14B1DBC3A3C00F83516 /* DOMJITAbstractHeapRepository.cpp */; };
    62056206                E35CA14E1DBC3A4200F83516 /* DOMJITAbstractHeapRepository.h in Headers */ = {isa = PBXBuildFile; fileRef = E35CA14C1DBC3A3C00F83516 /* DOMJITAbstractHeapRepository.h */; };
     
    1403214033                E1FF8F6B180DB5BE00132674 /* CryptoAlgorithmRegistry.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CryptoAlgorithmRegistry.h; sourceTree = "<group>"; };
    1403314034                E3150EA51DA7218D00194012 /* DOMJITHelpers.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = DOMJITHelpers.h; sourceTree = "<group>"; };
     14035                E34EE49F1DC2D57500EAA9D3 /* JSEventCustom.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JSEventCustom.h; sourceTree = "<group>"; };
    1403414036                E35CA14B1DBC3A3C00F83516 /* DOMJITAbstractHeapRepository.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = DOMJITAbstractHeapRepository.cpp; sourceTree = "<group>"; };
    1403514037                E35CA14C1DBC3A3C00F83516 /* DOMJITAbstractHeapRepository.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = DOMJITAbstractHeapRepository.h; sourceTree = "<group>"; };
     
    2161021612                                F3D461461161D53200CA0D09 /* JSErrorHandler.cpp */,
    2161121613                                F3D461471161D53200CA0D09 /* JSErrorHandler.h */,
     21614                                E34EE49F1DC2D57500EAA9D3 /* JSEventCustom.h */,
    2161221615                                BC60901E0E91B8EC000C68B5 /* JSEventTargetCustom.cpp */,
    2161321616                                46B63F6B1C6E8CDF002E914B /* JSEventTargetCustom.h */,
     
    2550725510                                1C81B95C0E97330800266E07 /* InspectorClient.h in Headers */,
    2550825511                                1C81B95A0E97330800266E07 /* InspectorController.h in Headers */,
     25512                                E3565B7B1DC2D6C900217DBD /* JSEventCustom.h in Headers */,
    2550925513                                82AB1744124B99EC00C5069D /* InspectorCSSAgent.h in Headers */,
    2551025514                                4A9CC82116BF9BB400EC645A /* InspectorCSSOMWrappers.h in Headers */,
  • trunk/Source/WebCore/bindings/js/JSDOMWrapper.h

    r207381 r208028  
    3131class ScriptExecutionContext;
    3232
    33 // We encode Node type into JSType. The format is the following.
    34 // offset | 7 | 6 5 4 | 3 2 1 0  |
    35 // value  | 1 | Kind  | NodeType |
     33// JSC allows us to extend JSType. If the highest bit is set, we can add any Object types and they are
     34// recognized as OtherObj in JSC. And we encode Node type into JSType if the given JSType is subclass of Node.
     35// offset | 7 | 6 | 5   4 | 3   2   1   0  |
     36// value  | 1 | 0 |  Non-node DOM types    |
     37// If the given JSType is a subclass of Node, the format is the following.
     38// offset | 7 | 6 | 5   4 | 3   2   1   0  |
     39// value  | 1 | 1 |  Kind |       NodeType |
    3640static const uint8_t JSNodeTypeMask                  = 0b00001111;
    3741
    3842static const uint8_t JSDOMWrapperType                = 0b10000000;
    39 static const uint8_t JSNodeType                      = 0b10010000;
     43static const uint8_t JSEventType                     = 0b10000001;
     44static const uint8_t JSNodeType                      = 0b11000000;
    4045static const uint8_t JSTextNodeType                  = JSNodeType | NodeConstants::TEXT_NODE;
    4146static const uint8_t JSProcessingInstructionNodeType = JSNodeType | NodeConstants::PROCESSING_INSTRUCTION_NODE;
     
    4651static const uint8_t JSCDATASectionNodeType          = JSNodeType | NodeConstants::CDATA_SECTION_NODE;
    4752static const uint8_t JSAttrNodeType                  = JSNodeType | NodeConstants::ATTRIBUTE_NODE;
    48 static const uint8_t JSElementType                   = 0b10100000 | NodeConstants::ELEMENT_NODE;
     53static const uint8_t JSElementType                   = 0b11010000 | NodeConstants::ELEMENT_NODE;
    4954
    5055static_assert(JSDOMWrapperType > JSC::LastJSCObjectType, "JSC::JSType offers the highest bit.");
  • trunk/Source/WebCore/bindings/scripts/CodeGeneratorJS.pm

    r208023 r208028  
    12171217sub GetJSTypeForNode
    12181218{
    1219     my ($codeGenerator, $interface) = @_;
     1219    my ($interface) = @_;
    12201220
    12211221    if ($codeGenerator->InheritsInterface($interface, "Document")) {
     
    14471447        push(@headerContent, "        return JSC::Structure::create(vm, globalObject, prototype, JSC::TypeInfo(JSC::GlobalObjectType, StructureFlags), info());\n");
    14481448    } elsif ($codeGenerator->InheritsInterface($interface, "Node")) {
    1449         my $type = GetJSTypeForNode($codeGenerator, $interface);
     1449        my $type = GetJSTypeForNode($interface);
    14501450        push(@headerContent, "        return JSC::Structure::create(vm, globalObject, prototype, JSC::TypeInfo(JSC::JSType($type), StructureFlags), info());\n");
     1451    } elsif ($codeGenerator->InheritsInterface($interface, "Event")) {
     1452        push(@headerContent, "        return JSC::Structure::create(vm, globalObject, prototype, JSC::TypeInfo(JSC::JSType(JSEventType), StructureFlags), info());\n");
    14511453    } else {
    14521454        push(@headerContent, "        return JSC::Structure::create(vm, globalObject, prototype, JSC::TypeInfo(JSC::ObjectType, StructureFlags), info());\n");
     
    24892491    return "jsDocumentCast" if $interfaceName eq "Document";
    24902492    return "jsEventTargetCast" if $interfaceName eq "EventTarget";
     2493    return "jsEventCast" if $interfaceName eq "Event";
    24912494    return "jsDynamicCast<JS$interfaceName*>";
    24922495}
  • trunk/Source/WebCore/bindings/scripts/test/JS/JSTestEventConstructor.h

    r207715 r208028  
    4545    static JSC::Structure* createStructure(JSC::VM& vm, JSC::JSGlobalObject* globalObject, JSC::JSValue prototype)
    4646    {
    47         return JSC::Structure::create(vm, globalObject, prototype, JSC::TypeInfo(JSC::ObjectType, StructureFlags), info());
     47        return JSC::Structure::create(vm, globalObject, prototype, JSC::TypeInfo(JSC::JSType(JSEventType), StructureFlags), info());
    4848    }
    4949
  • trunk/Source/WebCore/dom/Event.idl

    r207908 r208028  
    2828    ExportToWrappedFunction,
    2929    Exposed=(Window,Worker),
     30    JSCustomHeader,
    3031] interface Event {
    3132    // PhaseType
  • trunk/Source/WebCore/domjit/DOMJITHelpers.h

    r207999 r208028  
    9999}
    100100
     101inline CCallHelpers::Jump branchIfEvent(CCallHelpers& jit, GPRReg target)
     102{
     103    return jit.branchIfType(target, JSC::JSType(JSEventType));
     104}
     105
     106inline CCallHelpers::Jump branchIfNotEvent(CCallHelpers& jit, GPRReg target)
     107{
     108    return jit.branchIfNotType(target, JSC::JSType(JSEventType));
     109}
     110
    101111inline CCallHelpers::Jump branchIfNode(CCallHelpers& jit, GPRReg target)
    102112{
Note: See TracChangeset for help on using the changeset viewer.