From a28cca871fae89fc0bd7a3780bed10f7dd305706 Mon Sep 17 00:00:00 2001 From: "dglazkov@chromium.org" Date: Mon, 14 Dec 2009 22:17:19 +0000 Subject: [PATCH] 2009-12-14 Dimitri Glazkov Reviewed by Eric Seidel. [V8] Generate bindings for trivial indexers. https://bugs.webkit.org/show_bug.cgi?id=32455 Covered by existing tests. * bindings/scripts/CodeGeneratorV8.pm: Added detecting indexers and generating code for them. * bindings/v8/V8Collection.h: Removed code that's now generated. * bindings/v8/V8DOMWrapper.cpp: (WebCore::V8DOMWrapper::getTemplate): Ditto. git-svn-id: http://svn.webkit.org/repository/webkit/trunk@52120 268f45cc-cd09-0410-ab3c-d52691b4dbfc --- WebCore/ChangeLog | 15 +++++++++++ WebCore/bindings/scripts/CodeGeneratorV8.pm | 40 ++++++++++++++++++++++++++++- WebCore/bindings/v8/V8Collection.h | 11 -------- WebCore/bindings/v8/V8DOMWrapper.cpp | 25 +++--------------- 4 files changed, 57 insertions(+), 34 deletions(-) diff --git a/WebCore/ChangeLog b/WebCore/ChangeLog index 8a67e1b5a2..15758108bd 100644 --- a/WebCore/ChangeLog +++ b/WebCore/ChangeLog @@ -1,3 +1,18 @@ +2009-12-14 Dimitri Glazkov + + Reviewed by Eric Seidel. + + [V8] Generate bindings for trivial indexers. + https://bugs.webkit.org/show_bug.cgi?id=32455 + + Covered by existing tests. + + * bindings/scripts/CodeGeneratorV8.pm: + Added detecting indexers and generating code for them. + * bindings/v8/V8Collection.h: Removed code that's now generated. + * bindings/v8/V8DOMWrapper.cpp: + (WebCore::V8DOMWrapper::getTemplate): Ditto. + 2009-12-14 Alexey Proskuryakov Reviewed by Dave Hyatt. diff --git a/WebCore/bindings/scripts/CodeGeneratorV8.pm b/WebCore/bindings/scripts/CodeGeneratorV8.pm index 23b74e3d6b..9b6349f589 100644 --- a/WebCore/bindings/scripts/CodeGeneratorV8.pm +++ b/WebCore/bindings/scripts/CodeGeneratorV8.pm @@ -1127,6 +1127,37 @@ sub GenerateSingleBatchedAttribute END } +sub GenerateImplementationIndexer +{ + my $dataNode = shift; + my $indexer = shift; + my $interfaceName = $dataNode->name; + + if ($dataNode->extendedAttributes->{"HasIndexGetter"}) { + $implIncludes{"V8Collection.h"} = 1; + if (!$dataNode->extendedAttributes->{"HasCustomIndexGetter"}) { + if ($indexer->type eq "DOMString") { + my $conversion = $indexer->extendedAttributes->{"ConvertNullStringTo"}; + if ($conversion && $conversion eq "Null") { + push(@implContent, <(desc); +END + } else { + push(@implContent, <(desc); +END + } + } else { + my $indexerType = $indexer->type; + my $indexerClassIndex = uc($indexerType); + push(@implContent, <(desc, V8ClassIndex::${indexerClassIndex}); +END + } + } + } +} + sub GenerateImplementation { my $object = shift; @@ -1165,7 +1196,6 @@ sub GenerateImplementation push(@implContentDecls, "template void V8_USE(T) { }\n\n"); my $hasConstructors = 0; - # Generate property accessors for attributes. for ($index = 0; $index < @{$dataNode->attributes}; $index++) { $attribute = @{$dataNode->attributes}[$index]; @@ -1216,6 +1246,7 @@ sub GenerateImplementation GenerateConstructorGetter($implClassName, $classIndex); } + my $indexer; # Generate methods for functions. foreach my $function (@{$dataNode->functions}) { # hack for addEventListener/RemoveEventListener @@ -1226,6 +1257,10 @@ sub GenerateImplementation GenerateFunctionCallback($function, $dataNode, $classIndex, $implClassName); } + if ($function->signature->name eq "item") { + $indexer = $function->signature; + } + # If the function does not need domain security check, we need to # generate an access getter that returns different function objects # for different calling context. @@ -1244,6 +1279,7 @@ sub GenerateImplementation my @enabledAtRuntime; my @normal; foreach my $attribute (@$attributes) { + if ($interfaceName eq "DOMWindow" && $attribute->signature->extendedAttributes->{"V8DisallowShadowing"}) { push(@disallowsShadowing, $attribute); } elsif ($attribute->signature->extendedAttributes->{"EnabledAtRuntime"}) { @@ -1409,6 +1445,8 @@ END push(@implContent, "\n#endif // ${conditionalString}\n") if $conditionalString; } + GenerateImplementationIndexer($dataNode, $indexer) if $indexer; + # Define our functions with Set() or SetAccessor() $total_functions = 0; foreach my $function (@{$dataNode->functions}) { diff --git a/WebCore/bindings/v8/V8Collection.h b/WebCore/bindings/v8/V8Collection.h index 0a4134e0a8..8dea839176 100644 --- a/WebCore/bindings/v8/V8Collection.h +++ b/WebCore/bindings/v8/V8Collection.h @@ -203,17 +203,6 @@ namespace WebCore { desc->InstanceTemplate()->SetNamedPropertyHandler(collectionNamedPropertyGetter, 0, 0, 0, 0, v8::Integer::New(V8ClassIndex::ToInt(type))); } - - // Add named and indexed getters to the function template for a collection. - template static void setCollectionIndexedAndNamedGetters(v8::Handle desc, V8ClassIndex::V8WrapperType type) - { - // If we interceptor before object, accessing 'length' can trigger a webkit assertion error (see fast/dom/HTMLDocument/document-special-properties.html). - desc->InstanceTemplate()->SetNamedPropertyHandler(collectionNamedPropertyGetter, 0, 0, 0, 0, v8::Integer::New(V8ClassIndex::ToInt(type))); - desc->InstanceTemplate()->SetIndexedPropertyHandler(collectionIndexedPropertyGetter, 0, 0, 0, collectionIndexedPropertyEnumerator, - v8::Integer::New(V8ClassIndex::ToInt(type))); - } - - // Add indexed getter returning a string or null to a function template for a collection. template static void setCollectionStringOrNullIndexedGetter(v8::Handle desc) { diff --git a/WebCore/bindings/v8/V8DOMWrapper.cpp b/WebCore/bindings/v8/V8DOMWrapper.cpp index 6591325658..4263e73f0c 100644 --- a/WebCore/bindings/v8/V8DOMWrapper.cpp +++ b/WebCore/bindings/v8/V8DOMWrapper.cpp @@ -276,26 +276,12 @@ v8::Persistent V8DOMWrapper::getTemplate(V8ClassIndex::V8W // setter. Therefore, the interceptor has to be on the object // itself and not on the prototype object. descriptor->InstanceTemplate()->SetNamedPropertyHandler( USE_NAMED_PROPERTY_GETTER(CSSStyleDeclaration), USE_NAMED_PROPERTY_SETTER(CSSStyleDeclaration)); - setCollectionStringIndexedGetter(descriptor); - break; - case V8ClassIndex::CSSRULELIST: - setCollectionIndexedGetter(descriptor, V8ClassIndex::CSSRULE); - break; - case V8ClassIndex::CSSVALUELIST: - setCollectionIndexedGetter(descriptor, V8ClassIndex::CSSVALUE); - break; - case V8ClassIndex::CSSVARIABLESDECLARATION: - setCollectionStringIndexedGetter(descriptor); - break; - case V8ClassIndex::WEBKITCSSTRANSFORMVALUE: - setCollectionIndexedGetter(descriptor, V8ClassIndex::CSSVALUE); break; case V8ClassIndex::HTMLALLCOLLECTION: descriptor->InstanceTemplate()->MarkAsUndetectable(); // fall through case V8ClassIndex::HTMLCOLLECTION: descriptor->InstanceTemplate()->SetNamedPropertyHandler(USE_NAMED_PROPERTY_GETTER(HTMLCollection)); descriptor->InstanceTemplate()->SetCallAsFunctionHandler(USE_CALLBACK(HTMLCollectionCallAsFunction)); - setCollectionIndexedGetter(descriptor, V8ClassIndex::NODE); break; case V8ClassIndex::HTMLOPTIONSCOLLECTION: descriptor->InstanceTemplate()->SetNamedPropertyHandler(USE_NAMED_PROPERTY_GETTER(HTMLCollection)); @@ -361,11 +347,8 @@ v8::Persistent V8DOMWrapper::getTemplate(V8ClassIndex::V8W instanceTemplate->SetInternalFieldCount(V8Custom::kStyleSheetInternalFieldCount); break; } - case V8ClassIndex::MEDIALIST: - setCollectionStringOrNullIndexedGetter(descriptor); - break; case V8ClassIndex::MIMETYPEARRAY: - setCollectionIndexedAndNamedGetters(descriptor, V8ClassIndex::MIMETYPE); + setCollectionNamedGetter(descriptor, V8ClassIndex::MIMETYPE); break; case V8ClassIndex::NAMEDNODEMAP: { // We add an extra internal field to hold a reference to the owner node. @@ -383,18 +366,16 @@ v8::Persistent V8DOMWrapper::getTemplate(V8ClassIndex::V8W break; #endif case V8ClassIndex::NODELIST: - setCollectionIndexedGetter(descriptor, V8ClassIndex::NODE); descriptor->InstanceTemplate()->SetNamedPropertyHandler(USE_NAMED_PROPERTY_GETTER(NodeList)); break; case V8ClassIndex::PLUGIN: - setCollectionIndexedAndNamedGetters(descriptor, V8ClassIndex::MIMETYPE); + setCollectionNamedGetter(descriptor, V8ClassIndex::MIMETYPE); break; case V8ClassIndex::PLUGINARRAY: - setCollectionIndexedAndNamedGetters(descriptor, V8ClassIndex::PLUGIN); + setCollectionNamedGetter(descriptor, V8ClassIndex::PLUGIN); break; case V8ClassIndex::STYLESHEETLIST: descriptor->InstanceTemplate()->SetNamedPropertyHandler(USE_NAMED_PROPERTY_GETTER(StyleSheetList)); - setCollectionIndexedGetter(descriptor, V8ClassIndex::STYLESHEET); break; case V8ClassIndex::DOMWINDOW: { v8::Local defaultSignature = v8::Signature::New(descriptor); -- 2.11.4.GIT