diff --git a/sdk/lib/html/dart2js/html_dart2js.dart b/sdk/lib/html/dart2js/html_dart2js.dart index 089c189ca8d..8d0345519fd 100644 --- a/sdk/lib/html/dart2js/html_dart2js.dart +++ b/sdk/lib/html/dart2js/html_dart2js.dart @@ -10100,10 +10100,6 @@ class Document extends Node { @SupportedBrowser(SupportedBrowser.SAFARI) void _webkitExitFullscreen() native; - // From NonElementParentNode - - Element? getElementById(String elementId) native; - // From DocumentOrShadowRoot Element? get activeElement native; @@ -10126,6 +10122,10 @@ class Document extends Node { FontFaceSet? get fonts native; + // From NonElementParentNode + + Element? getElementById(String elementId) native; + // From ParentNode @JSName('childElementCount') diff --git a/tools/dom/new_scripts/code_generator_dart.py b/tools/dom/new_scripts/code_generator_dart.py index 2830e7f43b6..ad9fc3c0634 100644 --- a/tools/dom/new_scripts/code_generator_dart.py +++ b/tools/dom/new_scripts/code_generator_dart.py @@ -43,7 +43,7 @@ Design doc: http://www.chromium.org/developers/design-documents/idl-compiler """ import os -import cPickle as pickle +import pickle import re import sys diff --git a/tools/dom/new_scripts/dart_compiler.py b/tools/dom/new_scripts/dart_compiler.py index 5a1762939dc..7fe93797b8f 100755 --- a/tools/dom/new_scripts/dart_compiler.py +++ b/tools/dom/new_scripts/dart_compiler.py @@ -34,7 +34,7 @@ Design doc: http://www.chromium.org/developers/design-documents/idl-compiler import abc from optparse import OptionParser import os -import cPickle as pickle +import pickle from idl_reader import IdlReader from utilities import write_file diff --git a/tools/dom/scripts/css_code_generator.py b/tools/dom/scripts/css_code_generator.py index 717630b4547..3510eddaaaf 100644 --- a/tools/dom/scripts/css_code_generator.py +++ b/tools/dom/scripts/css_code_generator.py @@ -86,12 +86,11 @@ def GenerateCssTemplateFile(): # TODO(efortuna): do we also want CSSPropertyNames.in? data = [d.strip() for d in data if not isCommentLine(d) and not '=' in d] - browser_props = [readCssProperties(file) for file in BROWSER_PATHS] - universal_properties = reduce(lambda a, b: set(a).intersection(b), - browser_props) + browser_props = [set(readCssProperties(file)) for file in BROWSER_PATHS] + universal_properties = set.intersection(*browser_props) universal_properties = universal_properties.difference(['cssText']) universal_properties = universal_properties.intersection( - map(camelCaseName, data)) + list(map(camelCaseName, data))) class_file = open(TEMPLATE_FILE, 'w') diff --git a/tools/dom/scripts/dartgenerator.py b/tools/dom/scripts/dartgenerator.py index ceb213e5a0b..974cfc32be1 100755 --- a/tools/dom/scripts/dartgenerator.py +++ b/tools/dom/scripts/dartgenerator.py @@ -72,14 +72,12 @@ class DartGenerator(object): def LoadAuxiliary(self, auxiliary_dir): - def Visitor(_, dirname, names): + for (dirname, _, names) in os.walk(auxiliary_dir): for name in names: if name.endswith('.dart'): name = name[0:-5] # strip off ".dart" self._auxiliary_files[name] = os.path.join(dirname, name) - os.path.walk(auxiliary_dir, Visitor, None) - def FilterMembersWithUnidentifiedTypes(self, database): """Removes unidentified types. @@ -106,10 +104,13 @@ class DartGenerator(object): return False return True - interface.constants = filter(IsIdentified, interface.constants) - interface.attributes = filter(IsIdentified, interface.attributes) - interface.operations = filter(IsIdentified, interface.operations) - interface.parents = filter(IsIdentified, interface.parents) + interface.constants = list(filter(IsIdentified, + interface.constants)) + interface.attributes = list( + filter(IsIdentified, interface.attributes)) + interface.operations = list( + filter(IsIdentified, interface.operations)) + interface.parents = list(filter(IsIdentified, interface.parents)) def FilterInterfaces(self, database, diff --git a/tools/dom/scripts/dartmetadata.py b/tools/dom/scripts/dartmetadata.py index b997b60da6a..35e770c675e 100644 --- a/tools/dom/scripts/dartmetadata.py +++ b/tools/dom/scripts/dartmetadata.py @@ -12,7 +12,6 @@ import logging import monitored import os import re -from generator import ConstantOutputOrder from htmlrenamer import renamed_html_members, html_interface_renames _logger = logging.getLogger('dartmetadata') @@ -714,7 +713,7 @@ class DartMetadata(object): if _monitor_type_metadata: monitored_interfaces = {} - for interface_id, interface_data in self._types.items(): + for interface_id, interface_data in list(self._types.items()): monitored_interface = interface_data.copy() monitored_interface['members'] = monitored.Dict( 'dartmetadata.%s' % interface_id, interface_data['members']) diff --git a/tools/dom/scripts/database.py b/tools/dom/scripts/database.py index 75d8d2ed061..2ff5dc26961 100755 --- a/tools/dom/scripts/database.py +++ b/tools/dom/scripts/database.py @@ -149,7 +149,7 @@ class Database(object): def Save(self): """Saves all in-memory interfaces into files.""" - for interface in self._all_interfaces.values(): + for interface in list(self._all_interfaces.values()): self._SaveInterfaceFile(interface) for interface_name in self._interfaces_to_delete: self._DeleteInterfaceFile(interface_name) diff --git a/tools/dom/scripts/database_test.py b/tools/dom/scripts/database_test.py index a82ed24d9ef..e75ec9b3201 100755 --- a/tools/dom/scripts/database_test.py +++ b/tools/dom/scripts/database_test.py @@ -51,7 +51,7 @@ class DatabaseTestCase(unittest.TestCase): def testListInterfaces(self): db = database.Database(self._database_dir) db.Load() - self.assertEquals(self._ListInterfaces(db), ['I1']) + self.assertEqual(self._ListInterfaces(db), ['I1']) def testHasInterface(self): db = database.Database(self._database_dir) @@ -67,7 +67,7 @@ class DatabaseTestCase(unittest.TestCase): db.Save() self.assertTrue( os.path.exists(os.path.join(self._database_dir, 'I2.idl'))) - self.assertEquals(self._ListInterfaces(db), ['I1', 'I2']) + self.assertEqual(self._ListInterfaces(db), ['I1', 'I2']) def testDeleteInterface(self): db = database.Database(self._database_dir) @@ -76,13 +76,13 @@ class DatabaseTestCase(unittest.TestCase): db.Save() self.assertFalse( os.path.exists(os.path.join(self._database_dir, 'I1.idl'))) - self.assertEquals(self._ListInterfaces(db), []) + self.assertEqual(self._ListInterfaces(db), []) def testGetInterface(self): db = database.Database(self._database_dir) db.Load() interface = db.GetInterface('I1') - self.assertEquals(interface.id, 'I1') + self.assertEqual(interface.id, 'I1') if __name__ == '__main__': diff --git a/tools/dom/scripts/databasebuilder.py b/tools/dom/scripts/databasebuilder.py index c5327a78afe..c6180843ae8 100755 --- a/tools/dom/scripts/databasebuilder.py +++ b/tools/dom/scripts/databasebuilder.py @@ -236,9 +236,9 @@ class DatabaseBuilder(object): ext_attrs_node[ type_valued_attribute_name] = strip_modules(value) - map(rename_node, idl_file.all(IDLInterface)) - map(rename_node, idl_file.all(IDLType)) - map(rename_ext_attrs, idl_file.all(IDLExtAttrs)) + list(map(rename_node, idl_file.all(IDLInterface))) + list(map(rename_node, idl_file.all(IDLType))) + list(map(rename_ext_attrs, idl_file.all(IDLExtAttrs))) def _annotate(self, interface, import_options): """Adds @ annotations based on the source and source_attributes @@ -259,10 +259,10 @@ class DatabaseBuilder(object): add_source_annotation(interface) - map(add_source_annotation, interface.parents) - map(add_source_annotation, interface.constants) - map(add_source_annotation, interface.attributes) - map(add_source_annotation, interface.operations) + list(map(add_source_annotation, interface.parents)) + list(map(add_source_annotation, interface.constants)) + list(map(add_source_annotation, interface.attributes)) + list(map(add_source_annotation, interface.operations)) def _sign(self, node): """Computes a unique signature for the node, for merging purposed, by @@ -480,7 +480,8 @@ class DatabaseBuilder(object): def has_annotations(idl_node): return len(idl_node.annotations) - old_interface.__dict__[what] = filter(has_annotations, old_list) + old_interface.__dict__[what] = \ + list(filter(has_annotations, old_list)) return changed @@ -619,7 +620,7 @@ class DatabaseBuilder(object): def _process_ast(self, filename, ast): if len(ast) == 1: - ast = ast.values()[0] + ast = next(iter(ast.values())) else: print('ERROR: Processing AST: ' + os.path.basename(file_name)) new_asts[filename] = ast @@ -664,8 +665,8 @@ class DatabaseBuilder(object): (interface.id, import_options.source, os.path.basename(idl_file.filename))) - interface.attributes = filter(enabled, interface.attributes) - interface.operations = filter(enabled, interface.operations) + interface.attributes = list(filter(enabled, interface.attributes)) + interface.operations = list(filter(enabled, interface.operations)) self._imported_interfaces.append((interface, import_options)) # If an IDL dictionary then there is no implementsStatements. @@ -769,15 +770,15 @@ class DatabaseBuilder(object): if (source in idl_node.annotations and idl_node.annotations[source]): annotation = idl_node.annotations[source] - for name, value in annotation.items(): + for name, value in list(annotation.items()): if (name in top_level_annotation and value == top_level_annotation[name]): del annotation[name] - map(normalize, interface.parents) - map(normalize, interface.constants) - map(normalize, interface.attributes) - map(normalize, interface.operations) + list(map(normalize, interface.parents)) + list(map(normalize, interface.constants)) + list(map(normalize, interface.attributes)) + list(map(normalize, interface.operations)) def map_dictionaries(self): """Changes the type of operations/constructors arguments from an IDL @@ -790,12 +791,12 @@ class DatabaseBuilder(object): type_node.id = 'Dictionary' def all_types(node): - map(dictionary_to_map, node.all(IDLType)) + list(map(dictionary_to_map, node.all(IDLType))) for interface in self._database.GetInterfaces(): - map(all_types, interface.all(IDLExtAttrFunctionValue)) - map(all_types, interface.attributes) - map(all_types, interface.operations) + list(map(all_types, interface.all(IDLExtAttrFunctionValue))) + list(map(all_types, interface.attributes)) + list(map(all_types, interface.operations)) def fetch_constructor_data(self, options): window_interface = self._database.GetInterface('Window') @@ -1023,7 +1024,7 @@ Examination Complete self._no_interfaces_used_types = [] constructor_function = self._no_interface_constructor_types - map(constructor_function, interface.all(IDLExtAttrFunctionValue)) + list(map(constructor_function, interface.all(IDLExtAttrFunctionValue))) self._mark_usage(interface, check_dictionaries=check_dictionaries) @@ -1040,7 +1041,7 @@ Examination Complete self._no_interfaces_used_types = [] used = self._no_interface_used - map(used, operation_attribute.all(IDLType)) + list(map(used, operation_attribute.all(IDLType))) self._remember_usage( operation_attribute, check_dictionaries=check_dictionaries) @@ -1053,14 +1054,14 @@ Examination Complete # (IDLExtAttrFunctionValue) that have a dictionary reference. def _dictionary_constructor_types(self, node): self._dictionaries_used_types = [] - map(self._dictionary_used, node.all(IDLType)) + list(map(self._dictionary_used, node.all(IDLType))) self._remember_usage(node) # Iterator function for map to iterate over all constructor types # (IDLExtAttrFunctionValue) that reference an interface with NoInterfaceObject. def _no_interface_constructor_types(self, node): self._no_interfaces_used_types = [] - map(self._no_interface_used, node.all(IDLType)) + list(map(self._no_interface_used, node.all(IDLType))) self._remember_usage(node, check_dictionaries=False) # Maximum width of each column. diff --git a/tools/dom/scripts/databasebuilder_test.py b/tools/dom/scripts/databasebuilder_test.py index 7467b3edee7..840e6dd4c6c 100755 --- a/tools/dom/scripts/databasebuilder_test.py +++ b/tools/dom/scripts/databasebuilder_test.py @@ -30,7 +30,8 @@ class DatabaseBuilderTestCase(unittest.TestCase): def _assert_content_equals(self, path, expected_content): def clean(content): - return ' '.join(filter(len, map(str.strip, content.split('\n')))) + return ' '.join( + filter(len, list(map(str.strip, content.split('\n'))))) file_path = os.path.join(self._database_dir, path) self.assertTrue(os.path.exists(file_path)) diff --git a/tools/dom/scripts/emitter_test.py b/tools/dom/scripts/emitter_test.py index eb50c2a42cf..1c1021bdc22 100755 --- a/tools/dom/scripts/emitter_test.py +++ b/tools/dom/scripts/emitter_test.py @@ -18,7 +18,7 @@ class EmitterTestCase(unittest.TestCase): pass def check(self, e, expected): - self.assertEquals(''.join(e.Fragments()), expected) + self.assertEqual(''.join(e.Fragments()), expected) def testExample(self): e = emitter.Emitter() @@ -34,7 +34,7 @@ class EmitterTestCase(unittest.TestCase): try: e = emitter.Emitter() b = e.Emit('$(A)$(!B)$(A)$(!B)') # $(!B) is duplicated - except RuntimeError, ex: + except RuntimeError as ex: return raise AssertionError('Expected error') @@ -46,7 +46,7 @@ class EmitterTestCase(unittest.TestCase): def testTemplate2(self): e = emitter.Emitter() r = e.Emit('1$(A)2$(B)3$(A)4$(B)5', A='x', B='y') - self.assertEquals(None, r) + self.assertEqual(None, r) self.check(e, '1x2y3x4y5') def testTemplate3(self): @@ -128,12 +128,12 @@ class EmitterTestCase(unittest.TestCase): e = emitter.Emitter() e.Emit('$#A(-)', A='Invalid') e.Fragments() - except RuntimeError, ex: + except RuntimeError as ex: return raise AssertionError('Expected error') def testFormat(self): - self.assertEquals(emitter.Format('$A$B', A=1, B=2), '12') + self.assertEqual(emitter.Format('$A$B', A=1, B=2), '12') if __name__ == '__main__': diff --git a/tools/dom/scripts/fremontcutbuilder.py b/tools/dom/scripts/fremontcutbuilder.py index bd5fcad6ec2..d00700793ca 100755 --- a/tools/dom/scripts/fremontcutbuilder.py +++ b/tools/dom/scripts/fremontcutbuilder.py @@ -58,10 +58,10 @@ def ResolveAllTypedefs(all_interfaces): continue return True - interface.constants = filter(IsIdentified, interface.constants) - interface.attributes = filter(IsIdentified, interface.attributes) - interface.operations = filter(IsIdentified, interface.operations) - interface.parents = filter(IsIdentified, interface.parents) + interface.constants = list(filter(IsIdentified, interface.constants)) + interface.attributes = list(filter(IsIdentified, interface.attributes)) + interface.operations = list(filter(IsIdentified, interface.operations)) + interface.parents = list(filter(IsIdentified, interface.parents)) def build_database(idl_files, @@ -193,16 +193,15 @@ def main(parallel=False, logging_level=logging.WARNING, examine_idls=False): 'WebKitGamepadList.idl', # GamepadList is the new one. ] - def visitor(arg, dir_name, names): + for (dir_name, dirs, files) in os.walk(webcore_dir): if os.path.basename(dir_name) in DIRS_TO_IGNORE: - names[:] = [] # Do not go underneath - for name in names: - file_name = os.path.join(dir_name, name) - (interface, ext) = os.path.splitext(file_name) - if ext == '.idl' and not (name in FILES_TO_IGNORE): - idl_files.append(file_name) - - os.path.walk(webcore_dir, visitor, webcore_dir) + dirs[:] = [] # Do not go underneath + else: + for name in files: + file_name = os.path.join(dir_name, name) + (interface, ext) = os.path.splitext(file_name) + if ext == '.idl' and not (name in FILES_TO_IGNORE): + idl_files.append(file_name) database_dir = os.path.join(current_dir, '..', 'database') diff --git a/tools/dom/scripts/generate_blink_file.py b/tools/dom/scripts/generate_blink_file.py index 4e9c2a4629f..48a46126c5d 100644 --- a/tools/dom/scripts/generate_blink_file.py +++ b/tools/dom/scripts/generate_blink_file.py @@ -6,14 +6,13 @@ """Generates sdk/lib/_blink/dartium/_blink_dartium.dart file.""" import os -from sets import Set -from generator import AnalyzeOperation, AnalyzeConstructor +from generator import AnalyzeOperation, AnalyzeConstructor, ConstantOutputOrder # This is list of all methods with native c++ implementations # If performing a dartium merge, the best practice is to comment out this list, # ensure everything runs, and then uncomment this list which might possibly # introduce breaking changes due to changes to these method signatures. -_js_custom_members = Set([ +_js_custom_members = set([ 'Document.createElement', 'Element.id', 'Element.tagName', @@ -79,7 +78,7 @@ _js_custom_members = Set([ # Uncomment out this line to short circuited native methods and run all of # dart:html through JS interop except for createElement which is slightly more # tightly natively wired. -# _js_custom_members = Set([]) +# _js_custom_members = set() # Expose built-in methods support by an instance that is not shown in the IDL. _additional_methods = { @@ -385,12 +384,6 @@ CLASS_DEFINITION_END = """} """ - -def ConstantOutputOrder(a, b): - """Canonical output ordering for constants.""" - return (a.id > b.id) - (a.id < b.id) - - def generate_parameter_entries(param_infos): optional_default_args = 0 for argument in param_infos: @@ -524,7 +517,7 @@ def _Emit_Blink_Constructors(blink_file, analyzed_constructors): def _Process_Attributes(blink_file, interface, attributes): # Emit an interface's attributes and operations. - for attribute in sorted(attributes, ConstantOutputOrder): + for attribute in sorted(attributes, key=ConstantOutputOrder): name = attribute.id is_native = _Is_Native(interface.id, name) if attribute.is_read_only: @@ -552,7 +545,7 @@ def _Process_Operations(blink_file, primary_interface=False): analyzeOperations = [] - for operation in sorted(operations, ConstantOutputOrder): + for operation in sorted(operations, key=ConstantOutputOrder): if len(analyzeOperations) == 0: analyzeOperations.append(operation) else: diff --git a/tools/dom/scripts/generator.py b/tools/dom/scripts/generator.py index d8ad435af25..bcc36f365fd 100644 --- a/tools/dom/scripts/generator.py +++ b/tools/dom/scripts/generator.py @@ -10,6 +10,8 @@ import json import monitored import os import re +from functools import cmp_to_key +from itertools import zip_longest from htmlrenamer import custom_html_constructors, html_interface_renames, \ typed_array_renames @@ -216,7 +218,7 @@ _suppressed_native_constructors = monitored.Set( ]) _custom_types = monitored.Set('generator._custom_types', - typed_array_renames.keys()) + list(typed_array_renames.keys())) def IsCustomType(interface_name): @@ -399,6 +401,19 @@ def MatchSourceFilter(thing): return 'WebKit' in thing.annotations or 'Dart' in thing.annotations +# Legacy Python 2 way to sort lists. Group by type, and then sort by value. +class MultitypeSortKey: + + def __init__(self, value): + self.value = value + + def __lt__(self, other): + try: + return self.value < other.value + except TypeError: + return str(type(self)) < str(type(other)) + + class ParamInfo(object): """Holder for various information about a parameter of a Dart operation. @@ -497,7 +512,8 @@ def _BuildArguments(args, interface, constructor=False): # Given a list of overloaded default values, choose a suitable one. def OverloadedDefault(args): - defaults = sorted(set(arg.default_value for arg in args)) + defaults = sorted(set(arg.default_value for arg in args), + key=MultitypeSortKey) if len(set(DartType(arg.type.id) for arg in args)) == 1: null_default = False for arg in args: @@ -509,14 +525,12 @@ def _BuildArguments(args, interface, constructor=False): result = [] is_optional = False - # Process overloaded arguments across a set of overloaded operations. # Each tuple in args corresponds to overloaded arguments with the same name. - for arg_tuple in map(lambda *x: x, *args): + for arg_tuple in list(zip_longest(*args)): is_optional = is_optional or any( arg is None or IsOptional(arg) for arg in arg_tuple) - - filtered = filter(None, arg_tuple) + filtered = list(filter(None, arg_tuple)) (type_id, is_nullable) = OverloadedType(filtered) name = OverloadedName(filtered) (default_value, default_value_is_null) = OverloadedDefault(filtered) @@ -608,9 +622,9 @@ def ConvertToFuture(info): return 'Callback' not in type_id # Success callback is the first argument (change if this no longer holds). - new_info.callback_args = filter(lambda x: not IsNotCallbackType(x), - new_info.param_infos) - new_info.param_infos = filter(IsNotCallbackType, new_info.param_infos) + new_info.callback_args = list( + filter(lambda x: not IsNotCallbackType(x), new_info.param_infos)) + new_info.param_infos = list(filter(IsNotCallbackType, new_info.param_infos)) new_info.type_name = 'Future' return new_info @@ -745,9 +759,10 @@ class OperationInfo(object): # TODO(terry): This may have to change for dart2js for code shaking the # return types (unions) needs to be emitted with @create # annotations and/or with JS('type1|type2',...) - if hasattr(rename_type, - 'im_self') and rename_type.im_self._database.HasTypeDef( - param.type_id): + if hasattr( + rename_type, + '__self__') and rename_type.__self__._database.HasTypeDef( + param.type_id): dart_type = 'dynamic' else: dart_type = rename_type( @@ -783,7 +798,7 @@ class OperationInfo(object): def FormatParam(dec): return dec[0] + dec[1] - argtexts = map(FormatParam, required) + argtexts = list(map(FormatParam, required)) if optional: left_bracket, right_bracket = '{}' if needs_named else '[]' argtexts.append(left_bracket + @@ -799,7 +814,7 @@ class OperationInfo(object): """ Returns a number of required arguments in Dart declaration of the operation. """ - return len(filter(lambda i: not i.is_optional, self.param_infos)) + return len(list(filter(lambda i: not i.is_optional, self.param_infos))) def ParametersAsArgumentList(self, parameter_count=None, @@ -939,11 +954,14 @@ class OperationInfo(object): return rename_type(self.type_name) -def ConstantOutputOrder(a, b): +def _ConstantOutputOrder(a, b): """Canonical output ordering for constants.""" return (a.id > b.id) - (a.id < b.id) +ConstantOutputOrder = cmp_to_key(_ConstantOutputOrder) + + def _FormatNameList(names): """Returns JavaScript array literal expression with one name per line.""" #names = sorted(names) diff --git a/tools/dom/scripts/go.sh b/tools/dom/scripts/go.sh index 71789cf0002..4cd50f89a9c 100755 --- a/tools/dom/scripts/go.sh +++ b/tools/dom/scripts/go.sh @@ -38,4 +38,4 @@ fi # third_party IDL scripts are not compatible with python3, so use python2.7. reset && \ -python2.7 ./dartdomgenerator.py --systems="$SYSTEMS" --logging=40 --update-dom-metadata --gen-interop "$ARG_OPTION" +python3 ./dartdomgenerator.py --systems="$SYSTEMS" --logging=40 --update-dom-metadata --gen-interop "$ARG_OPTION" diff --git a/tools/dom/scripts/htmldartgenerator.py b/tools/dom/scripts/htmldartgenerator.py index 22890c9c497..15cc0f9357b 100644 --- a/tools/dom/scripts/htmldartgenerator.py +++ b/tools/dom/scripts/htmldartgenerator.py @@ -37,7 +37,6 @@ _custom_factories = [ 'EventSource', ] - class HtmlDartGenerator(object): def __init__(self, interface, options, dart_use_blink, logger): @@ -82,10 +81,10 @@ class HtmlDartGenerator(object): # one synthesized class (WebGL). self._gl_constants.extend(interface.constants) else: - for const in sorted(interface.constants, ConstantOutputOrder): + for const in sorted(interface.constants, key=ConstantOutputOrder): self.AddConstant(const) - for attr in sorted(interface.attributes, ConstantOutputOrder): + for attr in sorted(interface.attributes, key=ConstantOutputOrder): if attr.type.id != 'EventHandler' and attr.type.id != 'EventListener': self.AddAttribute(attr, declare_only) @@ -132,12 +131,13 @@ class HtmlDartGenerator(object): _logger.warn('Interface %s has duplicate parent interfaces %s - ' \ 'ignoring duplicates. Please file a bug with the dart:html team.' % (interface.id, parent_list)) - for parent_interface in sorted(secondary_parents): + for parent_interface in sorted(secondary_parents, + key=ConstantOutputOrder): if isinstance(parent_interface, str): continue for attr in sorted(parent_interface.attributes, - ConstantOutputOrder): + key=ConstantOutputOrder): if not FindMatchingAttribute(interface, attr): if attr.type.id != 'EventHandler': self.SecondaryContext(parent_interface) @@ -172,7 +172,6 @@ class HtmlDartGenerator(object): # are pure interfaces (mixins to this interface). if (IsPureInterface(parent_name, self._database)): return - for operation in parent.operations: if operation.id in operationsByName: operations = operationsByName[operation.id] @@ -242,8 +241,10 @@ class HtmlDartGenerator(object): if (operation.id in operations_by_name and len(operations_by_name[operation.id]) > 1 and len( - filter(lambda overload: overload.startswith(operation_str), - renamed_overloads.keys())) == 0 and + list( + filter( + lambda overload: overload.startswith(operation_str), + renamed_overloads.keys()))) == 0 and operation_str not in keep_overloaded_members and operation_str not in overloaded_and_renamed and operation_str not in renamed_html_members and diff --git a/tools/dom/scripts/idlnode.py b/tools/dom/scripts/idlnode.py index 40e86e5ab12..8be47969c49 100644 --- a/tools/dom/scripts/idlnode.py +++ b/tools/dom/scripts/idlnode.py @@ -7,6 +7,7 @@ import os import sys import idl_definitions +from generator import MultitypeSortKey from idl_types import IdlType, IdlNullableType, IdlUnionType, IdlArrayOrSequenceType import dependency @@ -88,12 +89,18 @@ class IDLNode(object): """Returns string of extra info for __repr__().""" return '' - def __cmp__(self, other): - """Override default compare operation. + def __eq__(self, other): + """Override default equals operation. IDLNodes are equal if all their properties are equal.""" if other is None or not isinstance(other, IDLNode): return 1 - return self.__dict__.__cmp__(other.__dict__) + return self.__dict__.__eq__(other.__dict__) + + def __hash__(self): + """Define default hashing behavior. + In order to comply with a == b => hash(a) == hash(b), we recursively iterate + self.__dict__ and convert all objects to hashable objects.""" + return self.to_hash() def reset_id(self, newId): """Reset the id of the Node. This is typically done during a normalization @@ -152,7 +159,36 @@ class IDLNode(object): res[k] = v return res - def _find_all(self, ast, label, max_results=sys.maxint): + def to_hash(self): + return hash(self._to_hashable(self)) + + def _to_hashable(self, obj): + # By default, lists and dicts are not hashable, and user-defined objects + # are unordered. In order to make a consistent hash for a given object, + # this converts unhashable types and sorts properties. + if isinstance(obj, list): + # Convert lists to tuples. + new_obj = [] + for item in obj: + new_obj.append(self._to_hashable(item)) + return tuple(new_obj) + elif isinstance(obj, dict): + # Convert dicts to frozensets of tuples. + new_obj = set() + # Sort to ensure fixed order. + for (k2, v2) in sorted(obj.items(), key=MultitypeSortKey): + new_obj.add((self._to_hashable(k2), self._to_hashable(v2))) + return frozenset(new_obj) + elif hasattr(obj, '__dict__'): + items = [] + # Sort properties to ensure fixed order. + for (k, v) in sorted(obj.__dict__.items(), key=MultitypeSortKey): + items.append((k, self._to_hashable(v))) + return tuple(items) + else: + return obj + + def _find_all(self, ast, label, max_results=sys.maxsize): """Searches the AST for tuples with a given label. The PegParser output is composed of lists and tuples, where the tuple 1st argument is a label. If ast root is a list, will search recursively inside each @@ -452,9 +488,9 @@ class IDLFile(IDLNode): interface_info = dependency.get_interfaces_info()[interface. id] - implements = interface_info[ - 'implements_interfaces'] if interface_info.has_key( - 'implements_interfaces') else [] + implements = [] + if 'implements_interfaces' in interface_info: + implements = interface_info['implements_interfaces'] if not (blink_interface.is_partial) and len(implements) > 0: implementor = new_asts[interface.id].interfaces.get( interface.id) diff --git a/tools/dom/scripts/idlnode_test.py b/tools/dom/scripts/idlnode_test.py index 61de65a46ec..5ce9037a396 100755 --- a/tools/dom/scripts/idlnode_test.py +++ b/tools/dom/scripts/idlnode_test.py @@ -37,7 +37,7 @@ class IDLNodeTestCase(unittest.TestCase): ast = parser.parse(content) node = idlnode.IDLFile(ast) actual = node.to_dict() if node else None - except SyntaxError, e: + except SyntaxError as e: error = e pass if actual == expected: diff --git a/tools/dom/scripts/mdnreader.py b/tools/dom/scripts/mdnreader.py index b142b7af735..50fc227ae29 100644 --- a/tools/dom/scripts/mdnreader.py +++ b/tools/dom/scripts/mdnreader.py @@ -46,13 +46,13 @@ def _get_browser_compat_data(): if 'api' in json_dict: # Get the interface name api_dict = json_dict['api'] - interface_name = api_dict.keys()[0] + interface_name = next(iter(api_dict)) return (interface_name, api_dict[interface_name]) elif 'html' in json_dict: html_dict = json_dict['html'] if 'elements' in html_dict: elements_dict = html_dict['elements'] - element_name = elements_dict.keys()[0] + element_name = next(iter(elements_dict)) # Convert to WebCore name interface = str('HTML' + element_name + 'Element') return (interface, elements_dict[element_name]) @@ -60,49 +60,12 @@ def _get_browser_compat_data(): svg_dict = json_dict['svg'] if 'elements' in svg_dict: elements_dict = svg_dict['elements'] - element_name = elements_dict.keys()[0] + element_name = next(iter(elements_dict)) # Convert to WebCore name interface = str('SVG' + element_name + 'Element') return (interface, elements_dict[element_name]) return (None, None) - def visitor(arg, dir_path, names): - - def should_process_dir(dir_path): - if os.path.abspath(dir_path) == browser_compat_folder: - return True - for dir in INCLUDE_DIRS: - if dir_path.startswith(dir): - return True - return False - - if should_process_dir(dir_path): - for name in names: - file_name = os.path.join(dir_path, name) - (interface_path, ext) = os.path.splitext(file_name) - if ext == '.json': - with open(file_name) as src: - json_dict = json.load(src) - interface, metadata = process_json_dict(json_dict) - if not interface is None: - # Note: interface and member names do not - # necessarily have the same capitalization as - # WebCore, so we keep them all lowercase for easier - # matching later. - interface = interface.lower() - metadata = { - member.lower(): info - for member, info in metadata.items() - } - - if interface in browser_compat_data: - _unify_metadata(browser_compat_data[interface], - metadata) - else: - browser_compat_data[interface] = metadata - else: - names[:] = [] # Do not go underneath - # Attempts to unify two compatibility infos by taking the union of both, and # for conflicting information, taking the "stricter" of the two versions. # Updates `a` in place to represent the union of `a` and `b`. @@ -182,7 +145,42 @@ def _get_browser_compat_data(): if not attr in a: a[attr] = b[attr] - os.path.walk(browser_compat_folder, visitor, browser_compat_folder) + for (dir_path, dirs, files) in os.walk(browser_compat_folder): + + def should_process_dir(dir_path): + if os.path.abspath(dir_path) == browser_compat_folder: + return True + for dir in INCLUDE_DIRS: + if dir_path.startswith(dir): + return True + return False + + if should_process_dir(dir_path): + for name in files: + file_name = os.path.join(dir_path, name) + (interface_path, ext) = os.path.splitext(file_name) + if ext == '.json': + with open(file_name) as src: + json_dict = json.load(src) + interface, metadata = process_json_dict(json_dict) + if not interface is None: + # Note: interface and member names do not + # necessarily have the same capitalization as + # WebCore, so we keep them all lowercase for easier + # matching later. + interface = interface.lower() + metadata = { + member.lower(): info + for member, info in metadata.items() + } + + if interface in browser_compat_data: + _unify_metadata(browser_compat_data[interface], + metadata) + else: + browser_compat_data[interface] = metadata + else: + dirs[:] = [] # Do not go underneath return browser_compat_data @@ -192,8 +190,8 @@ def _unify_versions(version_a, version_b): # Given two valid version strings, compares parts of the version string # iteratively. def _greater_version(version_a, version_b): - version_a_split = map(int, version_a.split('.')) - version_b_split = map(int, version_b.split('.')) + version_a_split = list(map(int, version_a.split('.'))) + version_b_split = list(map(int, version_b.split('.'))) for i in range(min(len(version_a_split), len(version_b_split))): if version_a_split[i] > version_b_split[i]: return version_a @@ -208,7 +206,7 @@ def _unify_versions(version_a, version_b): return False if version is True: return True - if isinstance(version, str) or isinstance(version, unicode): + if isinstance(version, str): pattern = re.compile('^([0-9]+\.)*[0-9]+$') if not pattern.match(version): # It's possible for version strings to look like '<35'. We don't diff --git a/tools/dom/scripts/multiemitter_test.py b/tools/dom/scripts/multiemitter_test.py index 17c360d5001..b1ae27c805e 100644 --- a/tools/dom/scripts/multiemitter_test.py +++ b/tools/dom/scripts/multiemitter_test.py @@ -29,7 +29,7 @@ class MultiEmitterTestCase(unittest.TestCase): files.append((file, ''.join(contents))) m.Flush(_Collect) - self.assertEquals(expected, files) + self.assertEqual(expected, files) def testExample(self): m = multiemitter.MultiEmitter() diff --git a/tools/dom/scripts/systemhtml.py b/tools/dom/scripts/systemhtml.py index 0ec6d7d71db..9fa35dcaf29 100644 --- a/tools/dom/scripts/systemhtml.py +++ b/tools/dom/scripts/systemhtml.py @@ -184,14 +184,14 @@ class ElementConstructorInfo(object): info.js_name = None info.type_name = interface_name # optional parameters are always nullable - info.param_infos = map( - lambda tXn: ParamInfo( - name=tXn[1], - type_id=tXn[0], - is_optional=True, - is_nullable=True, - default_value=None, - default_value_is_null=False), self.opt_params) + info.param_infos = [ + ParamInfo(name=tXn[1], + type_id=tXn[0], + is_optional=True, + is_nullable=True, + default_value=None, + default_value_is_null=False) for tXn in self.opt_params + ] info.requires_named_arguments = True info.factory_parameters = ['"%s"' % self.tag] info.pure_dart_constructor = True @@ -514,67 +514,69 @@ _js_support_checks_additional_element = [ 'SVGSetElement', ] -js_support_checks = dict({ - 'Animation': - "JS('bool', '!!(document.body.animate)')", - 'AudioContext': - "JS('bool', '!!(window.AudioContext ||" - " window.webkitAudioContext)')", - 'Crypto': - "JS('bool', '!!(window.crypto && window.crypto.getRandomValues)')", - 'Database': - "JS('bool', '!!(window.openDatabase)')", - 'DOMPoint': - "JS('bool', '!!(window.DOMPoint) || !!(window.WebKitPoint)')", - 'ApplicationCache': - "JS('bool', '!!(window.applicationCache)')", - 'DOMFileSystem': - "JS('bool', '!!(window.webkitRequestFileSystem)')", - 'FormData': - "JS('bool', '!!(window.FormData)')", - 'HashChangeEvent': - "Device.isEventTypeSupported('HashChangeEvent')", - 'HTMLShadowElement': - ElemSupportStr('shadow'), - 'HTMLTemplateElement': - ElemSupportStr('template'), - 'MediaStreamEvent': - "Device.isEventTypeSupported('MediaStreamEvent')", - 'MediaStreamTrackEvent': - "Device.isEventTypeSupported('MediaStreamTrackEvent')", - 'MediaSource': - "JS('bool', '!!(window.MediaSource)')", - 'Notification': - "JS('bool', '!!(window.Notification)')", - 'Performance': - "JS('bool', '!!(window.performance)')", - 'SpeechRecognition': - "JS('bool', '!!(window.SpeechRecognition || " - "window.webkitSpeechRecognition)')", - 'SVGExternalResourcesRequired': - ('supported(SvgElement element)', - "JS('bool', '#.externalResourcesRequired !== undefined && " - "#.externalResourcesRequired.animVal !== undefined', " - "element, element)"), - 'SVGLangSpace': - ('supported(SvgElement element)', - "JS('bool', '#.xmlspace !== undefined && #.xmllang !== undefined', " - "element, element)"), - 'TouchList': - "JS('bool', '!!document.createTouchList')", - 'WebGLRenderingContext': - "JS('bool', '!!(window.WebGLRenderingContext)')", - 'WebSocket': - "JS('bool', 'typeof window.WebSocket != \"undefined\"')", - 'Worker': - "JS('bool', '(typeof window.Worker != \"undefined\")')", - 'XSLTProcessor': - "JS('bool', '!!(window.XSLTProcessor)')", -}.items() + dict( - (key, SvgSupportStr(_svg_element_constructors[key]) if key. - startswith('SVG') else ElemSupportStr(_html_element_constructors[key])) - for key in _js_support_checks_basic_element_with_constructors + - _js_support_checks_additional_element).items()) +js_support_checks = dict( + list({ + 'Animation': + "JS('bool', '!!(document.body.animate)')", + 'AudioContext': + "JS('bool', '!!(window.AudioContext ||" + " window.webkitAudioContext)')", + 'Crypto': + "JS('bool', '!!(window.crypto && window.crypto.getRandomValues)')", + 'Database': + "JS('bool', '!!(window.openDatabase)')", + 'DOMPoint': + "JS('bool', '!!(window.DOMPoint) || !!(window.WebKitPoint)')", + 'ApplicationCache': + "JS('bool', '!!(window.applicationCache)')", + 'DOMFileSystem': + "JS('bool', '!!(window.webkitRequestFileSystem)')", + 'FormData': + "JS('bool', '!!(window.FormData)')", + 'HashChangeEvent': + "Device.isEventTypeSupported('HashChangeEvent')", + 'HTMLShadowElement': + ElemSupportStr('shadow'), + 'HTMLTemplateElement': + ElemSupportStr('template'), + 'MediaStreamEvent': + "Device.isEventTypeSupported('MediaStreamEvent')", + 'MediaStreamTrackEvent': + "Device.isEventTypeSupported('MediaStreamTrackEvent')", + 'MediaSource': + "JS('bool', '!!(window.MediaSource)')", + 'Notification': + "JS('bool', '!!(window.Notification)')", + 'Performance': + "JS('bool', '!!(window.performance)')", + 'SpeechRecognition': + "JS('bool', '!!(window.SpeechRecognition || " + "window.webkitSpeechRecognition)')", + 'SVGExternalResourcesRequired': + ('supported(SvgElement element)', + "JS('bool', '#.externalResourcesRequired !== undefined && " + "#.externalResourcesRequired.animVal !== undefined', " + "element, element)"), + 'SVGLangSpace': + ('supported(SvgElement element)', + "JS('bool', '#.xmlspace !== undefined && #.xmllang !== undefined', " + "element, element)"), + 'TouchList': + "JS('bool', '!!document.createTouchList')", + 'WebGLRenderingContext': + "JS('bool', '!!(window.WebGLRenderingContext)')", + 'WebSocket': + "JS('bool', 'typeof window.WebSocket != \"undefined\"')", + 'Worker': + "JS('bool', '(typeof window.Worker != \"undefined\")')", + 'XSLTProcessor': + "JS('bool', '!!(window.XSLTProcessor)')", + }.items()) + list( + dict((key, + SvgSupportStr(_svg_element_constructors[key]) if key.startswith( + 'SVG') else ElemSupportStr(_html_element_constructors[key])) + for key in _js_support_checks_basic_element_with_constructors + + _js_support_checks_additional_element).items())) # JavaScript element class names of elements for which createElement does not # always return exactly the right element, either because it might not be @@ -818,6 +820,9 @@ class HtmlDartInterfaceGenerator(object): NULLABLE='?', NULLSAFECAST=True, NULLASSERT='!') + if self._interface.doc_js_name is 'RadioNodeList': + print(self._backend.ImplementationTemplate()) + print(implementation_members_emitter) stream_getter_signatures_emitter = None element_stream_getters_emitter = None class_members_emitter = None @@ -2198,7 +2203,7 @@ class Dart2JSBackend(HtmlDartGenerator): return re.search('^@.*Returns', ann) or re.search( '^@.*Creates', ann) - if not filter(js_type_annotation, anns): + if not list(filter(js_type_annotation, anns)): _logger.warn('Member with wildcard native type: %s.%s' % (self._interface.id, idl_member_name)) @@ -2320,7 +2325,7 @@ class DartLibrary(): # Emit the $!TYPE_MAP if map_emitter: - items = self._typeMap.items() + items = list(self._typeMap.items()) items.sort() for (idl_name, dart_name) in items: map_emitter.Emit( diff --git a/tools/dom/scripts/templateloader_test.py b/tools/dom/scripts/templateloader_test.py index 4b16df7febb..f6bf5974b82 100755 --- a/tools/dom/scripts/templateloader_test.py +++ b/tools/dom/scripts/templateloader_test.py @@ -30,7 +30,7 @@ ACTUAL : threw = False try: output_text = self._preprocess(input_text, conds) - except Exception, e: + except Exception as e: threw = True if str(e).find(expected_message) == -1: self.fail("'%s' does not contain '%s'" % (e, expected_message))