WebCore/ChangeLog

 12009-12-11 Dimitri Glazkov <dglazkov@chromium.org>
 2
 3 Reviewed by NOBODY (OOPS!).
 4
 5 [V8] Generate bindings for trivial indexers.
 6 https://bugs.webkit.org/show_bug.cgi?id=32455
 7
 8 Covered by existing tests.
 9
 10 * bindings/scripts/CodeGeneratorV8.pm:
 11 Added detecting indexers and generating code for them.
 12 * bindings/v8/V8Collection.h: Removed code that's now generated.
 13 * bindings/v8/V8DOMWrapper.cpp:
 14 (WebCore::V8DOMWrapper::getTemplate): Ditto.
 15
1162009-12-14 Dimitri Glazkov <dglazkov@chromium.org>
217
318 Unreviewed, build fix.

WebCore/bindings/scripts/CodeGeneratorV8.pm

@@sub GenerateSingleBatchedAttribute
11271127END
11281128}
11291129
 1130sub GenerateImplementationIndexer
 1131{
 1132 my $dataNode = shift;
 1133 my $indexer = shift;
 1134 my $interfaceName = $dataNode->name;
 1135
 1136 if ($dataNode->extendedAttributes->{"HasIndexGetter"}) {
 1137 $implIncludes{"V8Collection.h"} = 1;
 1138 if (!$dataNode->extendedAttributes->{"HasCustomIndexGetter"}) {
 1139 if ($indexer->type eq "DOMString") {
 1140 my $conversion = $indexer->extendedAttributes->{"ConvertNullStringTo"};
 1141 if ($conversion && $conversion eq "Null") {
 1142 push(@implContent, <<END);
 1143 setCollectionStringOrNullIndexedGetter<${interfaceName}>(desc);
 1144END
 1145 } else {
 1146 push(@implContent, <<END);
 1147 setCollectionStringIndexedGetter<${interfaceName}>(desc);
 1148END
 1149 }
 1150 } else {
 1151 my $indexerType = $indexer->type;
 1152 my $indexerClassIndex = uc($indexerType);
 1153 push(@implContent, <<END);
 1154 setCollectionIndexedGetter<${interfaceName}, ${indexerType}>(desc, V8ClassIndex::${indexerClassIndex});
 1155END
 1156 }
 1157 }
 1158 }
 1159}
 1160
