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

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: Fix error with Perl < 5.14 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
« no previous file with comments | « Source/bindings/scripts/IDLParser.pm ('k') | Source/core/css/CSSFontFaceLoadEvent.idl » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: Source/bindings/scripts/preprocess-idls.pl
diff --git a/Source/bindings/scripts/preprocess-idls.pl b/Source/bindings/scripts/preprocess-idls.pl
index f4a81506fc791d86e8b90ed6c33e842e06b23e59..89f5699f6d552b41724ab6dd60124d5298619f98 100644
--- a/Source/bindings/scripts/preprocess-idls.pl
+++ b/Source/bindings/scripts/preprocess-idls.pl
@@ -28,13 +28,16 @@ my $defines;
my $preprocessor;
my $idlFilesList;
my $supplementalDependencyFile;
+my $windowConstructorsFile;
GetOptions('defines=s' => \$defines,
'preprocessor=s' => \$preprocessor,
'idlFilesList=s' => \$idlFilesList,
- 'supplementalDependencyFile=s' => \$supplementalDependencyFile);
+ 'supplementalDependencyFile=s' => \$supplementalDependencyFile,
+ 'windowConstructorsFile=s' => \$windowConstructorsFile);
die('Must specify an output file using --supplementalDependencyFile.') unless defined($supplementalDependencyFile);
+die('Must specify an output file using --windowConstructorsFile.') unless defined($windowConstructorsFile);
die('Must specify the file listing all IDLs using --idlFilesList.') unless defined($idlFilesList);
open FH, "< $idlFilesList" or die "Cannot open $idlFilesList\n";
@@ -47,18 +50,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, "> $windowConstructorsFile" or die "Cannot open $windowConstructorsFile\n";
+print PARTIAL_WINDOW_FH "partial interface DOMWindow {\n";
+print PARTIAL_WINDOW_FH $constructorAttributesCode;
+print PARTIAL_WINDOW_FH "};\n";
+close PARTIAL_WINDOW_FH;
+$supplementalDependencies{$windowConstructorsFile} = "DOMWindow";
+
# Resolves partial interfaces dependencies.
foreach my $idlFile (keys %supplementalDependencies) {
my $baseFile = $supplementalDependencies{$idlFile};
@@ -86,7 +106,38 @@ foreach my $idlFile (sort keys %supplementals) {
}
close FH;
-sub getPartialInterfaceNameFromIDLFile
+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"};
+ $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 getFileContents
{
my $idlFile = shift;
@@ -94,8 +145,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;
+}
« no previous file with comments | « Source/bindings/scripts/IDLParser.pm ('k') | Source/core/css/CSSFontFaceLoadEvent.idl » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698