Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(164)

Unified Diff: Source/bindings/scripts/CodeGeneratorV8.pm

Issue 13933014: Gen index getter by unified way instead of using several helper function in some special cases. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink@master
Patch Set: refined Created 7 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: Source/bindings/scripts/CodeGeneratorV8.pm
diff --git a/Source/bindings/scripts/CodeGeneratorV8.pm b/Source/bindings/scripts/CodeGeneratorV8.pm
index 4947379dbabcd922b1236f3d7a1a9e9e8688917f..ea5dba3fec709bba19f5542edc8706d22fdbad80 100644
--- a/Source/bindings/scripts/CodeGeneratorV8.pm
+++ b/Source/bindings/scripts/CodeGeneratorV8.pm
@@ -717,7 +717,7 @@ sub GenerateHeaderNamedAndIndexedPropertyAccessors
{
my $interface = shift;
my $interfaceName = $interface->name;
- my $hasCustomIndexedGetter = $interface->extendedAttributes->{"IndexedGetter"} || $interface->extendedAttributes->{"CustomGetOwnPropertySlot"};
+ my $hasIndexedGetter = $interface->extendedAttributes->{"IndexedGetter"} || $interface->extendedAttributes->{"CustomIndexedGetter"};
my $hasCustomIndexedSetter = $interface->extendedAttributes->{"CustomIndexedSetter"} && !$interface->extendedAttributes->{"NumericIndexedGetter"};
my $hasCustomNamedGetter = $interface->extendedAttributes->{"NamedGetter"} || $interface->extendedAttributes->{"CustomNamedGetter"} || $interface->extendedAttributes->{"CustomGetOwnPropertySlot"};
my $hasCustomNamedSetter = $interface->extendedAttributes->{"CustomNamedSetter"};
@@ -725,7 +725,7 @@ sub GenerateHeaderNamedAndIndexedPropertyAccessors
my $hasCustomEnumerator = $interface->extendedAttributes->{"CustomEnumerateProperty"};
if ($interfaceName eq "HTMLOptionsCollection") {
$interfaceName = "HTMLCollection";
- $hasCustomIndexedGetter = 1;
+ $hasIndexedGetter = 1;
$hasCustomNamedGetter = 1;
}
if ($interfaceName eq "DOMWindow") {
@@ -737,17 +737,21 @@ sub GenerateHeaderNamedAndIndexedPropertyAccessors
}
if ($interfaceName eq "HTMLDocument") {
$hasCustomNamedGetter = 0;
- $hasCustomIndexedGetter = 0;
+ $hasIndexedGetter = 0;
}
my $isIndexerSpecialCase = exists $indexerSpecialCases{$interfaceName};
+ if ($isIndexerSpecialCase) {
+ $hasIndexedGetter = 1;
+ $hasCustomIndexedSetter = 1;
+ }
- if ($hasCustomIndexedGetter || $isIndexerSpecialCase) {
+ if ($hasIndexedGetter) {
AddToHeader(<<END);
static v8::Handle<v8::Value> indexedPropertyGetter(uint32_t, const v8::AccessorInfo&);
END
}
- if ($isIndexerSpecialCase || $hasCustomIndexedSetter) {
+ if ($hasCustomIndexedSetter) {
AddToHeader(<<END);
static v8::Handle<v8::Value> indexedPropertySetter(uint32_t, v8::Local<v8::Value>, const v8::AccessorInfo&);
END
@@ -2681,39 +2685,38 @@ END
return $code;
}
-sub GenerateImplementationIndexer
+sub GenerateImplementationIndexedProperty
{
my $interface = shift;
my $indexer = shift;
- my $code = "";
-
my $interfaceName = $interface->name;
my $v8InterfaceName = "V8$interfaceName";
# FIXME: Figure out what NumericIndexedGetter is really supposed to do. Right now, it's only set on WebGL-related files.
- my $hasCustomSetter = $interface->extendedAttributes->{"CustomIndexedSetter"} && !$interface->extendedAttributes->{"NumericIndexedGetter"};
- my $hasGetter = $interface->extendedAttributes->{"IndexedGetter"} || $interface->extendedAttributes->{"CustomGetOwnPropertySlot"};
+ my $hasCustomIndexedSetter = $interface->extendedAttributes->{"CustomIndexedSetter"};
+ my $hasIndexedGetter = $interface->extendedAttributes->{"IndexedGetter"} || $interface->extendedAttributes->{"CustomIndexedGetter"};
# FIXME: Investigate and remove this nastinesss. In V8, named property handling and indexer handling are apparently decoupled,
# which means that object[X] where X is a number doesn't reach named property indexer. So we need to provide
# simplistic, mirrored indexer handling in addition to named property handling.
my $isSpecialCase = exists $indexerSpecialCases{$interfaceName};
if ($isSpecialCase) {
- $hasGetter = 1;
+ $hasIndexedGetter = 1;
if ($interface->extendedAttributes->{"CustomNamedSetter"}) {
- $hasCustomSetter = 1;
+ $hasCustomIndexedSetter = 1;
}
}
+ # FIXME: Remove the special cases. Interfaces that have indexedPropertyGetter should have indexedPropertyEnumerator.
my $hasEnumerator = !$isSpecialCase && $codeGenerator->InheritsInterface($interface, "Node");
# FIXME: Find a way to not have to special-case HTMLOptionsCollection.
if ($interfaceName eq "HTMLOptionsCollection") {
$hasEnumerator = 1;
- $hasGetter = 1;
+ $hasIndexedGetter = 1;
}
- if (!$hasGetter) {
+ if (!$hasIndexedGetter) {
return "";
}
@@ -2725,32 +2728,8 @@ sub GenerateImplementationIndexer
my $indexerType = $indexer ? $indexer->type : 0;
- # FIXME: Remove this once toV8 helper methods are implemented (see https://bugs.webkit.org/show_bug.cgi?id=32563).
- if ($interfaceName eq "WebKitCSSKeyframesRule") {
- $indexerType = "WebKitCSSKeyframeRule";
- }
-
- if ($indexerType && !$hasCustomSetter) {
- if ($indexerType eq "DOMString") {
- my $conversion = $indexer->extendedAttributes->{"TreatReturnedNullStringAs"};
- if ($conversion && $conversion eq "Null") {
- $code .= <<END;
- setCollectionStringOrUndefinedIndexedGetter<${interfaceName}>(desc);
-END
- } else {
- $code .= <<END;
- setCollectionStringIndexedGetter<${interfaceName}>(desc);
-END
- }
- } else {
- $code .= <<END;
- setCollectionIndexedGetter<${interfaceName}, ${indexerType}>(desc);
-END
- # Include the header for this indexer type, because setCollectionIndexedGetter() requires toV8() for this type.
- AddToImplIncludes("V8${indexerType}.h");
- }
-
- return $code;
+ if ($indexerType && !$hasCustomIndexedSetter) {
+ $hasEnumerator = 1;
}
my $hasDeleter = $interface->extendedAttributes->{"CustomDeleteProperty"};
@@ -2764,13 +2743,53 @@ END
$setOn = "Prototype";
$hasDeleter = 0;
}
+ # FIXME: Implement V8DataTransferItemList::indexedPropertyDeleter
+ if ($interfaceName eq "DataTransferItemList") {
+ $hasDeleter = 0;
+ }
+ my $code = "";
$code .= " desc->${setOn}Template()->SetIndexedPropertyHandler(${v8InterfaceName}::indexedPropertyGetter";
- $code .= $hasCustomSetter ? ", ${v8InterfaceName}::indexedPropertySetter" : ", 0";
+ $code .= $hasCustomIndexedSetter ? ", ${v8InterfaceName}::indexedPropertySetter" : ", 0";
$code .= ", 0"; # IndexedPropertyQuery -- not being used at the moment.
$code .= $hasDeleter ? ", ${v8InterfaceName}::indexedPropertyDeleter" : ", 0";
$code .= ", nodeCollectionIndexedPropertyEnumerator<${interfaceName}>" if $hasEnumerator;
$code .= ");\n";
+
+ if($interface->extendedAttributes->{"IndexedGetter"}) {
+ # FIXME: add item() method to WebKitCSSKeyframesRule.idl or remove [IndexedGetter] from WebKitCSSKeyframesRule.idl
+ # Currently indexer type is hard coded because it can not be obtained from IDL.
+ if ($interfaceName eq "WebKitCSSKeyframesRule") {
+ $indexerType = "WebKitCSSKeyframeRule";
+ }
+ my $jsValue = "";
+ my $nativeType = GetNativeType($indexerType);
+ my $isNull = "";
+
+ if ($codeGenerator->IsRefPtrType($indexerType)) {
+ $isNull = "!element";
+ if ($interfaceName eq "WebKitCSSKeyframesRule") {
+ $jsValue = "toV8(element.release(), info.Holder(), info.GetIsolate())";
+ } else {
+ $jsValue = NativeToJSValue($indexer, "element.release()", "info.Holder()", "info.GetIsolate()");
+ }
+ } else {
+ $isNull = "element.isNull()";
+ $jsValue = NativeToJSValue($indexer, "element", "info.Holder()", "info.GetIsolate()");
+ }
+
+ AddToImplContent(<<END);
+v8::Handle<v8::Value> ${v8InterfaceName}::indexedPropertyGetter(uint32_t index, const v8::AccessorInfo& info)
+{
+ ASSERT(V8DOMWrapper::maybeDOMWrapper(info.Holder()));
+ ${interfaceName}* collection = toNative(info.Holder());
+ $nativeType element = collection->item(index);
+ if ($isNull)
+ return v8Undefined();
+ return $jsValue;
+}
+END
+ }
return $code;
}
@@ -3348,10 +3367,8 @@ END
$code .= "\n#endif // ${conditionalString}\n" if $conditionalString;
}
- $code .= GenerateImplementationIndexer($interface, $indexer);
-
- my $tmplConfig = GenerateImplementationNamedPropertyGetter($interface, $namedPropertyGetter);
- $code .= $tmplConfig;
+ $code .= GenerateImplementationIndexedProperty($interface, $indexer);
+ $code .= GenerateImplementationNamedPropertyGetter($interface, $namedPropertyGetter);
$code .= GenerateImplementationCustomCall($interface);
$code .= GenerateImplementationMasqueradesAsUndefined($interface);
« no previous file with comments | « LayoutTests/gamepad/gamepad-polling-access-expected.txt ('k') | Source/bindings/tests/results/V8TestEventTarget.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698