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

Unified Diff: Source/bindings/scripts/unstable/v8_interface.py

Issue 112303003: IDL compiler: [Constructor] overloading (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Better test case Created 7 years 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/unstable/v8_interface.py
diff --git a/Source/bindings/scripts/unstable/v8_interface.py b/Source/bindings/scripts/unstable/v8_interface.py
index 841ee87fddea178579f03afbcce85c7f265f8879..5ad2528fb049449492aa3dedeed33f216669a94f 100644
--- a/Source/bindings/scripts/unstable/v8_interface.py
+++ b/Source/bindings/scripts/unstable/v8_interface.py
@@ -94,9 +94,10 @@ def generate_interface(interface):
v8_types.add_includes_for_type(special_wrap_interface)
# Constructors
- # [Constructor]
- has_constructor = 'Constructor' in extended_attributes
- if has_constructor:
+ constructors = [generate_constructor(interface, constructor)
+ for constructor in interface.constructors]
+ generate_constructor_overloads(constructors)
+ if constructors:
includes.add('bindings/v8/V8ObjectConstructor.h')
# [EventConstructor]
@@ -112,14 +113,9 @@ def generate_interface(interface):
template_contents = {
'any_type_attributes': any_type_attributes,
'conditional_string': conditional_string(interface), # [Conditional]
- 'constructor_argument_list': constructor_argument_list(interface),
- 'constructor_arguments': constructor_arguments(interface),
- 'constructor_method': {
- 'is_constructor': True,
- },
+ 'constructors': constructors,
'cpp_class': cpp_name(interface),
'generate_visit_dom_wrapper_function': generate_visit_dom_wrapper_function,
- 'has_constructor': has_constructor,
'has_custom_legacy_call_as_function': has_extended_attribute_value(interface, 'Custom', 'LegacyCallAsFunction'), # [Custom=LegacyCallAsFunction]
'has_custom_to_v8': has_extended_attribute_value(interface, 'Custom', 'ToV8'), # [Custom=ToV8]
'has_custom_wrap': has_extended_attribute_value(interface, 'Custom', 'Wrap'), # [Custom=Wrap]
@@ -129,7 +125,7 @@ def generate_interface(interface):
has_extended_attribute_value(interface, 'Custom', 'VisitDOMWrapper') or
'GenerateVisitDOMWrapper' in extended_attributes),
'header_includes': header_includes,
- 'interface_length': interface_length(interface),
+ 'interface_length': interface_length(interface, constructors),
'interface_name': interface.name,
'is_active_dom_object': 'ActiveDOMObject' in extended_attributes, # [ActiveDOMObject]
'is_check_security': is_check_security,
@@ -315,11 +311,21 @@ def overload_check_argument(index, argument):
# Constructors
-def constructor_argument_list(interface):
- if not interface.constructors:
- return []
- constructor = interface.constructors[0] # FIXME: support overloading
+# [Constructor]
+def generate_constructor(interface, constructor):
+ return {
+ 'argument_list': constructor_argument_list(interface, constructor),
+ 'arguments': [constructor_argument(argument, index)
+ for index, argument in enumerate(constructor.arguments)],
+ 'is_constructor': True,
+ 'is_variadic': False,
haraken 2013/12/13 10:23:31 Do we need to specify these, even though their val
Nils Barth (inactive) 2013/12/16 03:15:57 Added a comment; it's required for overload resolu
+ 'number_of_required_arguments':
+ len([argument for argument in constructor.arguments
+ if not argument.is_optional]),
+ }
+
+def constructor_argument_list(interface, constructor):
arguments = []
# [ConstructorCallWith=ExecutionContext]
if has_extended_attribute_value(interface, 'ConstructorCallWith', 'ExecutionContext'):
@@ -337,31 +343,35 @@ def constructor_argument_list(interface):
return arguments
-def constructor_arguments(interface):
- if not interface.constructors:
- return []
- constructor = interface.constructors[0] # FIXME: support overloading
- return [constructor_argument(argument, index)
- for index, argument in enumerate(constructor.arguments)]
-
-
def constructor_argument(argument, index):
return {
'idl_type': argument.idl_type,
'index': index,
+ 'is_nullable': False,
Nils Barth (inactive) 2013/12/13 07:04:16 Stubs for overload resolution.
+ 'is_optional': argument.is_optional,
+ 'is_strict_type_checking': False,
'name': argument.name,
'v8_value_to_local_cpp_value':
v8_methods.v8_value_to_local_cpp_value(argument, index),
}
-def interface_length(interface):
+def generate_constructor_overloads(constructors):
+ if len(constructors) < 2:
haraken 2013/12/13 10:23:31 Nit: I'd prefer '<= 1'
Nils Barth (inactive) 2013/12/16 03:15:57 n/p, done.
+ return
+ for overload_index, constructor in enumerate(constructors):
+ constructor.update({
+ 'overload_index': overload_index + 1,
+ 'overload_resolution_expression':
+ overload_resolution_expression(constructor),
+ })
+
+
+def interface_length(interface, constructors):
# Docs: http://heycam.github.io/webidl/#es-interface-call
if 'EventConstructor' in interface.extended_attributes:
return 1
- if not interface.constructors:
+ if not constructors:
return 0
- constructor = interface.constructors[0] # FIXME: support overloading
- return len([argument
- for argument in constructor.arguments
- if not argument.is_optional])
+ return min(constructor['number_of_required_arguments']
+ for constructor in constructors)

Powered by Google App Engine
This is Rietveld 408576698