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

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

Issue 15899009: Support indexed setter generation (Closed) Base URL: https://chromium.googlesource.com/chromium/blink@master
Patch Set: Use TreatNullAs, TreatUndefinedAs in case of value is null/undefined Created 7 years, 7 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 1d74697f1387891dcfa95fecb9a92e8e558e76e1..fc8351dbbc8eb187be2866a3be31d4858c207032 100644
--- a/Source/bindings/scripts/CodeGeneratorV8.pm
+++ b/Source/bindings/scripts/CodeGeneratorV8.pm
@@ -3183,9 +3183,11 @@ sub GenerateImplementationIndexedPropertyAccessors
GenerateImplementationIndexedPropertyGetter($interface, $indexedGetterFunction);
}
- # FIXME: Support generated indexed setter bindings.
my $indexedSetterFunction = GetIndexedSetterFunction($interface);
my $hasCustomIndexedSetter = $indexedSetterFunction ? $indexedSetterFunction->signature->extendedAttributes->{"Custom"} : 0;
+ if ($indexedSetterFunction && !$hasCustomIndexedSetter) {
+ GenerateImplementationIndexedPropertySetter($interface, $indexedSetterFunction);
+ }
my $indexedDeleterFunction = GetIndexedDeleterFunction($interface);
my $hasCustomIndexedDeleter = $indexedDeleterFunction ? $indexedDeleterFunction->signature->extendedAttributes->{"Custom"} : 0;
@@ -3273,6 +3275,80 @@ sub GenerateImplementationIndexedPropertyGetter
$implementation{nameSpaceWebCore}->add($getterCode);
}
+sub GenerateImplementationIndexedPropertySetter
+{
+ my $interface = shift;
+ my $indexedSetterFunction = shift;
+ my $implClassName = GetImplName($interface);
+ my $v8ClassName = GetV8ClassName($interface);
+ my $methodName = GetImplName($indexedSetterFunction->signature);
+
+ AddToImplIncludes("bindings/v8/V8Collection.h");
+ my $type = $indexedSetterFunction->parameters->[1]->type;
+ my $returnType = $indexedSetterFunction->signature->type;
+ my $nativeType = GetNativeType($returnType);
+ my $nativeValue = JSValueToNative($type, $indexedSetterFunction->signature->extendedAttributes, "value", "info.GetIsolate()");
+ my $raisesExceptions = $indexedSetterFunction->signature->extendedAttributes->{"RaisesException"};
+ my $treatNullAs = $indexedSetterFunction->parameters->[1]->extendedAttributes->{"TreatNullAs"};
+ my $treatUndefinedAs = $indexedSetterFunction->parameters->[1]->extendedAttributes->{"TreatUndefinedAs"};
+ my $code = "v8::Handle<v8::Value> ${v8ClassName}::indexedPropertySetter(uint32_t index, v8::Local<v8::Value> value, const v8::AccessorInfo& info)\n";
+ $code .= "{\n";
+ $code .= " ${implClassName}* collection = toNative(info.Holder());\n";
+ my $extraArguments = "";
+ if ($raisesExceptions) {
+ $code .= " ExceptionCode ec = 0;\n";
+ $extraArguments = ", ec";
+ }
+ if ($type eq "DOMString") {
+ my $nullCheck = "";
+ if ($treatNullAs && $treatNullAs eq "NullString") {
+ $nullCheck = "WithNullCheck";
+ }
haraken 2013/05/29 06:41:56 You should add a $treatUndefinedAs case as well. H
+ $code .= " V8TRYCATCH_FOR_V8STRINGRESOURCE(V8StringResource<${nullCheck}>, propertyValue, value);\n";
+ } else {
+ $code .= " $nativeType propertyValue = $nativeValue;\n";
+ }
haraken 2013/05/29 06:41:56 I think we duplicate code of line 3302 - 3310 in C
+ my $passNativeValue = "propertyValue";
+ $passNativeValue .= ".release()" if (IsRefPtrType($type));
+
+ my @conditions = ();
+ my @statements = ();
+ if ($treatNullAs && $treatNullAs ne "NullString") {
+ push @conditions, "value->IsNull()";
+ push @statements, "result = collection->${treatNullAs}(index$extraArguments);";
+ }
+ if ($treatUndefinedAs && $treatUndefinedAs ne "NullString") {
+ push @conditions, "value->IsUndefined()";
+ push @statements, "result = collection->${treatUndefinedAs}(index$extraArguments);";
+ }
+ push @conditions, "";
+ push @statements, "result = collection->${methodName}(index, $passNativeValue$extraArguments);";
+ if (@conditions==1) {
haraken 2013/05/29 06:41:56 Nit: Spaces needed around '=='.
+ $code .= " bool " . $statements[0] . "\n";
+ } else {
+ $code .= " bool result;\n";
+ for my $i (0..@conditions-1) {
+ my $token = "else if";
+ $token = "if" if $i==0;
haraken 2013/05/29 06:41:56 Ditto.
+ $token = "else" if $i==@conditions-1;
haraken 2013/05/29 06:41:56 Ditto.
+ $code .= " ${token}";
+ $code .= " (" . $conditions[$i] . ")" if $conditions[$i];
+ $code .= "\n";
+ $code .= " " . $statements[$i] . "\n";
+ }
+ }
+
+ $code .= " if (!result)\n";
+ $code .= " return v8Undefined();\n";
+ if ($raisesExceptions) {
+ $code .= " if (ec)\n";
+ $code .= " return setDOMException(ec, info.GetIsolate());\n";
+ }
+ $code .= " return value;\n";
+ $code .= "}\n\n";
+ $implementation{nameSpaceWebCore}->add($code);
+}
+
sub GenerateImplementationNamedPropertyAccessors
{
my $interface = shift;
@@ -3431,6 +3507,8 @@ sub GenerateImplementationNamedPropertySetter
my $type = $namedSetterFunction->parameters->[1]->type;
my $nativeType = GetNativeType($type);
my $raisesExceptions = $namedSetterFunction->signature->extendedAttributes->{"RaisesException"};
+ my $treatNullAs = $namedSetterFunction->parameters->[1]->extendedAttributes->{"TreatNullAs"};
+ my $treatUndefinedAs = $namedSetterFunction->parameters->[1]->extendedAttributes->{"TreatUndefinedAs"};
my $nativeValue = JSValueToNative($type, $namedSetterFunction->signature->extendedAttributes, "value", "info.GetIsolate()");
my $code = "v8::Handle<v8::Value> ${v8ClassName}::namedPropertySetter(v8::Local<v8::String> name, v8::Local<v8::Value> value, const v8::AccessorInfo& info)\n";
@@ -3450,7 +3528,6 @@ sub GenerateImplementationNamedPropertySetter
}
if ($type eq "DOMString") {
my $nullCheck = "";
- my $treatNullAs = $namedSetterFunction->parameters->[1]->extendedAttributes->{"TreatNullAs"};
if ($treatNullAs && $treatNullAs eq "NullString") {
$nullCheck = "WithNullCheck";
}
@@ -3458,7 +3535,34 @@ sub GenerateImplementationNamedPropertySetter
} else {
$code .= " $nativeType propertyValue = $nativeValue;\n";
}
- $code .= " bool result = collection->${methodName}(propertyName, propertyValue$extraArguments);\n";
+
+ my @conditions = ();
+ my @statements = ();
+ if ($treatNullAs && $treatNullAs ne "NullString") {
+ push @conditions, "value->IsNull()";
+ push @statements, "result = collection->${treatNullAs}(propertyName$extraArguments);";
+ }
+ if ($treatUndefinedAs && $treatUndefinedAs ne "NullString") {
+ push @conditions, "value->IsUndefined()";
+ push @statements, "result = collection->${treatUndefinedAs}(propertyName$extraArguments);";
+ }
+ push @conditions, "";
+ push @statements, "result = collection->${methodName}(propertyName, propertyValue$extraArguments);";
+ if (@conditions==1) {
+ $code .= " bool " . $statements[0] . "\n";
+ } else {
+ $code .= " bool result;\n";
+ for my $i (0..@conditions-1) {
+ my $token = "else if";
+ $token = "if" if $i==0;
+ $token = "else" if $i==@conditions-1;
+ $code .= " ${token}";
+ $code .= " (" . $conditions[$i] . ")" if $conditions[$i];
+ $code .= "\n";
+ $code .= " " . $statements[$i] . "\n";
+ }
+ }
haraken 2013/05/29 06:41:56 We don't want to duplicate the code to build up if
+
$code .= " if (!result)\n";
$code .= " return v8Undefined();\n";
if ($raisesExceptions) {
« no previous file with comments | « no previous file | Source/bindings/scripts/IDLAttributes.txt » ('j') | Source/core/html/HTMLOptionsCollection.cpp » ('J')

Powered by Google App Engine
This is Rietveld 408576698