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

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

Issue 1517043004: [mojo] Add typemap and variant support to generators (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@pickle3
Patch Set: set proper upstream Created 5 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 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 from mojom.generate.template_expander import UseJinja 10 from mojom.generate.template_expander import UseJinja
(...skipping 367 matching lines...) Expand 10 before | Expand all | Expand 10 after
378 "unions": self.GetUnions(), 378 "unions": self.GetUnions(),
379 "interfaces": self.GetInterfaces(), 379 "interfaces": self.GetInterfaces(),
380 "imported_interfaces": self.GetImportedInterfaces(), 380 "imported_interfaces": self.GetImportedInterfaces(),
381 } 381 }
382 382
383 @UseJinja("js_templates/module.amd.tmpl", filters=js_filters) 383 @UseJinja("js_templates/module.amd.tmpl", filters=js_filters)
384 def GenerateAMDModule(self): 384 def GenerateAMDModule(self):
385 return self.GetParameters() 385 return self.GetParameters()
386 386
387 def GenerateFiles(self, args): 387 def GenerateFiles(self, args):
388 if self.variant:
389 raise Exception("Variants not supported in JavaScript bindings.")
390
388 self.Write(self.GenerateAMDModule(), 391 self.Write(self.GenerateAMDModule(),
389 self.MatchMojomFilePath("%s.js" % self.module.name)) 392 self.MatchMojomFilePath("%s.js" % self.module.name))
390 393
391 def GetImports(self): 394 def GetImports(self):
392 used_names = set() 395 used_names = set()
393 for each_import in self.module.imports: 396 for each_import in self.module.imports:
394 simple_name = each_import["module_name"].split(".")[0] 397 simple_name = each_import["module_name"].split(".")[0]
395 398
396 # Since each import is assigned a variable in JS, they need to have unique 399 # Since each import is assigned a variable in JS, they need to have unique
397 # names. 400 # names.
398 unique_name = simple_name 401 unique_name = simple_name
399 counter = 0 402 counter = 0
400 while unique_name in used_names: 403 while unique_name in used_names:
401 counter += 1 404 counter += 1
402 unique_name = simple_name + str(counter) 405 unique_name = simple_name + str(counter)
403 406
404 used_names.add(unique_name) 407 used_names.add(unique_name)
405 each_import["unique_name"] = unique_name + "$" 408 each_import["unique_name"] = unique_name + "$"
406 counter += 1 409 counter += 1
407 return self.module.imports 410 return self.module.imports
408 411
409 def GetImportedInterfaces(self): 412 def GetImportedInterfaces(self):
410 interface_to_import = {}; 413 interface_to_import = {};
411 for each_import in self.module.imports: 414 for each_import in self.module.imports:
412 for each_interface in each_import["module"].interfaces: 415 for each_interface in each_import["module"].interfaces:
413 name = each_interface.name 416 name = each_interface.name
414 interface_to_import[name] = each_import["unique_name"] + "." + name 417 interface_to_import[name] = each_import["unique_name"] + "." + name
415 return interface_to_import; 418 return interface_to_import;
416 419
OLDNEW
« no previous file with comments | « mojo/public/tools/bindings/generators/mojom_java_generator.py ('k') | mojo/public/tools/bindings/mojom.gni » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698