Changeset 166765 in webkit


Ignore:
Timestamp:
Apr 3, 2014 9:42:21 PM (10 years ago)
Author:
akling@apple.com
Message:

Fast-path for casting JS wrappers to JSElement.
<https://webkit.org/b/131210>

Add an extended JSType for Element wrappers so we can avoid walking
the ClassInfo chain in those bindings as well.

Generalized the code to select a casting helper in the bindings
generator into a function (GetCastingHelperForThisObject.)
Updated all the jsDynamicCast call sites to go through this, in case
there's an optimized cast available for the desired type.

Reviewed by Benjamin Poulain.

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

(WebCore::jsElementCast):

  • bindings/js/JSNodeCustom.h:

(WebCore::jsNodeCast):

  • bindings/scripts/CodeGeneratorJS.pm:

(GenerateHeader):
(GetCastingHelperForThisObject):
(GenerateImplementation):

  • dom/Element.idl:
Location:
trunk/Source/WebCore
Files:
1 added
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r166761 r166765  
     12014-04-03  Andreas Kling  <akling@apple.com>
     2
     3        Fast-path for casting JS wrappers to JSElement.
     4        <https://webkit.org/b/131210>
     5
     6        Add an extended JSType for Element wrappers so we can avoid walking
     7        the ClassInfo chain in those bindings as well.
     8
     9        Generalized the code to select a casting helper in the bindings
     10        generator into a function (GetCastingHelperForThisObject.)
     11        Updated all the jsDynamicCast call sites to go through this, in case
     12        there's an optimized cast available for the desired type.
     13
     14        Reviewed by Benjamin Poulain.
     15
     16        * WebCore.xcodeproj/project.pbxproj:
     17        * bindings/js/JSDOMWrapper.h:
     18        * bindings/js/JSElementCustom.h: Added.
     19        (WebCore::jsElementCast):
     20        * bindings/js/JSNodeCustom.h:
     21        (WebCore::jsNodeCast):
     22        * bindings/scripts/CodeGeneratorJS.pm:
     23        (GenerateHeader):
     24        (GetCastingHelperForThisObject):
     25        (GenerateImplementation):
     26        * dom/Element.idl:
     27
    1282014-04-03  Andreas Kling  <akling@apple.com>
    229
  • trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj

    r166752 r166765  
    42374237                AD726FEF16DA11F5003A4E6D /* JSCSSRuleCustom.h in Headers */ = {isa = PBXBuildFile; fileRef = AD726FE916D9F40A003A4E6D /* JSCSSRuleCustom.h */; settings = {ATTRIBUTES = (Private, ); }; };
    42384238                ADDF1AD71257CD9A0003A759 /* RenderSVGPath.h in Headers */ = {isa = PBXBuildFile; fileRef = ADDF1AD51257CD9A0003A759 /* RenderSVGPath.h */; };
     4239                ADEC78F818EE5308001315C2 /* JSElementCustom.h in Headers */ = {isa = PBXBuildFile; fileRef = ADEC78F718EE5308001315C2 /* JSElementCustom.h */; settings = {ATTRIBUTES = (Private, ); }; };
    42394240                B10B6980140C174000BC1C26 /* WebVTTToken.h in Headers */ = {isa = PBXBuildFile; fileRef = B10B697D140C174000BC1C26 /* WebVTTToken.h */; };
    42404241                B10B6981140C174000BC1C26 /* WebVTTTokenizer.cpp in Sources */ = {isa = PBXBuildFile; fileRef = B10B697E140C174000BC1C26 /* WebVTTTokenizer.cpp */; };
     
    1134711348                ADE11F4A18D8311B0078983B /* ElementDescendantIterator.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ElementDescendantIterator.h; sourceTree = "<group>"; };
    1134811349                ADE16736181050C300463A2E /* RenderPtr.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RenderPtr.h; sourceTree = "<group>"; };
     11350                ADEC78F718EE5308001315C2 /* JSElementCustom.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JSElementCustom.h; sourceTree = "<group>"; };
    1134911351                B10B697D140C174000BC1C26 /* WebVTTToken.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WebVTTToken.h; sourceTree = "<group>"; };
    1135011352                B10B697E140C174000BC1C26 /* WebVTTTokenizer.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = WebVTTTokenizer.cpp; sourceTree = "<group>"; };
     
    2053320535                                652FBBBB0DE27CB60001D386 /* JSDOMWindowCustom.h */,
    2053420536                                BC2ED5540C6B9BD300920BFF /* JSElementCustom.cpp */,
     20537                                ADEC78F718EE5308001315C2 /* JSElementCustom.h */,
    2053520538                                BCEFAF4D0C317E6900FA81F6 /* JSEventCustom.cpp */,
    2053620539                                2E7582ED12764F260062628B /* JSFileReaderCustom.cpp */,
     
    2621626219                                2E4346500F546A8200B0F1BA /* WorkerMessagingProxy.h in Headers */,
    2621726220                                CD52481B18E200ED0008A07D /* DisplaySleepDisabler.h in Headers */,
     26221                                ADEC78F818EE5308001315C2 /* JSElementCustom.h in Headers */,
    2621826222                                E1271A0B0EEEC77A00F61213 /* WorkerNavigator.h in Headers */,
    2621926223                                1ABC7109170E5E1B00F9A9D6 /* WorkerNavigatorStorageQuota.h in Headers */,
  • trunk/Source/WebCore/bindings/js/JSDOMWrapper.h

    r166760 r166765  
    3131
    3232static const uint8_t JSNodeType = JSC::LastJSCObjectType + 1;
     33static const uint8_t JSElementType = JSC::LastJSCObjectType + 2;
    3334
    3435class JSDOMWrapper : public JSC::JSDestructibleObject {
  • trunk/Source/WebCore/bindings/js/JSNodeCustom.h

    r166760 r166765  
    8383    if (UNLIKELY(!value.isCell()))
    8484        return nullptr;
    85     return value.asCell()->type() == JSNodeType ? JSC::jsCast<JSNode*>(value) : nullptr;
     85    return value.asCell()->type() >= JSNodeType ? JSC::jsCast<JSNode*>(value) : nullptr;
    8686}
    8787
  • trunk/Source/WebCore/bindings/scripts/CodeGeneratorJS.pm

    r166760 r166765  
    960960    if (IsDOMGlobalObject($interface)) {
    961961        push(@headerContent, "        return JSC::Structure::create(vm, globalObject, prototype, JSC::TypeInfo(JSC::GlobalObjectType, StructureFlags), info());\n");
     962    } elsif ($codeGenerator->InheritsInterface($interface, "Element")) {
     963        push(@headerContent, "        return JSC::Structure::create(vm, globalObject, prototype, JSC::TypeInfo(JSC::JSType(JSElementType), StructureFlags), info());\n");
    962964    } elsif ($codeGenerator->InheritsInterface($interface, "Node")) {
    963965        push(@headerContent, "        return JSC::Structure::create(vm, globalObject, prototype, JSC::TypeInfo(JSC::JSType(JSNodeType), StructureFlags), info());\n");
     
    16941696}
    16951697
     1698sub GetCastingHelperForThisObject
     1699{
     1700    my $interface = shift;
     1701
     1702    if ($interface->name eq "Node") {
     1703        return "jsNodeCast";
     1704    }
     1705    if ($interface->name eq "Element") {
     1706        return "jsElementCast";
     1707    }
     1708    return "jsDynamicCast<JS" . $interface->name . "*>";
     1709}
     1710
    16961711sub GenerateImplementation
    16971712{
     
    21332148                    push(@implContent, "    UNUSED_PARAM(slotBase);\n");
    21342149                } else {
    2135                     if ($interfaceName eq "Node") {
    2136                         push(@implContent, "    JSNode* castedThis = jsNodeCast(JSValue::decode(thisValue));\n");
    2137                     } else {
    2138                         push(@implContent, "    ${className}* castedThis = jsDynamicCast<$className*>(JSValue::decode(thisValue));\n");
    2139                     }
     2150                    push(@implContent, "    ${className}* castedThis = " . GetCastingHelperForThisObject($interface) . "(JSValue::decode(thisValue));\n");
    21402151                    push(@implContent, "    UNUSED_PARAM(slotBase);\n");
    21412152                }
     
    23552366                push(@implContent, "    ${className}* domObject = to${className}(JSValue::decode(thisValue));\n");
    23562367            } else {
    2357                 push(@implContent, "    ${className}* domObject = jsDynamicCast<${className}*>(JSValue::decode(thisValue));\n") if ConstructorShouldBeOnInstance($interface);
     2368                push(@implContent, "    ${className}* domObject = " . GetCastingHelperForThisObject($interface) . "(JSValue::decode(thisValue));\n") if ConstructorShouldBeOnInstance($interface);
    23582369                push(@implContent, "    ${className}Prototype* domObject = jsDynamicCast<${className}Prototype*>(baseValue);\n") if !ConstructorShouldBeOnInstance($interface);
    23592370            }
     
    23802391                push(@implContent, "    ${className}* castedThis = to${className}(JSValue::decode(thisValue));\n");
    23812392            } else {
    2382                 push(@implContent, "    ${className}* castedThis = jsDynamicCast<${className}*>(JSValue::decode(thisValue));\n");
     2393                push(@implContent, "    ${className}* castedThis = " . GetCastingHelperForThisObject($interface) . "(JSValue::decode(thisValue));\n");
    23832394            }
    23842395            push(@implContent, "    if (UNLIKELY(!castedThis)) {\n");
     
    24872498                        push(@implContent, "    ${className}* castedThis = to${className}(JSValue::decode(thisValue));\n");
    24882499                    } else {
    2489                         push(@implContent, "    ${className}* castedThis = jsDynamicCast<${className}*>(JSValue::decode(thisValue));\n");
     2500                        push(@implContent, "    ${className}* castedThis = " . GetCastingHelperForThisObject($interface) . "(JSValue::decode(thisValue));\n");
    24902501                    }
    24912502                    push(@implContent, "    if (UNLIKELY(!castedThis)) {\n");
     
    27222733                } else {
    27232734                    push(@implContent, "    JSValue thisValue = exec->thisValue();\n");
    2724                     push(@implContent, "    $className* castedThis = jsDynamicCast<$className*>(thisValue);\n");
     2735                    push(@implContent, "    $className* castedThis = " . GetCastingHelperForThisObject($interface) . "(thisValue);\n");
    27252736                    my $domFunctionName = $function->signature->name;
    27262737                    push(@implContent, "    if (UNLIKELY(!castedThis))\n");
  • trunk/Source/WebCore/dom/Element.idl

    r164131 r166765  
    2020
    2121[
     22    JSCustomHeader,
    2223    JSGenerateToNativeObject,
    2324] interface Element : Node {
Note: See TracChangeset for help on using the changeset viewer.