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

Side by Side Diff: mojo/public/tools/bindings/generators/mojom_js_generator.py

Issue 2876903002: NOT FOR COMMIT
Patch Set: Merge branch 'refs/heads/c76_dummy_stylize' into c76_tried_mojom_name_and_name Created 3 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 unified diff | Download patch
OLDNEW
1 # Copyright 2013 The Chromium Authors. All rights reserved. 1 # Copyright 2013 The Chromium Authors. All rights reserved.
2 # Use of this source code is governed by a BSD-style license that can be 2 # Use of this source code is governed by a BSD-style license that can be
3 # found in the LICENSE file. 3 # found in the LICENSE file.
4 4
5 """Generates JavaScript source files from a mojom.Module.""" 5 """Generates JavaScript source files from a mojom.Module."""
6 6
7 import mojom.generate.generator as generator 7 import mojom.generate.generator as generator
8 import mojom.generate.module as mojom 8 import mojom.generate.module as mojom
9 import mojom.generate.pack as pack 9 import mojom.generate.pack as pack
10 import os 10 import os
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after
153 def _GenerateAMDModule(self): 153 def _GenerateAMDModule(self):
154 return self._GetParameters() 154 return self._GetParameters()
155 155
156 def GenerateFiles(self, args): 156 def GenerateFiles(self, args):
157 if self.variant: 157 if self.variant:
158 raise Exception("Variants not supported in JavaScript bindings.") 158 raise Exception("Variants not supported in JavaScript bindings.")
159 159
160 # TODO(yzshen): Remove this method once the old JS bindings go away. 160 # TODO(yzshen): Remove this method once the old JS bindings go away.
161 self._SetUniqueNameForImports() 161 self._SetUniqueNameForImports()
162 162
163 # TODO(yzshen): Add a JavaScriptStylizer.
164 self.module.Stylize(generator.Stylizer())
165
163 self.Write(self._GenerateAMDModule(), 166 self.Write(self._GenerateAMDModule(),
164 self.MatchMojomFilePath("%s.js" % self.module.name)) 167 self.MatchMojomFilePath("%s.js" % self.module.name))
165 168
166 def _SetUniqueNameForImports(self): 169 def _SetUniqueNameForImports(self):
167 used_names = set() 170 used_names = set()
168 for each_import in self.module.imports: 171 for each_import in self.module.imports:
169 simple_name = each_import.name.split(".")[0] 172 simple_name = each_import.name.split(".")[0]
170 173
171 # Since each import is assigned a variable in JS, they need to have unique 174 # Since each import is assigned a variable in JS, they need to have unique
172 # names. 175 # names.
(...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after
374 return self._TranslateConstants(value) 377 return self._TranslateConstants(value)
375 378
376 def _GetStructsFromMethods(self): 379 def _GetStructsFromMethods(self):
377 result = [] 380 result = []
378 for interface in self.module.interfaces: 381 for interface in self.module.interfaces:
379 for method in interface.methods: 382 for method in interface.methods:
380 result.append(method.param_struct) 383 result.append(method.param_struct)
381 if method.response_param_struct is not None: 384 if method.response_param_struct is not None:
382 result.append(method.response_param_struct) 385 result.append(method.response_param_struct)
383 return result 386 return result
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698