- Revision
- 166760
- Author
- [email protected]
- Date
- 2014-04-03 19:29:15 -0700 (Thu, 03 Apr 2014)
Log Message
Fast-path for casting JS wrappers to JSNode.
<https://webkit.org/b/131196>
Source/_javascript_Core:
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.
Modified Paths
Diff
Modified: trunk/Source/_javascript_Core/ChangeLog (166759 => 166760)
--- trunk/Source/_javascript_Core/ChangeLog 2014-04-04 02:24:28 UTC (rev 166759)
+++ trunk/Source/_javascript_Core/ChangeLog 2014-04-04 02:29:15 UTC (rev 166760)
@@ -1,3 +1,24 @@
+2014-04-03 Andreas Kling <[email protected]>
+
+ Fast-path for casting JS wrappers to JSNode.
+ <https://webkit.org/b/131196>
+
+ 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.
+
2014-04-03 Mark Hahnenberg <[email protected]>
All Heap::writeBarriers should be inline
Modified: trunk/Source/_javascript_Core/runtime/JSObject.h (166759 => 166760)
--- trunk/Source/_javascript_Core/runtime/JSObject.h 2014-04-04 02:24:28 UTC (rev 166759)
+++ trunk/Source/_javascript_Core/runtime/JSObject.h 2014-04-04 02:29:15 UTC (rev 166760)
@@ -1122,10 +1122,9 @@
inline bool JSObject::isVariableObject() const
{
- return type() >= VariableObjectType;
+ return type() == GlobalObjectType || type() == ActivationObjectType;
}
-
inline bool JSObject::isStaticScopeObject() const
{
JSType type = this->type();
Modified: trunk/Source/_javascript_Core/runtime/JSType.h (166759 => 166760)
--- trunk/Source/_javascript_Core/runtime/JSType.h 2014-04-04 02:24:28 UTC (rev 166759)
+++ trunk/Source/_javascript_Core/runtime/JSType.h 2014-04-04 02:29:15 UTC (rev 166760)
@@ -69,11 +69,11 @@
DataViewType,
NameScopeObjectType,
- // VariableObjectType must be less than MOST of the types of its subclasses and only its subclasses.
- // We use >=VariableObjectType checks to test for Global & Activation objects, but exclude NameScopes.
- VariableObjectType,
+
GlobalObjectType,
ActivationObjectType,
+
+ LastJSCObjectType = ActivationObjectType,
};
COMPILE_ASSERT(sizeof(JSType) == sizeof(uint8_t), sizeof_jstype_is_one_byte);
Modified: trunk/Source/WebCore/ChangeLog (166759 => 166760)
--- trunk/Source/WebCore/ChangeLog 2014-04-04 02:24:28 UTC (rev 166759)
+++ trunk/Source/WebCore/ChangeLog 2014-04-04 02:29:15 UTC (rev 166760)
@@ -1,3 +1,29 @@
+2014-04-03 Andreas Kling <[email protected]>
+
+ Fast-path for casting JS wrappers to JSNode.
+ <https://webkit.org/b/131196>
+
+ 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.
+
2014-04-03 Bem Jones-Bey <[email protected]>
Merge ShapeInfo & ShapeOutsideInfo now that ShapeInsideInfo is no more
Modified: trunk/Source/WebCore/bindings/js/JSDOMWrapper.h (166759 => 166760)
--- trunk/Source/WebCore/bindings/js/JSDOMWrapper.h 2014-04-04 02:24:28 UTC (rev 166759)
+++ trunk/Source/WebCore/bindings/js/JSDOMWrapper.h 2014-04-04 02:29:15 UTC (rev 166760)
@@ -29,6 +29,8 @@
class ScriptExecutionContext;
+static const uint8_t JSNodeType = JSC::LastJSCObjectType + 1;
+
class JSDOMWrapper : public JSC::JSDestructibleObject {
public:
typedef JSC::JSDestructibleObject Base;
Modified: trunk/Source/WebCore/bindings/js/JSNodeCustom.h (166759 => 166760)
--- trunk/Source/WebCore/bindings/js/JSNodeCustom.h 2014-04-04 02:24:28 UTC (rev 166759)
+++ trunk/Source/WebCore/bindings/js/JSNodeCustom.h 2014-04-04 02:29:15 UTC (rev 166760)
@@ -78,6 +78,13 @@
return root(&node);
}
+ALWAYS_INLINE JSNode* jsNodeCast(JSC::JSValue value)
+{
+ if (UNLIKELY(!value.isCell()))
+ return nullptr;
+ return value.asCell()->type() == JSNodeType ? JSC::jsCast<JSNode*>(value) : nullptr;
+}
+
} // namespace WebCore
#endif // JSDOMNodeCustom_h
Modified: trunk/Source/WebCore/bindings/scripts/CodeGeneratorJS.pm (166759 => 166760)
--- trunk/Source/WebCore/bindings/scripts/CodeGeneratorJS.pm 2014-04-04 02:24:28 UTC (rev 166759)
+++ trunk/Source/WebCore/bindings/scripts/CodeGeneratorJS.pm 2014-04-04 02:29:15 UTC (rev 166760)
@@ -959,6 +959,8 @@
push(@headerContent, " {\n");
if (IsDOMGlobalObject($interface)) {
push(@headerContent, " return JSC::Structure::create(vm, globalObject, prototype, JSC::TypeInfo(JSC::GlobalObjectType, StructureFlags), info());\n");
+ } elsif ($codeGenerator->InheritsInterface($interface, "Node")) {
+ push(@headerContent, " return JSC::Structure::create(vm, globalObject, prototype, JSC::TypeInfo(JSC::JSType(JSNodeType), StructureFlags), info());\n");
} else {
push(@headerContent, " return JSC::Structure::create(vm, globalObject, prototype, JSC::TypeInfo(JSC::ObjectType, StructureFlags), info());\n");
}
@@ -2130,7 +2132,11 @@
push(@implContent, " ${className}* castedThis = to${className}(JSValue::decode(thisValue));\n");
push(@implContent, " UNUSED_PARAM(slotBase);\n");
} else {
- push(@implContent, " ${className}* castedThis = jsDynamicCast<$className*>(JSValue::decode(thisValue));\n");
+ if ($interfaceName eq "Node") {
+ push(@implContent, " JSNode* castedThis = jsNodeCast(JSValue::decode(thisValue));\n");
+ } else {
+ push(@implContent, " ${className}* castedThis = jsDynamicCast<$className*>(JSValue::decode(thisValue));\n");
+ }
push(@implContent, " UNUSED_PARAM(slotBase);\n");
}
$implIncludes{"ScriptExecutionContext.h"} = 1;