Changeset 166760 in webkit


Ignore:
Timestamp:
Apr 3, 2014 7:29:15 PM (10 years ago)
Author:
akling@apple.com
Message:

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

Source/JavaScriptCore:

Allow code outside of JSC (well, WebCore) to extend the JSType spectrum
a little bit. We do this by exposing a LastJSCObjectType constant so
WebCore can encode its own wrapper types after that.

Reviewed by Mark Hahnenberg and Geoff Garen.

  • runtime/JSType.h:

Added LastJSCObjectType for use by WebCore.

  • runtime/JSObject.h:

(JSC::JSObject::isVariableObject):

Updated since this can no longer assume that types >= VariableObjectType
are all variable objects.

Source/WebCore:

Add a way to quickly determine that a given JSObject is a JSNode.
This lets us avoid walking the ClassInfo chain in the DOM bindings
for WebCore::Node.

Reviewed by Mark Hahnenberg and Geoff Garen.

  • bindings/js/JSDOMWrapper.h:

Added a JSNodeType constant that extends beyond JSC::JSType.

  • bindings/js/JSNodeCustom.h:

(WebCore::jsNodeCast):

Added. Fast cast from JSValue to JSNode.

  • bindings/scripts/CodeGeneratorJS.pm:

(GenerateHeader):
(GenerateImplementation):

Generate code that uses jsNodeCast in Node interfaces.

Location:
trunk/Source
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/JavaScriptCore/ChangeLog

    r166759 r166760  
     12014-04-03  Andreas Kling  <akling@apple.com>
     2
     3        Fast-path for casting JS wrappers to JSNode.
     4        <https://webkit.org/b/131196>
     5
     6        Allow code outside of JSC (well, WebCore) to extend the JSType spectrum
     7        a little bit. We do this by exposing a LastJSCObjectType constant so
     8        WebCore can encode its own wrapper types after that.
     9
     10        Reviewed by Mark Hahnenberg and Geoff Garen.
     11
     12        * runtime/JSType.h:
     13
     14            Added LastJSCObjectType for use by WebCore.
     15
     16        * runtime/JSObject.h:
     17        (JSC::JSObject::isVariableObject):
     18
     19            Updated since this can no longer assume that types >= VariableObjectType
     20            are all variable objects.
     21
    1222014-04-03  Mark Hahnenberg  <mhahnenberg@apple.com>
    223
  • trunk/Source/JavaScriptCore/runtime/JSObject.h

    r166397 r166760  
    11231123inline bool JSObject::isVariableObject() const
    11241124{
    1125     return type() >= VariableObjectType;
    1126 }
    1127 
     1125    return type() == GlobalObjectType || type() == ActivationObjectType;
     1126}
    11281127
    11291128inline bool JSObject::isStaticScopeObject() const
  • trunk/Source/JavaScriptCore/runtime/JSType.h

    r164764 r166760  
    7070
    7171    NameScopeObjectType,
    72     // VariableObjectType must be less than MOST of the types of its subclasses and only its subclasses.
    73     // We use >=VariableObjectType checks to test for Global & Activation objects, but exclude NameScopes.
    74     VariableObjectType,
     72
    7573    GlobalObjectType,
    7674    ActivationObjectType,
     75
     76    LastJSCObjectType = ActivationObjectType,
    7777};
    7878
  • trunk/Source/WebCore/ChangeLog

    r166752 r166760  
     12014-04-03  Andreas Kling  <akling@apple.com>
     2
     3        Fast-path for casting JS wrappers to JSNode.
     4        <https://webkit.org/b/131196>
     5
     6        Add a way to quickly determine that a given JSObject is a JSNode.
     7        This lets us avoid walking the ClassInfo chain in the DOM bindings
     8        for WebCore::Node.
     9
     10        Reviewed by Mark Hahnenberg and Geoff Garen.
     11
     12        * bindings/js/JSDOMWrapper.h:
     13
     14            Added a JSNodeType constant that extends beyond JSC::JSType.
     15
     16        * bindings/js/JSNodeCustom.h:
     17        (WebCore::jsNodeCast):
     18
     19            Added. Fast cast from JSValue to JSNode.
     20
     21        * bindings/scripts/CodeGeneratorJS.pm:
     22        (GenerateHeader):
     23        (GenerateImplementation):
     24
     25            Generate code that uses jsNodeCast in Node interfaces.
     26
    1272014-04-03  Bem Jones-Bey  <bjonesbe@adobe.com>
    228
  • trunk/Source/WebCore/bindings/js/JSDOMWrapper.h

    r148696 r166760  
    3030class ScriptExecutionContext;
    3131
     32static const uint8_t JSNodeType = JSC::LastJSCObjectType + 1;
     33
    3234class JSDOMWrapper : public JSC::JSDestructibleObject {
    3335public:
  • trunk/Source/WebCore/bindings/js/JSNodeCustom.h

    r165914 r166760  
    7979}
    8080
     81ALWAYS_INLINE JSNode* jsNodeCast(JSC::JSValue value)
     82{
     83    if (UNLIKELY(!value.isCell()))
     84        return nullptr;
     85    return value.asCell()->type() == JSNodeType ? JSC::jsCast<JSNode*>(value) : nullptr;
     86}
     87
    8188} // namespace WebCore
    8289
  • trunk/Source/WebCore/bindings/scripts/CodeGeneratorJS.pm

    r166493 r166760  
    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, "Node")) {
     963        push(@headerContent, "        return JSC::Structure::create(vm, globalObject, prototype, JSC::TypeInfo(JSC::JSType(JSNodeType), StructureFlags), info());\n");
    962964    } else {
    963965        push(@headerContent, "        return JSC::Structure::create(vm, globalObject, prototype, JSC::TypeInfo(JSC::ObjectType, StructureFlags), info());\n");
     
    21312133                    push(@implContent, "    UNUSED_PARAM(slotBase);\n");
    21322134                } else {
    2133                     push(@implContent, "    ${className}* castedThis = jsDynamicCast<$className*>(JSValue::decode(thisValue));\n");
     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                    }
    21342140                    push(@implContent, "    UNUSED_PARAM(slotBase);\n");
    21352141                }
Note: See TracChangeset for help on using the changeset viewer.