[SCM] WebKit Debian packaging branch, webkit-1.1, updated. upstream/1.1.16-1409-g5afdf4d
snej at chromium.org
snej at chromium.org
Thu Dec 3 13:34:32 UTC 2009
The following commit has been merged in the webkit-1.1 branch:
commit 08181fb191b66378708df7a08a2a6999e9666d09
Author: snej at chromium.org <snej at chromium.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Date: Thu Nov 12 21:17:23 2009 +0000
Table-driven setup for V8 binding template callback functions. 100k in code savings.
https://bugs.webkit.org/show_bug.cgi?id=31420
Reviewed by Dimitri Glazkov.
* bindings/scripts/CodeGeneratorV8.pm: Change generated ConfigureXXXTemplate fn
to call configureTemplate().
* bindings/v8/V8Binding.cpp:
(WebCore::configureTemplate): New function; does all the standard configuration work.
(WebCore::createCallback): De-inlined wrapper for FunctionTemplate creation.
* bindings/v8/V8Binding.h:
* bindings/v8/V8Proxy.cpp:
(WebCore::batchConfigureAttributes): Just wrapped the very long fn parameter list.
(WebCore::batchConfigureCallbacks): New function, used by configureTemplate.
(WebCore::batchConfigureConstants): Just wrapped the very long fn parameter list.
* bindings/v8/V8Proxy.h:
git-svn-id: http://svn.webkit.org/repository/webkit/trunk@50897 268f45cc-cd09-0410-ab3c-d52691b4dbfc
diff --git a/WebCore/ChangeLog b/WebCore/ChangeLog
index 968b91d..c3b63d4 100644
--- a/WebCore/ChangeLog
+++ b/WebCore/ChangeLog
@@ -1,3 +1,22 @@
+2009-11-12 Jens Alfke <snej at chromium.org>
+
+ Reviewed by Dimitri Glazkov.
+
+ Table-driven setup for V8 binding template callback functions. 100k in code savings.
+ https://bugs.webkit.org/show_bug.cgi?id=31420
+
+ * bindings/scripts/CodeGeneratorV8.pm: Change generated ConfigureXXXTemplate fn
+ to call configureTemplate().
+ * bindings/v8/V8Binding.cpp:
+ (WebCore::configureTemplate): New function; does all the standard configuration work.
+ (WebCore::createCallback): De-inlined wrapper for FunctionTemplate creation.
+ * bindings/v8/V8Binding.h:
+ * bindings/v8/V8Proxy.cpp:
+ (WebCore::batchConfigureAttributes): Just wrapped the very long fn parameter list.
+ (WebCore::batchConfigureCallbacks): New function, used by configureTemplate.
+ (WebCore::batchConfigureConstants): Just wrapped the very long fn parameter list.
+ * bindings/v8/V8Proxy.h:
+
2009-11-12 Dumitru Daniliuc <dumi at chromium.org>
Unreviewed, fix Chromium build after http://trac.webkit.org/changeset/50876.
diff --git a/WebCore/bindings/scripts/CodeGeneratorV8.pm b/WebCore/bindings/scripts/CodeGeneratorV8.pm
index 835b3c6..bd60971 100644
--- a/WebCore/bindings/scripts/CodeGeneratorV8.pm
+++ b/WebCore/bindings/scripts/CodeGeneratorV8.pm
@@ -793,12 +793,11 @@ END
push(@implContentDecls, " }\n\n"); # end of setter
}
-sub GenerateNewFunctionTemplate
+sub GetFunctionTemplateCallbackName
{
$function = shift;
$dataNode = shift;
- $signature = shift;
-
+
my $interfaceName = $dataNode->name;
my $name = $function->signature->name;
@@ -813,12 +812,22 @@ sub GenerateNewFunctionTemplate
if ($customFunc eq 1) {
$customFunc = $interfaceName . $codeGenerator->WK_ucfirst($name);
}
- return "v8::FunctionTemplate::New(V8Custom::v8${customFunc}Callback, v8::Handle<v8::Value>(), $signature)";
+ return "V8Custom::v8${customFunc}Callback";
} else {
- return "v8::FunctionTemplate::New(${interfaceName}Internal::${name}Callback, v8::Handle<v8::Value>(), $signature)";
+ return "${interfaceName}Internal::${name}Callback";
}
}
+sub GenerateNewFunctionTemplate
+{
+ $function = shift;
+ $dataNode = shift;
+ $signature = shift;
+
+ my $callback = GetFunctionTemplateCallbackName($function, $dataNode);
+ return "v8::FunctionTemplate::New($callback, v8::Handle<v8::Value>(), $signature)";
+}
+
sub GenerateFunctionCallback
{
my $function = shift;
@@ -1206,6 +1215,38 @@ sub GenerateImplementation
GenerateBatchedAttributeData($dataNode, $attributes);
push(@implContent, "};\n");
}
+
+ # Setup table of standard callback functions
+ $num_callbacks = 0;
+ $has_callbacks = 0;
+ foreach my $function (@{$dataNode->functions}) {
+ my $attrExt = $function->signature->extendedAttributes;
+ # Don't put any nonstandard functions into this table:
+ if ($attrExt->{"V8OnInstance"}) {
+ next;
+ }
+ if ($attrExt->{"EnabledAtRuntime"} || RequiresCustomSignature($function) || $attrExt->{"V8DoNotCheckSignature"}) {
+ next;
+ }
+ if ($attrExt->{"DoNotCheckDomainSecurity"} &&
+ ($dataNode->extendedAttributes->{"CheckDomainSecurity"} || $interfaceName eq "DOMWindow")) {
+ next;
+ }
+ if ($attrExt->{"DontEnum"} || $attrExt->{"V8ReadOnly"}) {
+ next;
+ }
+ if (!$has_callbacks) {
+ $has_callbacks = 1;
+ push(@implContent, "static const BatchedCallback ${interfaceName}_callbacks[] = {\n");
+ }
+ my $name = $function->signature->name;
+ my $callback = GetFunctionTemplateCallbackName($function, $dataNode);
+ push(@implContent, <<END);
+ {"$name", $callback},
+END
+ $num_callbacks++;
+ }
+ push(@implContent, "};\n") if $has_callbacks;
# Setup constants
my $has_constants = 0;
@@ -1229,7 +1270,7 @@ END
push(@implContentDecls, "} // namespace ${interfaceName}Internal\n\n");
- my $access_check = "/* no access check */";
+ my $access_check = "";
if ($dataNode->extendedAttributes->{"CheckDomainSecurity"} && !($interfaceName eq "DOMWindow")) {
$access_check = "instance->SetAccessCheckCallbacks(V8Custom::v8${interfaceName}NamedSecurityCheck, V8Custom::v8${interfaceName}IndexedSecurityCheck, v8::Integer::New(V8ClassIndex::ToInt(V8ClassIndex::${classIndex})));";
}
@@ -1248,35 +1289,59 @@ static v8::Persistent<v8::ObjectTemplate> ConfigureShadowObjectTemplate(v8::Pers
END
}
+ # find the super descriptor
+ my $parentClassIndex = "INVALID_CLASS_INDEX";
+ foreach (@{$dataNode->parents}) {
+ my $parent = $codeGenerator->StripModule($_);
+ if ($parent eq "EventTarget") { next; }
+ $implIncludes{"V8${parent}.h"} = 1;
+ $parentClassIndex = uc($codeGenerator->StripModule($parent));
+ last;
+ }
+
+ # find the field count
+ my $fieldCount = "V8Custom::kDefaultWrapperInternalFieldCount";
+ if (IsNodeSubType($dataNode)) {
+ $fieldCount = "V8Custom::kNodeMinimumInternalFieldCount";
+ }
+
# Generate the template configuration method
push(@implContent, <<END);
static v8::Persistent<v8::FunctionTemplate> Configure${className}Template(v8::Persistent<v8::FunctionTemplate> desc) {
- v8::Local<v8::ObjectTemplate> instance = desc->InstanceTemplate();
+ v8::Local<v8::Signature> default_signature = configureTemplate(desc, \"${interfaceName}\",
+ V8ClassIndex::$parentClassIndex, $fieldCount,
END
- if (IsNodeSubType($dataNode)) {
+
+ # Set up our attributes if we have them
+ if ($has_attributes) {
push(@implContent, <<END);
- instance->SetInternalFieldCount(V8Custom::kNodeMinimumInternalFieldCount);
+ ${interfaceName}_attrs, sizeof(${interfaceName}_attrs)/sizeof(*${interfaceName}_attrs),
END
} else {
push(@implContent, <<END);
- instance->SetInternalFieldCount(V8Custom::kDefaultWrapperInternalFieldCount);
+ NULL, 0,
+END
+ }
+
+ if ($has_callbacks) {
+ push(@implContent, <<END);
+ ${interfaceName}_callbacks, sizeof(${interfaceName}_callbacks)/sizeof(*${interfaceName}_callbacks));
+END
+ } else {
+ push(@implContent, <<END);
+ NULL, 0);
END
}
+ if ($access_check or @enabledAtRuntime or @{$dataNode->functions} or $has_constants) {
push(@implContent, <<END);
- v8::Local<v8::Signature> default_signature = v8::Signature::New(desc);
+ v8::Local<v8::ObjectTemplate> instance = desc->InstanceTemplate();
v8::Local<v8::ObjectTemplate> proto = desc->PrototypeTemplate();
- $access_check
-END
-
-
- # Set up our attributes if we have them
- if ($has_attributes) {
- push(@implContent, <<END);
- batchConfigureAttributes(instance, proto, ${interfaceName}_attrs, sizeof(${interfaceName}_attrs)/sizeof(*${interfaceName}_attrs));
END
}
+ push(@implContent, " $access_check\n");
+
# Setup the enable-at-runtime attrs if we have them
foreach my $runtime_attr (@enabledAtRuntime) {
$enable_function = $interfaceName . $codeGenerator->WK_ucfirst($runtime_attr->signature->name);
@@ -1293,7 +1358,9 @@ END
}
# Define our functions with Set() or SetAccessor()
+ $total_functions = 0;
foreach my $function (@{$dataNode->functions}) {
+ $total_functions++;
my $attrExt = $function->signature->extendedAttributes;
my $name = $function->signature->name;
@@ -1347,6 +1414,7 @@ END
v8::ALL_CAN_READ,
static_cast<v8::PropertyAttribute>($property_attributes));
END
+ $num_callbacks++;
next;
}
@@ -1361,31 +1429,26 @@ END
}
# Normal function call is a template
- my $templateFunction = GenerateNewFunctionTemplate($function, $dataNode, $signature);
-
-
+ my $callback = GetFunctionTemplateCallbackName($function, $dataNode);
+
+ if ($property_attributes eq "v8::DontDelete") {
+ $property_attributes = "";
+ } else {
+ $property_attributes = ", static_cast<v8::PropertyAttribute>($property_attributes)";
+ }
+
+ if ($template eq "proto" && $conditional eq "" && $signature eq "default_signature" && $property_attributes eq "") {
+ # Standard type of callback, already created in the batch, so skip it here.
+ next;
+ }
+
push(@implContent, <<END);
-
- // $commentInfo
- $conditional ${template}->Set(
- v8::String::New("$name"),
- $templateFunction,
- static_cast<v8::PropertyAttribute>($property_attributes));
+ ${conditional}createCallback($template, "$name", $callback, ${signature}$property_attributes);
END
+ $num_callbacks++;
}
-
- # set the super descriptor
- foreach (@{$dataNode->parents}) {
- my $parent = $codeGenerator->StripModule($_);
- if ($parent eq "EventTarget") { next; }
- $implIncludes{"V8${parent}.h"} = 1;
- my $parentClassIndex = uc($codeGenerator->StripModule($parent));
- push(@implContent, " desc->Inherit(V8DOMWrapper::getTemplate(V8ClassIndex::${parentClassIndex}));\n");
- last;
- }
-
- # Set the class name. This is used when printing objects.
- push(@implContent, " desc->SetClassName(v8::String::New(\"${interfaceName}\"));\n");
+
+ die "Wrong number of callbacks generated for $interfaceName ($num_callbacks, should be $total_functions)" if $num_callbacks != $total_functions;
if ($has_constants) {
push(@implContent, <<END);
diff --git a/WebCore/bindings/v8/V8Binding.cpp b/WebCore/bindings/v8/V8Binding.cpp
index 30e6610..ede85a4 100644
--- a/WebCore/bindings/v8/V8Binding.cpp
+++ b/WebCore/bindings/v8/V8Binding.cpp
@@ -387,4 +387,41 @@ v8::Persistent<v8::FunctionTemplate> createRawTemplate()
return v8::Persistent<v8::FunctionTemplate>::New(result);
}
+v8::Local<v8::Signature> configureTemplate(v8::Persistent<v8::FunctionTemplate>desc,
+ const char *interfaceName,
+ V8ClassIndex::V8WrapperType parentClassIndex,
+ int fieldCount,
+ const BatchedAttribute* attributes,
+ size_t attributeCount,
+ const BatchedCallback* callbacks,
+ size_t callbackCount)
+{
+ desc->SetClassName(v8::String::New(interfaceName));
+ v8::Local<v8::ObjectTemplate> instance = desc->InstanceTemplate();
+ instance->SetInternalFieldCount(fieldCount);
+ if (parentClassIndex)
+ desc->Inherit(V8DOMWrapper::getTemplate(parentClassIndex));
+ if (attributeCount)
+ batchConfigureAttributes(instance, desc->PrototypeTemplate(),
+ attributes, attributeCount);
+ v8::Local<v8::Signature> defaultSignature = v8::Signature::New(desc);
+ if (callbackCount)
+ batchConfigureCallbacks(desc->PrototypeTemplate(),
+ defaultSignature,
+ static_cast<v8::PropertyAttribute>(v8::DontDelete),
+ callbacks, callbackCount);
+ return defaultSignature;
+}
+
+void createCallback(v8::Local<v8::ObjectTemplate> proto,
+ const char *name,
+ v8::InvocationCallback callback,
+ v8::Handle<v8::Signature> signature,
+ v8::PropertyAttribute attribute)
+{
+ proto->Set(v8::String::New(name),
+ v8::FunctionTemplate::New(callback, v8::Handle<v8::Value>(), signature),
+ attribute);
+}
+
} // namespace WebCore
diff --git a/WebCore/bindings/v8/V8Binding.h b/WebCore/bindings/v8/V8Binding.h
index 4447453..3ce0526 100644
--- a/WebCore/bindings/v8/V8Binding.h
+++ b/WebCore/bindings/v8/V8Binding.h
@@ -203,6 +203,24 @@ namespace WebCore {
v8::Persistent<v8::FunctionTemplate> createRawTemplate();
+ struct BatchedAttribute;
+ struct BatchedCallback;
+
+ v8::Local<v8::Signature> configureTemplate(v8::Persistent<v8::FunctionTemplate>,
+ const char *interfaceName,
+ V8ClassIndex::V8WrapperType parentClassIndex,
+ int fieldCount,
+ const BatchedAttribute*,
+ size_t attributeCount,
+ const BatchedCallback*,
+ size_t callbackCount);
+
+ void createCallback(v8::Local<v8::ObjectTemplate> proto,
+ const char *name,
+ v8::InvocationCallback,
+ v8::Handle<v8::Signature>,
+ v8::PropertyAttribute attributes = v8::DontDelete);
+
} // namespace WebCore
#endif // V8Binding_h
diff --git a/WebCore/bindings/v8/V8Proxy.cpp b/WebCore/bindings/v8/V8Proxy.cpp
index 45ac1ea..b785f41 100644
--- a/WebCore/bindings/v8/V8Proxy.cpp
+++ b/WebCore/bindings/v8/V8Proxy.cpp
@@ -72,13 +72,34 @@ V8Extensions V8Proxy::m_extensions;
const char* V8Proxy::kContextDebugDataType = "type";
const char* V8Proxy::kContextDebugDataValue = "value";
-void batchConfigureAttributes(v8::Handle<v8::ObjectTemplate> instance, v8::Handle<v8::ObjectTemplate> proto, const BatchedAttribute* attributes, size_t attributeCount)
+void batchConfigureAttributes(v8::Handle<v8::ObjectTemplate> instance,
+ v8::Handle<v8::ObjectTemplate> proto,
+ const BatchedAttribute* attributes,
+ size_t attributeCount)
{
for (size_t i = 0; i < attributeCount; ++i)
configureAttribute(instance, proto, attributes[i]);
}
-void batchConfigureConstants(v8::Handle<v8::FunctionTemplate> functionDescriptor, v8::Handle<v8::ObjectTemplate> proto, const BatchedConstant* constants, size_t constantCount)
+void batchConfigureCallbacks(v8::Handle<v8::ObjectTemplate> proto,
+ v8::Handle<v8::Signature> signature,
+ v8::PropertyAttribute attributes,
+ const BatchedCallback* callbacks,
+ size_t callbackCount)
+{
+ for (size_t i = 0; i < callbackCount; ++i) {
+ proto->Set(v8::String::New(callbacks[i].name),
+ v8::FunctionTemplate::New(callbacks[i].callback,
+ v8::Handle<v8::Value>(),
+ signature),
+ attributes);
+ }
+}
+
+void batchConfigureConstants(v8::Handle<v8::FunctionTemplate> functionDescriptor,
+ v8::Handle<v8::ObjectTemplate> proto,
+ const BatchedConstant* constants,
+ size_t constantCount)
{
for (size_t i = 0; i < constantCount; ++i) {
const BatchedConstant* constant = &constants[i];
diff --git a/WebCore/bindings/v8/V8Proxy.h b/WebCore/bindings/v8/V8Proxy.h
index 9882a4c..99ae1f2 100644
--- a/WebCore/bindings/v8/V8Proxy.h
+++ b/WebCore/bindings/v8/V8Proxy.h
@@ -102,6 +102,17 @@ namespace WebCore {
void batchConfigureConstants(v8::Handle<v8::FunctionTemplate>, v8::Handle<v8::ObjectTemplate>, const BatchedConstant*, size_t constantCount);
+ struct BatchedCallback {
+ const char* const name;
+ v8::InvocationCallback callback;
+ };
+
+ void batchConfigureCallbacks(v8::Handle<v8::ObjectTemplate>,
+ v8::Handle<v8::Signature>,
+ v8::PropertyAttribute,
+ const BatchedCallback*,
+ size_t callbackCount);
+
const int kMaxRecursionDepth = 20;
// Information about an extension that is registered for use with V8. If
--
WebKit Debian packaging
More information about the Pkg-webkit-commits
mailing list