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

Unified Diff: Source/bindings/scripts/preprocess-idls.pl

Issue 14179013: Add support for [NoInterfaceObject] extended attribute to bindings generator (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: No longer parse IDL files to avoid slowing down build time 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/preprocess-idls.pl
diff --git a/Source/bindings/scripts/preprocess-idls.pl b/Source/bindings/scripts/preprocess-idls.pl
index 1f3190eb48f424d49bcf7fe643733c1a329e7b61..0821db0b9093fc2b5056a71a9bdc071c027fe39d 100644
--- a/Source/bindings/scripts/preprocess-idls.pl
+++ b/Source/bindings/scripts/preprocess-idls.pl
@@ -28,15 +28,18 @@ my $defines;
my $preprocessor;
my $idlFilesList;
my $supplementalDependencyFile;
+my $windowConstructorsSupplementalFile;
my $supplementalMakefileDeps;
GetOptions('defines=s' => \$defines,
'preprocessor=s' => \$preprocessor,
'idlFilesList=s' => \$idlFilesList,
'supplementalDependencyFile=s' => \$supplementalDependencyFile,
+ 'windowConstructorsSupplementalFile=s' => \$windowConstructorsSupplementalFile,
'supplementalMakefileDeps=s' => \$supplementalMakefileDeps);
die('Must specify an output file using --supplementalDependencyFile.') unless defined($supplementalDependencyFile);
+die('Must specify an output file using --windowConstructorsSupplementalFile.') unless defined($windowConstructorsSupplementalFile);
die('Must specify the file listing all IDLs using --idlFilesList.') unless defined($idlFilesList);
open FH, "< $idlFilesList" or die "Cannot open $idlFilesList\n";
@@ -49,18 +52,35 @@ my %interfaceNameToIdlFile;
my %idlFileToInterfaceName;
my %supplementalDependencies;
my %supplementals;
+my $constructorAttributesCode = "";
foreach my $idlFile (@idlFiles) {
my $fullPath = Cwd::realpath($idlFile);
- my $partialInterfaceName = getPartialInterfaceNameFromIDLFile($fullPath);
+ my $idlFileContents = getFileContents($fullPath);
+ my $partialInterfaceName = getPartialInterfaceNameFromIDL($idlFileContents);
if ($partialInterfaceName) {
$supplementalDependencies{$fullPath} = $partialInterfaceName;
+ next;
}
my $interfaceName = fileparse(basename($idlFile), ".idl");
+ unless (isCallbackInterfaceFromIDL($idlFileContents)) {
+ my $extendedAttributes = getInterfaceExtendedAttributesFromIDL($idlFileContents);
+ unless ($extendedAttributes->{"NoInterfaceObject"}) {
+ $constructorAttributesCode .= GenerateConstructorAttribute($interfaceName, $extendedAttributes);
+ }
+ }
$interfaceNameToIdlFile{$interfaceName} = $fullPath;
$idlFileToInterfaceName{$fullPath} = $interfaceName;
$supplementals{$fullPath} = [];
}
+# Generate DOMWindow Constructors partial interface.
+open PARTIAL_WINDOW_FH, "> $windowConstructorsSupplementalFile" or die "Cannot open $windowConstructorsSupplementalFile\n";
+print PARTIAL_WINDOW_FH "partial interface DOMWindow {\n";
+print PARTIAL_WINDOW_FH $constructorAttributesCode;
+print PARTIAL_WINDOW_FH "};\n";
+close PARTIAL_WINDOW_FH;
+$supplementalDependencies{$windowConstructorsSupplementalFile} = "DOMWindow";
haraken 2013/05/07 01:12:06 Clever!
+
# Resolves partial interfaces dependencies.
foreach my $idlFile (keys %supplementalDependencies) {
my $baseFile = $supplementalDependencies{$idlFile};
@@ -88,7 +108,6 @@ foreach my $idlFile (sort keys %supplementals) {
}
close FH;
-
if ($supplementalMakefileDeps) {
open MAKE_FH, "> $supplementalMakefileDeps" or die "Cannot open $supplementalMakefileDeps\n";
my @all_dependencies = [];
@@ -108,8 +127,39 @@ if ($supplementalMakefileDeps) {
close MAKE_FH;
}
+sub GenerateConstructorAttribute
+{
+ my $interfaceName = shift;
+ my $extendedAttributes = shift;
+
+ my $code = " ";
+ my @extendedAttributesList;
+ foreach my $attributeName (keys $extendedAttributes) {
+ next unless ($attributeName eq "Conditional" || $attributeName eq "EnabledAtRuntime" || $attributeName eq "EnabledPerContext");
+ my $extendedAttribute = $attributeName;
+ $extendedAttribute .= "=" . $extendedAttributes->{$attributeName} unless $extendedAttributes->{$attributeName} eq "VALUE_IS_MISSING";
+ push(@extendedAttributesList, $extendedAttribute);
+ }
+ $code .= "[" . join(', ', @extendedAttributesList) . "] " if @extendedAttributesList;
+
+ my $originalInterfaceName = $interfaceName;
+ $interfaceName = $extendedAttributes->{"InterfaceName"} if $extendedAttributes->{"InterfaceName"};
+ $interfaceName = $extendedAttributes->{"ConstructorPrefix"} . $interfaceName if $extendedAttributes->{"ConstructorPrefix"};
+ $code .= "attribute " . $originalInterfaceName . "Constructor $interfaceName;\n";
+
+ # In addition to the regular property, for every [NamedConstructor] extended attribute on an interface,
+ # a corresponding property MUST exist on the ECMAScript global object.
+ if ($extendedAttributes->{"NamedConstructor"}) {
+ my $constructorName = $extendedAttributes->{"NamedConstructor"};
+ $constructorName =~ s/\(.*//g; # Extract function name.
+ $code .= " ";
+ $code .= "[" . join(', ', @extendedAttributesList) . "] " if @extendedAttributesList;
+ $code .= "attribute " . $originalInterfaceName . "ConstructorConstructor $constructorName;\n";
+ }
+ return $code;
+}
-sub getPartialInterfaceNameFromIDLFile
+sub getFileContents
{
my $idlFile = shift;
@@ -117,8 +167,51 @@ sub getPartialInterfaceNameFromIDLFile
my @lines = <FILE>;
close FILE;
- my $fileContents = join('', @lines);
+ # Filter out preprocessor lines.
+ @lines = grep(!/^\s*#/, @lines);
+
+ return join('', @lines);
+}
+
+sub getPartialInterfaceNameFromIDL
+{
+ my $fileContents = shift;
+
if ($fileContents =~ /partial\s+interface\s+(\w+)/gs) {
return $1;
}
}
+
+sub isCallbackInterfaceFromIDL
+{
+ my $fileContents = shift;
+ return ($fileContents =~ /callback\s+interface\s+\w+/gs);
+}
+
+sub trim
+{
+ my $string = shift;
+ $string =~ s/^\s+|\s+$//g;
+ return $string;
+}
+
+sub getInterfaceExtendedAttributesFromIDL
+{
+ my $fileContents = shift;
+
+ my $extendedAttributes = {};
+
+ if ($fileContents =~ /\[(.*)\]\s+(interface|exception)\s+(\w+)/gs) {
+ my @parts = split(',', $1);
+ foreach my $part (@parts) {
+ my @keyValue = split('=', $part);
+ my $key = trim($keyValue[0]);
+ next unless length($key);
+ my $value = "VALUE_IS_MISSING";
+ $value = trim($keyValue[1]) if @keyValue > 1;
+ $extendedAttributes->{$key} = $value;
+ }
+ }
+
+ return $extendedAttributes;
+}

Powered by Google App Engine
This is Rietveld 408576698