diff options
author | kalman@chromium.org <kalman@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-04-04 22:57:43 +0000 |
---|---|---|
committer | kalman@chromium.org <kalman@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-04-04 22:57:43 +0000 |
commit | a4b8a9f934180012696162db9cdfb638841ddfa5 (patch) | |
tree | 879fb45cabe31b78b33610f685f3235f1912f104 | |
parent | b8ce52f740745c9f7cb26b0f01372a58801ddac7 (diff) | |
download | chromium_src-a4b8a9f934180012696162db9cdfb638841ddfa5.zip chromium_src-a4b8a9f934180012696162db9cdfb638841ddfa5.tar.gz chromium_src-a4b8a9f934180012696162db9cdfb638841ddfa5.tar.bz2 |
Revert 261891 "Don't generate vacuous JSON schema during IDL par..."
> Don't generate vacuous JSON schema during IDL parsing, and split long
> strings up into multiple string literals when generating that JSON schema.
>
> BUG=358449
> NOTRY=true
>
> Review URL: https://codereview.chromium.org/220453002
TBR=kalman@chromium.org
Review URL: https://codereview.chromium.org/226083006
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@261909 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r-- | tools/json_schema_compiler/cpp_bundle_generator.py | 11 | ||||
-rw-r--r-- | tools/json_schema_compiler/idl_schema.py | 40 | ||||
-rwxr-xr-x | tools/json_schema_compiler/idl_schema_test.py | 16 |
3 files changed, 27 insertions, 40 deletions
diff --git a/tools/json_schema_compiler/cpp_bundle_generator.py b/tools/json_schema_compiler/cpp_bundle_generator.py index 91ae920..20acccc 100644 --- a/tools/json_schema_compiler/cpp_bundle_generator.py +++ b/tools/json_schema_compiler/cpp_bundle_generator.py @@ -274,15 +274,10 @@ class _SchemasCCGenerator(object): json_content = json.dumps([_RemoveDescriptions(api)], separators=(',', ':')) # Escape all double-quotes and backslashes. For this to output a valid - # JSON C string, we need to escape \ and ". Note that some schemas are - # too large to compile on windows. Split the JSON up into several - # strings, since apparently that helps. - max_length = 8192 - segments = [json_content[i:i + max_length].replace('\\', '\\\\') - .replace('"', '\\"') - for i in xrange(0, len(json_content), max_length)] + # JSON C string, we need to escape \ and ". + json_content = json_content.replace('\\', '\\\\').replace('"', '\\"') c.Append('const char %s[] = "%s";' % - (_FormatNameAsConstant(namespace.name), '" "'.join(segments))) + (_FormatNameAsConstant(namespace.name), json_content)) c.Append('}') c.Concat(cpp_util.OpenNamespace(self._bundle._cpp_namespace)) c.Append() diff --git a/tools/json_schema_compiler/idl_schema.py b/tools/json_schema_compiler/idl_schema.py index c6bf8ac..991b1c6 100644 --- a/tools/json_schema_compiler/idl_schema.py +++ b/tools/json_schema_compiler/idl_schema.py @@ -193,8 +193,7 @@ class Member(object): is_function = True name, parameters, return_type = (Callspec(node, parameter_comments) .process(callbacks)) - if parameters: - properties['parameters'] = parameters + properties['parameters'] = parameters if return_type is not None: properties['returns'] = return_type properties['name'] = name @@ -304,16 +303,13 @@ class Enum(object): enum = [] for node in self.node.GetChildren(): if node.cls == 'EnumItem': - description = None + enum_value = {'name': node.GetName()} for child in node.GetChildren(): if child.cls == 'Comment': - description = ProcessComment(child.GetName())[0] + enum_value['description'] = ProcessComment(child.GetName())[0] else: raise ValueError('Did not process %s %s' % (child.cls, child)) - if description: - enum.append({'name': node.GetName(), 'description': description}) - else: - enum.append(node.GetName()) + enum.append(enum_value) elif node.cls == 'Comment': self.description = ProcessComment(node.GetName())[0] else: @@ -376,24 +372,16 @@ class Namespace(object): compiler_options = self.compiler_options else: compiler_options = {} - # This slightly bizarre way of constructing a dictionary is so that we - # don't create a lot of vacuous JSON values like {"functions": []} which - # cause exceedingly long strings. See http://crbug.com/358449 for one bad - # thing this can do. - result = {} - for key, value in (('namespace', self.namespace.GetName()), - ('description', self.description), - ('nodoc', self.nodoc), - ('types', self.types), - ('functions', self.functions), - ('internal', self.internal), - ('events', self.events), - ('platforms', self.platforms), - ('compiler_options', compiler_options), - ('deprecated', self.deprecated)): - if value: - result[key] = value - return result + return {'namespace': self.namespace.GetName(), + 'description': self.description, + 'nodoc': self.nodoc, + 'types': self.types, + 'functions': self.functions, + 'internal': self.internal, + 'events': self.events, + 'platforms': self.platforms, + 'compiler_options': compiler_options, + 'deprecated': self.deprecated} def process_interface(self, node): members = [] diff --git a/tools/json_schema_compiler/idl_schema_test.py b/tools/json_schema_compiler/idl_schema_test.py index f9fa9d2..8174317 100755 --- a/tools/json_schema_compiler/idl_schema_test.py +++ b/tools/json_schema_compiler/idl_schema_test.py @@ -41,7 +41,7 @@ class IdlSchemaTest(unittest.TestCase): def testSimpleCallbacks(self): schema = self.idl_basics - expected = [{'type':'function', 'name':'cb'}] + expected = [{'type':'function', 'name':'cb', 'parameters':[]}] self.assertEquals(expected, getParams(schema, 'function4')) expected = [{'type':'function', 'name':'cb', @@ -85,7 +85,8 @@ class IdlSchemaTest(unittest.TestCase): def testEnum(self): schema = self.idl_basics - expected = {'enum': [{'name': 'name1', 'description': 'comment1'}, 'name2'], + expected = {'enum': [{'name': 'name1', 'description': 'comment1'}, + {'name': 'name2'}], 'description': 'Enum description', 'type': 'string', 'id': 'EnumType'} self.assertEquals(expected, getType(schema, expected['id'])) @@ -115,7 +116,7 @@ class IdlSchemaTest(unittest.TestCase): idl_basics = self.idl_basics self.assertEquals('idl_basics', idl_basics['namespace']) self.assertTrue(idl_basics['internal']) - self.assertFalse('nodoc' in idl_basics) + self.assertFalse(idl_basics['nodoc']) def testReturnTypes(self): schema = self.idl_basics @@ -150,7 +151,8 @@ class IdlSchemaTest(unittest.TestCase): schema = idl_schema.Load('test/idl_namespace_non_specific_platforms.idl')[0] self.assertEquals('idl_namespace_non_specific_platforms', schema['namespace']) - self.assertFalse('platforms' in schema) + expected = None + self.assertEquals(expected, schema['platforms']) def testSpecificImplementNamespace(self): schema = idl_schema.Load('test/idl_namespace_specific_implement.idl')[0] @@ -205,10 +207,12 @@ class IdlSchemaTest(unittest.TestCase): schema = idl_schema.Load('test/idl_reserved_words.idl')[0] foo_type = getType(schema, 'Foo') - self.assertEquals(['float', 'DOMString'], foo_type['enum']) + self.assertEquals([{'name': 'float'}, {'name': 'DOMString'}], + foo_type['enum']) enum_type = getType(schema, 'enum') - self.assertEquals(['callback', 'namespace'], enum_type['enum']) + self.assertEquals([{'name': 'callback'}, {'name': 'namespace'}], + enum_type['enum']) dictionary = getType(schema, 'dictionary') self.assertEquals('integer', dictionary['properties']['long']['type']) |