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

Unified Diff: third_party/WebKit/Source/bindings/scripts/code_generator_web_module.py

Issue 2568693002: Add first bindings unit test and enable testing. (Closed)
Patch Set: Add harness code after typ roll. Created 4 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: third_party/WebKit/Source/bindings/scripts/code_generator_web_module.py
diff --git a/third_party/WebKit/Source/bindings/scripts/code_generator_web_module.py b/third_party/WebKit/Source/bindings/scripts/code_generator_web_module.py
index 0e44aeacb8778fd8614d51b5451d609949f90de0..5868b002512a2e96fe1cdc6f11ce93cdb3cafd4d 100644
--- a/third_party/WebKit/Source/bindings/scripts/code_generator_web_module.py
+++ b/third_party/WebKit/Source/bindings/scripts/code_generator_web_module.py
@@ -38,46 +38,62 @@ def includes_for_type(idl_type):
def interface_context(idl_interface):
- attributes = []
- methods = []
- includes = set()
+ builder = InterfaceContextBuilder(MODULE_PYNAME)
+ builder.set_class_name(idl_interface.name)
+
for idl_attribute in idl_interface.attributes:
- attributes.append(Attribute.create(idl_attribute))
- includes.update(includes_for_type(idl_attribute.idl_type))
+ builder.add_attribute(idl_attribute)
+
for idl_operation in idl_interface.operations:
- if idl_operation.name:
- methods.append(Method.create(idl_operation))
- return {
- 'code_generator': MODULE_PYNAME,
- 'class_name': idl_interface.name,
- 'cpp_includes': includes,
- 'attributes': attributes,
- 'methods': methods,
- }
-
-
-class Attribute(object):
- def __init__(self, name, return_type):
- self.name = name
- self.return_type = return_type
-
- @staticmethod
- def create(idl_attribute):
- name = idl_attribute.name
- return_type = idl_attribute.idl_type.preprocessed_type.base_type
- return Attribute(name, return_type)
+ builder.add_operation(idl_operation)
+
+ return builder.build()
+
+
+class InterfaceContextBuilder(object):
+ def __init__(self, code_generator):
+ self.result = {'code_generator': code_generator}
+ def set_class_name(self, class_name):
+ self.result['class_name'] = class_name
-class Method(object):
- def __init__(self, name, return_type):
- self.name = name
- self.return_type = return_type
+ def _ensure_set(self, name):
+ return self.result.setdefault(name, set())
- @staticmethod
- def create(idl_operation):
+ def _ensure_list(self, name):
+ return self.result.setdefault(name, [])
+
+ def add_attribute(self, idl_attribute):
+ self._ensure_list('attributes').append(
+ self.create_attribute(idl_attribute))
+ self._ensure_set('cpp_includes').update(
+ includes_for_type(idl_attribute.idl_type))
+
+ def add_operation(self, idl_operation):
+ if idl_operation.name:
+ self._ensure_list('methods').append(
+ self.create_method(idl_operation))
+ self._ensure_set('cpp_includes').update(
+ includes_for_type(idl_operation.idl_type))
+
+ def create_method(self, idl_operation):
name = idl_operation.name
return_type = idl_operation.idl_type.preprocessed_type.base_type
bashi 2016/12/12 05:04:38 Not directly related to this CL but do we need pre
- return Method(name, return_type)
+ return {
+ 'name': name,
+ 'return_type': return_type
+ }
+
+ def create_attribute(self, idl_attribute):
+ name = idl_attribute.name
+ return_type = idl_attribute.idl_type.preprocessed_type.base_type
+ return {
+ 'name': name,
+ 'return_type': return_type
+ }
+
+ def build(self):
+ return self.result
class CodeGeneratorWebModule(CodeGeneratorBase):
@@ -102,7 +118,7 @@ class CodeGeneratorWebModule(CodeGeneratorBase):
# TODO(dglazkov): Implement callback interfaces.
# TODO(dglazkov): Make sure partial interfaces are handled.
if interface.is_callback or interface.is_partial:
- raise ValueError("Partial or callback interfaces are not supported")
+ raise ValueError('Partial or callback interfaces are not supported')
template_context = interface_context(interface)

Powered by Google App Engine
This is Rietveld 408576698