11301161sub GenerateImplementation
11311162{
11321163 my $object = shift;

@@sub GenerateImplementation
11651196 push(@implContentDecls, "template <typename T> void V8_USE(T) { }\n\n");
11661197
11671198 my $hasConstructors = 0;
1168 
11691199 # Generate property accessors for attributes.
11701200 for ($index = 0; $index < @{$dataNode->attributes}; $index++) {
11711201 $attribute = @{$dataNode->attributes}[$index];

@@sub GenerateImplementation
12161246 GenerateConstructorGetter($implClassName, $classIndex);
12171247 }
12181248
 1249 my $indexer;
12191250 # Generate methods for functions.
12201251 foreach my $function (@{$dataNode->functions}) {
12211252 # hack for addEventListener/RemoveEventListener

@@sub GenerateImplementation
12261257 GenerateFunctionCallback($function, $dataNode, $classIndex, $implClassName);
12271258 }
12281259
 1260 if ($function->signature->name eq "item") {
 1261 $indexer = $function->signature;
 1262 }
 1263
12291264 # If the function does not need domain security check, we need to
12301265 # generate an access getter that returns different function objects
12311266 # for different calling context.

@@sub GenerateImplementation
12441279 my @enabledAtRuntime;
12451280 my @normal;
12461281 foreach my $attribute (@$attributes) {
 1282
12471283 if ($interfaceName eq "DOMWindow" && $attribute->signature->extendedAttributes->{"V8DisallowShadowing"}) {
12481284 push(@disallowsShadowing, $attribute);
12491285 } elsif ($attribute->signature->extendedAttributes->{"EnabledAtRuntime"}) {

@@END
14091445 push(@implContent, "\n#endif // ${conditionalString}\n") if $conditionalString;
14101446 }
14111447
 1448 GenerateImplementationIndexer($dataNode, $indexer) if $indexer;
 1449
14121450 # Define our functions with Set() or SetAccessor()
14131451 $total_functions = 0;
14141452 foreach my $function (@{$dataNode->functions}) {

WebCore/bindings/v8/V8Collection.h

@@namespace WebCore {
203203 desc->InstanceTemplate()->SetNamedPropertyHandler(collectionNamedPropertyGetter<Collection, ItemType>, 0, 0, 0, 0, v8::Integer::New(V8ClassIndex::ToInt(type)));
204204 }
205205
206 
207  // Add named and indexed getters to the function template for a collection.
208  template<class Collection, class ItemType> static void setCollectionIndexedAndNamedGetters(v8::Handle<v8::FunctionTemplate> desc, V8ClassIndex::V8WrapperType type)
209  {
210  // If we interceptor before object, accessing 'length' can trigger a webkit assertion error (see fast/dom/HTMLDocument/document-special-properties.html).
211  desc->InstanceTemplate()->SetNamedPropertyHandler(collectionNamedPropertyGetter<Collection, ItemType>, 0, 0, 0, 0, v8::Integer::New(V8ClassIndex::ToInt(type)));
212  desc->InstanceTemplate()->SetIndexedPropertyHandler(collectionIndexedPropertyGetter<Collection, ItemType>, 0, 0, 0, collectionIndexedPropertyEnumerator<Collection>,
213  v8::Integer::New(V8ClassIndex::ToInt(type)));
214  }
215 
216 
217206 // Add indexed getter returning a string or null to a function template for a collection.
218207 template<class Collection> static void setCollectionStringOrNullIndexedGetter(v8::Handle<v8::FunctionTemplate> desc)
219208 {

WebCore/bindings/v8/V8DOMWrapper.cpp

@@v8::Persistent<v8::FunctionTemplate> V8DOMWrapper::getTemplate(V8ClassIndex::V8W
276276 // setter. Therefore, the interceptor has to be on the object
277277 // itself and not on the prototype object.
278278 descriptor->InstanceTemplate()->SetNamedPropertyHandler( USE_NAMED_PROPERTY_GETTER(CSSStyleDeclaration), USE_NAMED_PROPERTY_SETTER(CSSStyleDeclaration));
279  setCollectionStringIndexedGetter<CSSStyleDeclaration>(descriptor);
280  break;
281  case V8ClassIndex::CSSRULELIST:
282  setCollectionIndexedGetter<CSSRuleList, CSSRule>(descriptor, V8ClassIndex::CSSRULE);
283  break;
284  case V8ClassIndex::CSSVALUELIST:
285  setCollectionIndexedGetter<CSSValueList, CSSValue>(descriptor, V8ClassIndex::CSSVALUE);
286  break;
287  case V8ClassIndex::CSSVARIABLESDECLARATION:
288  setCollectionStringIndexedGetter<CSSVariablesDeclaration>(descriptor);
289  break;
290  case V8ClassIndex::WEBKITCSSTRANSFORMVALUE:
291  setCollectionIndexedGetter<WebKitCSSTransformValue, CSSValue>(descriptor, V8ClassIndex::CSSVALUE);
292279 break;
293280 case V8ClassIndex::HTMLALLCOLLECTION:
294281 descriptor->InstanceTemplate()->MarkAsUndetectable(); // fall through
295282 case V8ClassIndex::HTMLCOLLECTION:
296283 descriptor->InstanceTemplate()->SetNamedPropertyHandler(USE_NAMED_PROPERTY_GETTER(HTMLCollection));
297284 descriptor->InstanceTemplate()->SetCallAsFunctionHandler(USE_CALLBACK(HTMLCollectionCallAsFunction));
298  setCollectionIndexedGetter<HTMLCollection, Node>(descriptor, V8ClassIndex::NODE);
299285 break;
300286 case V8ClassIndex::HTMLOPTIONSCOLLECTION:
301287 descriptor->InstanceTemplate()->SetNamedPropertyHandler(USE_NAMED_PROPERTY_GETTER(HTMLCollection));

@@v8::Persistent<v8::FunctionTemplate> V8DOMWrapper::getTemplate(V8ClassIndex::V8W
361347 instanceTemplate->SetInternalFieldCount(V8Custom::kStyleSheetInternalFieldCount);
362348 break;
363349 }
364  case V8ClassIndex::MEDIALIST:
365  setCollectionStringOrNullIndexedGetter<MediaList>(descriptor);
366  break;
367350 case V8ClassIndex::MIMETYPEARRAY:
368  setCollectionIndexedAndNamedGetters<MimeTypeArray, MimeType>(descriptor, V8ClassIndex::MIMETYPE);
 351 setCollectionNamedGetter<MimeTypeArray, MimeType>(descriptor, V8ClassIndex::MIMETYPE);
369352 break;
370353 case V8ClassIndex::NAMEDNODEMAP: {
371354 // We add an extra internal field to hold a reference to the owner node.

@@v8::Persistent<v8::FunctionTemplate> V8DOMWrapper::getTemplate(V8ClassIndex::V8W
383366 break;
384367#endif
385368 case V8ClassIndex::NODELIST:
386  setCollectionIndexedGetter<NodeList, Node>(descriptor, V8ClassIndex::NODE);
387369 descriptor->InstanceTemplate()->SetNamedPropertyHandler(USE_NAMED_PROPERTY_GETTER(NodeList));
388370 break;
389371 case V8ClassIndex::PLUGIN:
390  setCollectionIndexedAndNamedGetters<Plugin, MimeType>(descriptor, V8ClassIndex::MIMETYPE);
 372 setCollectionNamedGetter<Plugin, MimeType>(descriptor, V8ClassIndex::MIMETYPE);
391373 break;
392374 case V8ClassIndex::PLUGINARRAY:
393  setCollectionIndexedAndNamedGetters<PluginArray, Plugin>(descriptor, V8ClassIndex::PLUGIN);
 375 setCollectionNamedGetter<PluginArray, Plugin>(descriptor, V8ClassIndex::PLUGIN);
394376 break;
395377 case V8ClassIndex::STYLESHEETLIST:
396378 descriptor->InstanceTemplate()->SetNamedPropertyHandler(USE_NAMED_PROPERTY_GETTER(StyleSheetList));
397  setCollectionIndexedGetter<StyleSheetList, StyleSheet>(descriptor, V8ClassIndex::STYLESHEET);
398379 break;
399380 case V8ClassIndex::DOMWINDOW: {
400381 v8::Local<v8::Signature> defaultSignature = v8::Signature::New(descriptor);